From 519886cf3ebb1c5ba8fa983760d40d8739949569 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sun, 1 Nov 2020 11:57:15 +0100 Subject: [PATCH] Use slugs in arena and class permission checks. This commit changes the permission checks for arenas and classes to a slug-based approach instead of the "config names", which are somewhat arbitrary and may contain spaces, which are generally not supported by permissions plugins. This is a breaking change, which means it will be necessary for users to change their permission setups. Backwards compatibility could have been implemented, but it just leaves more room for ambiguity and will make a necessary transition later down the road less obvious. Instead, we burn the ships! As a result of this change, access to the "My Items" class can now be revoked as intended with the key `mobarena.classes.my-items`. Fixes #647 --- changelog.md | 1 + src/main/java/com/garbagemule/MobArena/ArenaClass.java | 9 +++++++-- src/main/java/com/garbagemule/MobArena/ArenaImpl.java | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 608c6e5..890c345 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,7 @@ These changes will (most likely) be included in the next version. - Boss rewards also support the `all()` and `random()` functions as well as the `nothing` keyword. - New command `/ma addreward ` can be used to add a reward to an arena player's reward list. This can be useful for hooking into the rewards system from scripts or other plugins. - The Root Target ability now uses potion effects (slowness, slow falling, and negative jump boost) instead of repeated teleports. This should make for a smoother root experience. +- Permissions for arenas and classes are now based on "slugs". It is now possible to configure permissions for arenas and classes with multi-word names (including "My Items"). Check the Permissions page on the wiki for details. - Using `spectate-on-death: true` no longer forces players out to their join location/exit warp before moving them to the spectator area. This should prevent "jumpy" behavior in multi-world setups. - Players should now properly respawn at the spectator area rather than at world spawn on servers with plugins that override respawn locations. - Config-files with missing `pet-items` nodes no longer errors. A missing `pet-items` node in `global-settings` is treated as empty, i.e. no pet items will be registered. diff --git a/src/main/java/com/garbagemule/MobArena/ArenaClass.java b/src/main/java/com/garbagemule/MobArena/ArenaClass.java index e9c7abc..a809ba0 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaClass.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaClass.java @@ -148,8 +148,13 @@ public class ArenaClass } public boolean hasPermission(Player p) { - String perm = "mobarena.classes." + configName; - return !p.isPermissionSet(perm) || p.hasPermission(perm); + String key = "mobarena.classes." + slug; + if (p.isPermissionSet(key)) { + return p.hasPermission(key); + } + + // Permissive by default. + return true; } /** diff --git a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java index d81824b..87e0455 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java @@ -680,8 +680,13 @@ public class ArenaImpl implements Arena @Override public boolean hasPermission(Player p) { - String perm = "mobarena.arenas." + name; - return !p.isPermissionSet(perm) || p.hasPermission(perm); + String key = "mobarena.arenas." + slug; + if (p.isPermissionSet(key)) { + return p.hasPermission(key); + } + + // Permissive by default. + return true; } @Override