From d570570394427a34ee0f12f81b80b003b147598f Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Thu, 14 Jan 2016 18:16:36 +0000 Subject: [PATCH] In Commandtime: - Make world name normalization lowercase the name as well. - Permission checks will now always consider essentials.time.world.all for convenience. --- .../essentials/commands/Commandtime.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index 06e52a717..36f1e2694 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -112,14 +112,13 @@ public class Commandtime extends EssentialsCommand { * Used to parse an argument of the type "world(s) selector" */ private Set getWorlds(final Server server, final CommandSource sender, final String selector) throws Exception { - final String permissionPrefix = "essentials.time.world."; final Set worlds = new TreeSet<>(new WorldNameComparator()); User user = ess.getUser(sender.getPlayer()); // If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user. if (selector == null) { if (sender.isPlayer()) { - if (!user.isAuthorized(permissionPrefix + normalizeWorldName(user.getWorld()))) { + if (!canUpdateWorld(user, user.getWorld())) { throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName())); } worlds.add(user.getWorld()); @@ -132,7 +131,7 @@ public class Commandtime extends EssentialsCommand { // Try to find the world with name = selector final World world = server.getWorld(selector); if (world != null) { - if (user != null && !user.isAuthorized(permissionPrefix + normalizeWorldName(world))) { + if (!canUpdateWorld(user, world)) { throw new Exception(tl("timeSetWorldPermission", world.getName())); } worlds.add(world); @@ -140,12 +139,12 @@ public class Commandtime extends EssentialsCommand { // If that fails, Is the argument something like "*" or "all"? else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all")) { // Add all worlds by default if the sender is console or player has the permission. - if (user == null || user.isAuthorized(permissionPrefix + "all")) { + if (canUpdateAll(user)) { worlds.addAll(server.getWorlds()); } else { // They don't have the _all_ permission, add worlds that they have permission for. for (World world1 : server.getWorlds()) { - if (user.isAuthorized(permissionPrefix + normalizeWorldName(world1))) { + if (canUpdateWorld(user, world1)) { worlds.add(world1); } } @@ -164,9 +163,17 @@ public class Commandtime extends EssentialsCommand { return worlds; } + + private boolean canUpdateAll(User user) { + return user == null || user.isAuthorized("essentials.time.world.all"); + } + + private boolean canUpdateWorld(User user, World world) { + return canUpdateAll(user) || user.isAuthorized("essentials.time.world." + normalizeWorldName(world)); + } private String normalizeWorldName(World world) { - return world.getName().replaceAll("\\s+", "_"); + return world.getName().toLowerCase().replaceAll("\\s+", "_"); } }