diff --git a/AdvancedTeleport-Bukkit/build.gradle.kts b/AdvancedTeleport-Bukkit/build.gradle.kts index 0858ef05..ee6c745b 100644 --- a/AdvancedTeleport-Bukkit/build.gradle.kts +++ b/AdvancedTeleport-Bukkit/build.gradle.kts @@ -585,6 +585,8 @@ bukkit { "at.admin.bypass.distance-limit" to true, "at.admin.sethome.bypass" to true, "at.admin.bypass.teleport-on-join" to true, + "at.admin.bypass.movement" to true, + "at.admin.bypass.rotation" to true, "at.admin.toggletp" to true, "at.admin.bypass" to true, "at.admin.tploc" to true, diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/MovementManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/MovementManager.java index b70ba659..1038ec50 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/MovementManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/MovementManager.java @@ -28,19 +28,11 @@ public class MovementManager implements Listener { @EventHandler public void onMovement(PlayerMoveEvent event) { - boolean cancelOnRotate = MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get(); - boolean cancelOnMove = MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get(); - if (!cancelOnRotate) { - Location locTo = event.getTo(); - Location locFrom = event.getFrom(); - if (locTo.getBlockX() == locFrom.getBlockX() // If the player rotated instead of moved - && locTo.getBlockY() == locFrom.getBlockY() - && locTo.getBlockZ() == locFrom.getBlockZ()) { - return; - } - } + + boolean cancelled = willCancelTimer(event); + UUID uuid = event.getPlayer().getUniqueId(); - if ((cancelOnRotate || cancelOnMove) && movement.containsKey(uuid)) { + if (cancelled && movement.containsKey(uuid)) { ImprovedRunnable timer = movement.get(uuid); timer.cancel(); CustomMessages.sendMessage(event.getPlayer(), "Teleport.eventMovement"); @@ -49,6 +41,37 @@ public void onMovement(PlayerMoveEvent event) { } } + private static boolean willCancelTimer(PlayerMoveEvent event) { + boolean cancelOnRotate = MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get() && !event.getPlayer().hasPermission("at.admin.bypass.rotation"); + boolean cancelOnMove = MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get() && !event.getPlayer().hasPermission("at.admin.bypass.movement"); + + boolean cancelled = false; + + // If we have to perform position checks, compare blocks + if (cancelOnMove) { + Location locTo = event.getTo(); + Location locFrom = event.getFrom(); + if (locTo.getBlockX() != locFrom.getBlockX() // If the player moved + || locTo.getBlockY() != locFrom.getBlockY() + || locTo.getBlockZ() != locFrom.getBlockZ()) { + cancelled = true; + } + } + + // If we have to perform rotation checks, compare + if (cancelOnRotate && !cancelled) { + Location locTo = event.getTo(); + Location locFrom = event.getFrom(); + + if (locTo.getPitch() != locFrom.getPitch() + || locTo.getYaw() != locFrom.getYaw()) { + cancelled = true; + } + } + + return cancelled; + } + public static HashMap getMovement() { return movement; } @@ -122,8 +145,8 @@ public void run() { }; movement.put(uuid, movementtimer); movementtimer.runTaskLater(CoreClass.getInstance(), warmUp * 20L); - if (MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get() - || MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get()) { + if ((MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get() && !teleportingPlayer.hasPermission("at.admin.bypass.movement")) + || (MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get() && !teleportingPlayer.hasPermission("at.admin.bypass.rotation"))) { CustomMessages.sendMessage( teleportingPlayer, "Teleport.eventBeforeTP",