diff --git a/src/de/steamwar/lobby/listener/PlayerMoveListener.java b/src/de/steamwar/lobby/listener/PlayerMoveListener.java index e5daf07..ebe2e92 100644 --- a/src/de/steamwar/lobby/listener/PlayerMoveListener.java +++ b/src/de/steamwar/lobby/listener/PlayerMoveListener.java @@ -20,7 +20,6 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.utils.Config; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -29,37 +28,15 @@ import org.bukkit.util.Vector; public class PlayerMoveListener implements Listener { + private static final Vector borderMinVector = new Vector(Config.BorderMinX, Config.BorderMinY, Config.BorderMinZ); + private static final Vector borderMaxVector = new Vector(Config.BorderMaxX, Config.BorderMaxY, Config.BorderMaxZ); + @EventHandler public void handleWorldBorder(PlayerMoveEvent event) { Location to = event.getTo(); - if(!isInRegion( - new Vector(Config.BorderMinX, Config.BorderMinY, Config.BorderMinZ), - new Vector(Config.BorderMaxX, Config.BorderMaxY, Config.BorderMaxZ), - to.toVector())) - event.getPlayer().teleport(new Location( - Bukkit.getWorlds().get(0), - Config.SpawnX, - Config.SpawnY, - Config.SpawnZ, - Config.Yaw, - Config.Pitch)); + if (!to.toVector().isInAABB(borderMinVector, borderMaxVector)) { + event.getPlayer().teleport(event.getFrom()); + } } - private boolean isInRegion(Vector minPoint, Vector maxPoint, Vector location) { - int x = location.getBlockX(); - int y = location.getBlockY(); - int z = location.getBlockZ(); - - if(x >= minPoint.getBlockX() - && x <= maxPoint.getBlockX() - && y >= minPoint.getBlockY() - && y <= maxPoint.getBlockY() - && z >= minPoint.getBlockZ() - && z <= maxPoint.getBlockZ()) { - return true; - } else - return false; - } - - -} +} \ No newline at end of file