Would it be possible to get an Event or Boolean for when a player hits the edge of a static sized world (World_MaxSector= >-1)?
I would prefer an event over checking a bool every time a player changes position.
Would it be possible to get an Event or Boolean for when a player hits the edge of a static sized world (World_MaxSector= >-1)?
I would prefer an event over checking a bool every time a player changes position.
That's a bit tricky unfortunately
The max sector is basically handled client- and serverside: on clientside, the game smoothly prevents the player from leaving the world bounds. This feels a bit like an "invisible wall", i.e it smoothly stops the player. It's not an actual wall, instead the player movement is slowed down the closer to player gets to edge of the world. Unfortunately the server isn't even aware at this stage that the player is leaving the sector, so unfortunately it couldn't trigger an event.
The server, however, also has a handling for the max sector: if the player still manages to escape the world bounds (e.g. by teleporting, or when moving with a very high speed etc), the server teleports the player back into the world bounds. This is a situation where we could trigger an event, but usually this shouldn't happen very often (considering the clientside handling should already prevent the player from reaching that point in most cases).
However, we could add a serverside check if the player is very close to the world bounds (i.e the point at which the client starts slowing down the player - which is ~ 16 blocks from the world edge), then trigger an event and/or set a bool. It wouldn't be 100% perfect because the player could still move a bit closer to the edge at that stage. Would that still work for you?
QuoteHowever, we could add a serverside check if the player is very close to the world bounds (i.e the point at which the client starts slowing down the player - which is ~ 16 blocks from the world edge), then trigger an event and/or set a bool. It wouldn't be 100% perfect because the player could still move a bit closer to the edge at that stage. Would that still work for you?
this should work. its mainly needed for my server clustering system. i just need a way to know when a player is at the end of the map so i can send them to the next server in the cluster.
After taking a closer look at this I'd probably recommend to handle this in the plugin instead - actually that would be more reliable and more performant
If the game has an event (or a bool), we have to calculate that every frame the player position changes (to keep the behaviour consistent and predictable). It would always be necessary to calculate it, even if no plugin uses it.
But if a plugin implements it instead, it could actually just calculate it every block (or every chunk, for example), which would be better in terms of performance.
Im your case, I'd recommend to use the PlayerChangeBlockPositionEvent. If it doesn't have to be exactly the edge of the world (right now it's ~16 blocks from the world edge), you could use the PlayerEnterChunkEvent instead for even better performance (that would trigger at ~32 blocks from the world edge). I will add a new Server.getDistanceToWorldEdge() function with the upcoming hotfix which calculates the distance of a position to the world edge (to make this handling a bit easier and more consistent), so the code could look like this:
Don’t have an account yet? Create a new account now and be part of our community!