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 afcc526a71 for more info.
This commit is contained in:
Andreas Troelsen 2022-02-12 19:06:40 +01:00
parent 77b2525707
commit d4dcc8dc90
3 changed files with 15 additions and 9 deletions

View File

@ -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

View File

@ -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();

View File

@ -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);
}
}