Skip to content

fix(paper): prevent players from being incorrectly teleported to world spawn on login - #66

Closed
naipret wants to merge 2 commits into
Navio1430:masterfrom
naipret:master
Closed

fix(paper): prevent players from being incorrectly teleported to world spawn on login#66
naipret wants to merge 2 commits into
Navio1430:masterfrom
naipret:master

Conversation

@naipret

@naipret naipret commented May 24, 2026

Copy link
Copy Markdown

Description

This PR fixes a critical and highly disruptive bug on Paper where players are frequently teleported to the world's default spawn (0, y, 0) upon joining, instead of spawning at their actual logout coordinates.

Motivation and Context

Many server owners and players experienced an issue where their survival coordinates were permanently lost upon logging in. After investigating the Paper module, I identified two root causes for this behavior, which this PR addresses:

  1. Session/Auto-login Bug: In chooseWorld (PaperListeners.java), the event spawn location was being unconditionally overwritten by world.value().getSpawnLocation(). When a player has an active session, they bypass the /login phase and its subsequent teleportation logic. Consequently, their logout coordinates were forcibly overwritten by the world's default spawn upon joining.

    • Fix: The code now checks if the player is authorized (world.key()) and staying in the same world. If true, their eventSpawnLocation is preserved.
  2. Cache Expiration Bug: The spawnLocationCache was set to expire after exactly 2 minutes. If an unauthorized player took slightly longer than 2 minutes to type /login <password>, the cache would return null, causing the fallback logic to teleport them to the world spawn instead of their original location.

    • Fix: Increased the Caffeine cache expiration from 2 minutes to 1 hour to allow ample time for authentication without risking coordinate loss.

How Has This Been Tested?

  • Logged into the server as a new player without a session (verified Limbo teleportation and /login correctly restores coordinates after 5+ minutes).
  • Logged into the server with an active session/auto-login (verified the player spawns exactly at their logout coordinates instead of the world spawn).
  • Tested joining while dead.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

naipret added 2 commits May 24, 2026 09:48
Previously, `spawnLocationCache` and `joinedWhileDead` caches expired after only 2 minutes. This caused a bug where players who took longer than 2 minutes to authenticate (e.g., typing `/login`) would lose their saved coordinates and get forcefully teleported to the world's default spawn. Increasing the expiration time to 1 hour gives players ample time to log in without losing their location.
The `AsyncPlayerSpawnLocationEvent` was previously unconditionally overwriting the player's spawn location with the world's default spawn. This caused players with active sessions (auto-login) to permanently lose their exact logout coordinates upon joining. Now, if a player is authorized via an active session and connects to the same world, their original `eventSpawnLocation` coordinates are explicitly preserved.
@Navio1430

Copy link
Copy Markdown
Owner

Hi! Sorry for the lack of response. I must have missed a notification or something. The issue should be fixed in Vuxeim's PR #69

@Navio1430 Navio1430 closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants