Current PlayerMoveEvent: Code (Java): @EventHandler public void onPlayerMove(PlayerMoveEvent event) { if(event.getTo().getBlockX() == event.getFrom().getBlockX() && event.getTo().getBlockY() == event.getFrom().getBlockY() && event.getTo().getBlockZ() == event.getFrom().getBlockZ()) return; if(PreventMovementManager.contains(event.getPlayer())) { Location loc = new Location(event.getFrom().getWorld(), event.getFrom().getBlockX(), (int) event.getFrom().getY(), event.getFrom().getZ(), event.getFrom().getYaw(), event.getFrom().getPitch()); event.getPlayer().teleport(loc); return; } } This is my current code with this line: Code (Java): if(event.getTo().getBlockX() == event.getFrom().getBlockX() && event.getTo().getBlockY() == event.getFrom().getBlockY() && event.getTo().getBlockZ() == event.getFrom().getBlockZ()) return; This line makes the code only cancel the event if the player moved a block. However, I have another piece of code that helps to teleport the player to the centre of a block, and I instead want to make it so that the code cancels movement events if the player moves out of the centre point (~.5, ~.0, ~.5). How would I do this?
Remove first decimal part of x then check that is it between 0.45 and 0.55 same goes for z too. You can shorten different. Maybe try exactly 0.5? Test and see
i've tried to replicate this and solved with saving double x,y,z and double toX,toY,toZ, if it is not equal cancel event
I got the end point by doing basic calculation and just subtracting the two values like kingOf0 mentioned, then checked against the 0.45 - 0.55