Default the value to true in set/settemp commands if no arg is given. Closes #82

This commit is contained in:
Luck
2016-12-12 16:52:15 +00:00
Unverified
parent 70aa3964ee
commit 22ccce3208
3 changed files with 12 additions and 8 deletions
@@ -46,10 +46,10 @@ import static me.lucko.luckperms.common.commands.SubCommand.getPermissionTabComp
public class PermissionSet extends SharedSubCommand {
public PermissionSet() {
super("set", "Sets a permission for the object", Permission.USER_PERM_SET, Permission.GROUP_PERM_SET,
Predicates.notInRange(2, 4),
Predicates.notInRange(1, 4),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
Arg.create("true|false", false, "the value of the node"),
Arg.create("server", false, "the server to add the permission node on"),
Arg.create("world", false, "the world to add the permission node on")
)
@@ -47,10 +47,10 @@ import static me.lucko.luckperms.common.commands.SubCommand.getPermissionTabComp
public class PermissionSetTemp extends SharedSubCommand {
public PermissionSetTemp() {
super("settemp", "Sets a permission for the object temporarily", Permission.USER_PERM_SETTEMP,
Permission.GROUP_PERM_SETTEMP, Predicates.notInRange(3, 5),
Permission.GROUP_PERM_SETTEMP, Predicates.notInRange(2, 5),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),
Arg.create("true|false", false, "the value of the node"),
Arg.create("duration", true, "the duration until the permission node expires"),
Arg.create("server", false, "the server to add the permission node on"),
Arg.create("world", false, "the world to add the permission node on")
@@ -66,11 +66,15 @@ public class ArgumentUtils {
}
public static boolean handleBoolean(int index, List<String> args) throws ArgumentException {
String bool = args.get(index);
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
throw new DetailedUsageException();
if (index < args.size()) {
String bool = args.get(index);
if (bool.equalsIgnoreCase("true") || bool.equalsIgnoreCase("false")) {
return Boolean.parseBoolean(bool);
}
}
return Boolean.parseBoolean(bool);
args.add(index, "true");
return true;
}
public static String handleServer(int index, List<String> args) throws ArgumentException {