Skip to content

Fix server-crash when teleporting across regions with negative coordinates - #79

Merged
PureGero merged 1 commit into
MultiPaper:ver/26.2from
KarnickelDev:fix-tp-command-crash
Aug 6, 2026
Merged

Fix server-crash when teleporting across regions with negative coordinates#79
PureGero merged 1 commit into
MultiPaper:ver/26.2from
KarnickelDev:fix-tp-command-crash

Conversation

@KarnickelDev

Copy link
Copy Markdown
Contributor

Found an issue where /tp can crash the server when teleporting across region boundaries with negative coordinates.

Reproduction

With a region size of 8, run the following commands in sequence:

/tp @s 0 80 0
/tp @s 0 80 -128.5

Cause

The crash occurs because region calculation uses an integer cast of the position. This works for positive coordinates but produces incorrect results for negative coordinates.

Using only the Z coordinate as an example (region size 8):

originLocation:  0      -> (int) 0     = region 0
targetLocation: -128.5  -> (int) -128  = region 0

ensureSync() incorrectly determines that both positions are in the same region and executes the teleport on the current thread.
However, z = -128.5 actually belongs to region -1, not region 0. So the teleport runs on the wrong thread, crashing the server.

Fix

This can be fixed by using eg. Math.floor() instead of relying on casting:
Math.floor(-128.5) = -129 = region -1
Now z=-128.5 correctly maps to region -1 and ensures that teleports across negative region boundaries are synchronized correctly.

Btw, really cool project

@PureGero

PureGero commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

TIL int casting is not a floor for negative numbers... Thanks Java

Thank you!

@PureGero
PureGero merged commit 017a4d9 into MultiPaper:ver/26.2 Aug 6, 2026
1 check passed
@KarnickelDev
KarnickelDev deleted the fix-tp-command-crash branch August 6, 2026 21:24
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