From d4dcc8dc90cf824f18e50ca98dc65959ab8ac966 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sat, 12 Feb 2022 19:06:40 +0100 Subject: [PATCH] Don't nag players with `mobarena.admin.teleport`. Changes the behavior of the ArenaListener's teleport event handler such that it _ignores_ teleport attempts instead of _rejecting_ them when the player in question has the `mobarena.admin.teleport` permission. Because the global listener's event handler only ever checks the permission if at least one per-arena listener has _rejected_ the teleport attempt, and none of them have explicitly _allowed_ it, the change means that it will never check the permission, because its internal `allow` flag will never change to `false`. Thus, the check can be safely removed from the global listener's logic. When the response is to ignore instead of reject, the message that would have otherwise been sent to the player is skipped. This fixes #702. It is perhaps tempting to move the permission check up into the section of sanity checks in the global listener, but this is very specifically avoided to allow MobArena to _uncancel_ teleport events that have been cancelled by other plugins, but that MobArena might need to go through. Please see afcc526a7187571aea467fe9180cc224cfe3d149 for more info. --- changelog.md | 1 + .../garbagemule/MobArena/ArenaListener.java | 18 ++++++++++++------ .../MobArena/listeners/MAGlobalListener.java | 5 ++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index 29e28bc..f382c43 100644 --- a/changelog.md +++ b/changelog.md @@ -37,6 +37,7 @@ These changes will (most likely) be included in the next version. - Flaming arrows now ignite TNT blocks in the arena. - Players no longer take fall damage when they leave (or get removed from) an arena while falling. - Players no longer take damage from projectiles shot by pets of other players. +- MobArena no longer nags players with the `mobarena.admin.teleport` permission when they engage in a teleport that would have otherwise been blocked. ## [0.106] - 2021-05-09 ### Added diff --git a/src/main/java/com/garbagemule/MobArena/ArenaListener.java b/src/main/java/com/garbagemule/MobArena/ArenaListener.java index bc70b9a..0c65809 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaListener.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaListener.java @@ -1291,23 +1291,20 @@ public class ArenaListener if (region.contains(to)) { // Inside -> inside if (!(arena.inArena(p) || arena.inLobby(p))) { - arena.getMessenger().tell(p, Msg.WARP_TO_ARENA); - return TeleportResponse.REJECT; + return reject(p, Msg.WARP_TO_ARENA); } return TeleportResponse.ALLOW; } else { // Inside -> outside if (arena.getAllPlayers().contains(p)) { - arena.getMessenger().tell(p, Msg.WARP_FROM_ARENA); - return TeleportResponse.REJECT; + return reject(p, Msg.WARP_FROM_ARENA); } return TeleportResponse.IDGAF; } } else { if (region.contains(to)) { // Outside -> inside - arena.getMessenger().tell(p, Msg.WARP_TO_ARENA); - return TeleportResponse.REJECT; + return reject(p, Msg.WARP_TO_ARENA); } else { // Outside -> outside return TeleportResponse.IDGAF; @@ -1315,6 +1312,15 @@ public class ArenaListener } } + private TeleportResponse reject(Player p, Msg message) { + if (p.hasPermission("mobarena.admin.teleport")) { + return TeleportResponse.IDGAF; + } + + arena.getMessenger().tell(p, message); + return TeleportResponse.REJECT; + } + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { Player p = event.getPlayer(); diff --git a/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java b/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java index 9d023f5..2e486a1 100644 --- a/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java +++ b/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java @@ -369,10 +369,9 @@ public class MAGlobalListener implements Listener /* * If we reach this point, no arena has specifically allowed the * teleport, but one or more arenas may have rejected it, so we - * may have to cancel the event. If the player has the teleport - * override permission, however, we don't cancel. + * may have to cancel the event. */ - if (!allow && !event.getPlayer().hasPermission("mobarena.admin.teleport")) { + if (!allow) { event.setCancelled(true); } }