From 148fe4c729a23a881dcfa5f3ee2672c996efb2d8 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 15 Jan 2017 15:11:35 +0000 Subject: [PATCH] Make prefix/suffix string optional in the meta remove commands - related to #83 --- .../common/commands/generic/meta/MetaAddPrefix.java | 2 +- .../common/commands/generic/meta/MetaAddSuffix.java | 2 +- .../commands/generic/meta/MetaAddTempPrefix.java | 2 +- .../commands/generic/meta/MetaAddTempSuffix.java | 2 +- .../common/commands/generic/meta/MetaRemovePrefix.java | 6 +++--- .../common/commands/generic/meta/MetaRemoveSuffix.java | 6 +++--- .../commands/generic/meta/MetaRemoveTempPrefix.java | 10 +++++----- .../commands/generic/meta/MetaRemoveTempSuffix.java | 7 ++++--- .../commands/generic/permission/PermissionCheck.java | 2 +- .../generic/permission/PermissionCheckInherits.java | 2 +- .../luckperms/common/commands/utils/ArgumentUtils.java | 10 +++++++++- 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java index 99016af17..cd2718421 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java @@ -57,7 +57,7 @@ public class MetaAddPrefix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String prefix = ArgumentUtils.handleString(1, args); String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java index a122873be..44be485b4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java @@ -57,7 +57,7 @@ public class MetaAddSuffix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String suffix = ArgumentUtils.handleString(1, args); String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java index 6e993292d..3d657a9b2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java @@ -59,7 +59,7 @@ public class MetaAddTempPrefix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String prefix = ArgumentUtils.handleString(1, args); long duration = ArgumentUtils.handleDuration(2, args); String server = ArgumentUtils.handleServer(3, args); String world = ArgumentUtils.handleWorld(4, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java index 5b23a04da..ab12d3863 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java @@ -59,7 +59,7 @@ public class MetaAddTempSuffix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String suffix = ArgumentUtils.handleString(1, args); long duration = ArgumentUtils.handleDuration(2, args); String server = ArgumentUtils.handleServer(3, args); String world = ArgumentUtils.handleWorld(4, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java index 7f7fdb372..e42fb4383 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java @@ -46,10 +46,10 @@ import java.util.stream.Collectors; public class MetaRemovePrefix extends SharedSubCommand { public MetaRemovePrefix() { super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX, - Predicates.notInRange(2, 4), + Predicates.notInRange(1, 4), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), - Arg.create("prefix", true, "the prefix string"), + Arg.create("prefix", false, "the prefix string"), Arg.create("server", false, "the server to add the prefix on"), Arg.create("world", false, "the world to add the prefix on") ) @@ -59,7 +59,7 @@ public class MetaRemovePrefix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String prefix = ArgumentUtils.handleStringOrElse(1, args, "null"); String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java index 6d2031707..d68cd8587 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java @@ -46,10 +46,10 @@ import java.util.stream.Collectors; public class MetaRemoveSuffix extends SharedSubCommand { public MetaRemoveSuffix() { super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX, - Predicates.notInRange(2, 4), + Predicates.notInRange(1, 4), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), - Arg.create("suffix", true, "the suffix string"), + Arg.create("suffix", false, "the suffix string"), Arg.create("server", false, "the server to add the suffix on"), Arg.create("world", false, "the world to add the suffix on") ) @@ -59,7 +59,7 @@ public class MetaRemoveSuffix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String suffix = ArgumentUtils.handleStringOrElse(1, args, "null"); String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java index 7b886871e..0c99e81e8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java @@ -45,10 +45,11 @@ import java.util.stream.Collectors; public class MetaRemoveTempPrefix extends SharedSubCommand { public MetaRemoveTempPrefix() { - super("removetempprefix", "Removes a temporary prefix", Permission.USER_META_REMOVETEMP_PREFIX, Permission.GROUP_META_REMOVETEMP_PREFIX, Predicates.notInRange(2, 4), + super("removetempprefix", "Removes a temporary prefix", Permission.USER_META_REMOVETEMP_PREFIX, Permission.GROUP_META_REMOVETEMP_PREFIX, + Predicates.notInRange(1, 4), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), - Arg.create("prefix", true, "the prefix string"), + Arg.create("prefix", false, "the prefix string"), Arg.create("server", false, "the server to add the prefix on"), Arg.create("world", false, "the world to add the prefix on") ) @@ -58,7 +59,7 @@ public class MetaRemoveTempPrefix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String prefix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String prefix = ArgumentUtils.handleStringOrElse(1, args, "null"); String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); @@ -90,8 +91,7 @@ public class MetaRemoveTempPrefix extends SharedSubCommand { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) { - } + } catch (ObjectLacksException ignored) {} }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java index aeb58eab6..112f05836 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java @@ -45,10 +45,11 @@ import java.util.stream.Collectors; public class MetaRemoveTempSuffix extends SharedSubCommand { public MetaRemoveTempSuffix() { - super("removetempsuffix", "Removes a temporary suffix", Permission.USER_META_REMOVETEMP_SUFFIX, Permission.GROUP_META_REMOVETEMP_SUFFIX, Predicates.notInRange(2, 4), + super("removetempsuffix", "Removes a temporary suffix", Permission.USER_META_REMOVETEMP_SUFFIX, Permission.GROUP_META_REMOVETEMP_SUFFIX, + Predicates.notInRange(1, 4), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), - Arg.create("suffix", true, "the suffix string"), + Arg.create("suffix", false, "the suffix string"), Arg.create("server", false, "the server to add the suffix on"), Arg.create("world", false, "the world to add the suffix on") ) @@ -58,7 +59,7 @@ public class MetaRemoveTempSuffix extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { int priority = ArgumentUtils.handlePriority(0, args); - String suffix = ArgumentUtils.handleNodeWithoutCheck(1, args); + String suffix = ArgumentUtils.handleStringOrElse(1, args, "null"); String server = ArgumentUtils.handleServer(2, args); String world = ArgumentUtils.handleWorld(3, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java index d6278aea4..64a3509b7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java @@ -54,7 +54,7 @@ public class PermissionCheck extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { - String node = ArgumentUtils.handleNodeWithoutCheck(0, args); + String node = ArgumentUtils.handleString(0, args); String server = ArgumentUtils.handleServer(1, args); String world = ArgumentUtils.handleWorld(2, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java index 10599985b..78b902dac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java @@ -55,7 +55,7 @@ public class PermissionCheckInherits extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { - String node = ArgumentUtils.handleNodeWithoutCheck(0, args); + String node = ArgumentUtils.handleString(0, args); String server = ArgumentUtils.handleServer(1, args); String world = ArgumentUtils.handleWorld(2, args); 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 84f8c0025..bcb2eeb6b 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 @@ -40,7 +40,15 @@ import java.util.function.Function; public class ArgumentUtils { public static final Function WRAPPER = s -> s.contains(" ") ? "\"" + s + "\"" : s; - public static String handleNodeWithoutCheck(int index, List args) { + public static String handleString(int index, List args) { + return args.get(index).replace("{SPACE}", " "); + } + + public static String handleStringOrElse(int index, List args, String other) { + if (index < 0 || index >= args.size()) { + return other; + } + return args.get(index).replace("{SPACE}", " "); }