From 22ccce3208ef07c48c0d92c948ad27e296ff6a71 Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 12 Dec 2016 16:52:15 +0000 Subject: [PATCH] Default the value to true in set/settemp commands if no arg is given. Closes #82 --- .../commands/generic/permission/PermissionSet.java | 4 ++-- .../generic/permission/PermissionSetTemp.java | 4 ++-- .../common/commands/utils/ArgumentUtils.java | 12 ++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index d4ec5858c..5bb6ff0bd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -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") ) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index 1b726646c..c429362b4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -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") diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java index 0fba34296..c69e028d5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java @@ -66,11 +66,15 @@ public class ArgumentUtils { } public static boolean handleBoolean(int index, List 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 args) throws ArgumentException {