Relocate mobarena.admin.teleport permission check.
Instead of explicitly ALLOW'ing a teleport if a player has the permission, we let the teleport handler logic run its course. If an arena explicitly REJECTs the teleport, we need to cancel the event, but the permission now overrides that behavior. This means that only in the case of an impending event cancellation, the permission kicks in. This is important, because the permission is supposed to override the decision to cancel, rather than drive the decision to uncancel. With this change, MobArena never uncancels something it wouldn't have uncancelled otherwise, meaning it won't interfere with teleports outside of its own context, and thus won't interfere with other plugins. Fixes #515, closes #516 Thanks to @minoneer for the bug report and pull request that this code was based upon!
This commit is contained in:
@@ -1214,7 +1214,7 @@ public class ArenaListener
|
||||
* transition and are removed from that state as soon as the transition
|
||||
* is complete.
|
||||
*/
|
||||
if (arena.isMoving(p) || p.hasPermission("mobarena.admin.teleport")) {
|
||||
if (arena.isMoving(p)) {
|
||||
return TeleportResponse.ALLOW;
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ public class MAGlobalListener implements Listener
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void playerTeleport(PlayerTeleportEvent event) {
|
||||
if (!am.isEnabled()) return;
|
||||
|
||||
|
||||
boolean allow = true;
|
||||
for (Arena arena : am.getArenas()) {
|
||||
TeleportResponse r = arena.getEventListener().onPlayerTeleport(event);
|
||||
@@ -364,9 +364,14 @@ public class MAGlobalListener implements Listener
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// Only cancel if at least one arena has rejected the teleport.
|
||||
if (!allow) {
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
if (!allow && !event.getPlayer().hasPermission("mobarena.admin.teleport")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user