mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-04-25 07:59:44 +00:00
In Commandtime:
- Make world name normalization lowercase the name as well. - Permission checks will now always consider essentials.time.world.all for convenience.
This commit is contained in:
parent
0347badeda
commit
d570570394
1 changed files with 13 additions and 6 deletions
|
@ -112,14 +112,13 @@ public class Commandtime extends EssentialsCommand {
|
||||||
* Used to parse an argument of the type "world(s) selector"
|
* Used to parse an argument of the type "world(s) selector"
|
||||||
*/
|
*/
|
||||||
private Set<World> getWorlds(final Server server, final CommandSource sender, final String selector) throws Exception {
|
private Set<World> getWorlds(final Server server, final CommandSource sender, final String selector) throws Exception {
|
||||||
final String permissionPrefix = "essentials.time.world.";
|
|
||||||
final Set<World> worlds = new TreeSet<>(new WorldNameComparator());
|
final Set<World> worlds = new TreeSet<>(new WorldNameComparator());
|
||||||
User user = ess.getUser(sender.getPlayer());
|
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 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 (selector == null) {
|
||||||
if (sender.isPlayer()) {
|
if (sender.isPlayer()) {
|
||||||
if (!user.isAuthorized(permissionPrefix + normalizeWorldName(user.getWorld()))) {
|
if (!canUpdateWorld(user, user.getWorld())) {
|
||||||
throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName()));
|
throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName()));
|
||||||
}
|
}
|
||||||
worlds.add(user.getWorld());
|
worlds.add(user.getWorld());
|
||||||
|
@ -132,7 +131,7 @@ public class Commandtime extends EssentialsCommand {
|
||||||
// Try to find the world with name = selector
|
// Try to find the world with name = selector
|
||||||
final World world = server.getWorld(selector);
|
final World world = server.getWorld(selector);
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
if (user != null && !user.isAuthorized(permissionPrefix + normalizeWorldName(world))) {
|
if (!canUpdateWorld(user, world)) {
|
||||||
throw new Exception(tl("timeSetWorldPermission", world.getName()));
|
throw new Exception(tl("timeSetWorldPermission", world.getName()));
|
||||||
}
|
}
|
||||||
worlds.add(world);
|
worlds.add(world);
|
||||||
|
@ -140,12 +139,12 @@ public class Commandtime extends EssentialsCommand {
|
||||||
// If that fails, Is the argument something like "*" or "all"?
|
// If that fails, Is the argument something like "*" or "all"?
|
||||||
else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all")) {
|
else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all")) {
|
||||||
// Add all worlds by default if the sender is console or player has the permission.
|
// 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());
|
worlds.addAll(server.getWorlds());
|
||||||
} else {
|
} else {
|
||||||
// They don't have the _all_ permission, add worlds that they have permission for.
|
// They don't have the _all_ permission, add worlds that they have permission for.
|
||||||
for (World world1 : server.getWorlds()) {
|
for (World world1 : server.getWorlds()) {
|
||||||
if (user.isAuthorized(permissionPrefix + normalizeWorldName(world1))) {
|
if (canUpdateWorld(user, world1)) {
|
||||||
worlds.add(world1);
|
worlds.add(world1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,9 +163,17 @@ public class Commandtime extends EssentialsCommand {
|
||||||
|
|
||||||
return worlds;
|
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) {
|
private String normalizeWorldName(World world) {
|
||||||
return world.getName().replaceAll("\\s+", "_");
|
return world.getName().toLowerCase().replaceAll("\\s+", "_");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue