Hi. I'm creating a plugin. And i wanna know the code that using PlayerMoveEvent. Get player position and if player moved from x+2 , z+2, event cancelled. How to write this? Thanks for teaching.
First of all, player wouldn't move exactly two blocks diagonally.l That situation is basically impossible to reproduce. Maybe you meant within that range? Also, your title...
In other words, i want a code that like "LifeBoat" server. In lifeboat, player joined a match, player move a little. I want to code this.
You first need to know the central position of the player, then use Vector3->distanceSquared() to check player distance from central position to see if it is greater than 4 (2²), if true, teleport back to central position. You don't need to use PlayerMoveEvent; just use a scheduled task to check at a lower frequency.