From 610766ef8bceaa2937475996bdf14b7fc2f3d62b Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 25 Dec 2024 13:59:37 +0000 Subject: [PATCH] feat: hide spark command for players who do not have any spark related permissions --- .../spark/minestom/MinestomSparkPlugin.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java index 518d099..de121aa 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java @@ -169,17 +169,16 @@ public MinestomSparkCommand(SparkPlatform platform) { ArgumentStringArray arrayArgument = ArgumentType.StringArray("args"); arrayArgument.setSuggestionCallback(this); - addSyntax(this, arrayArgument); - setDefaultExecutor((sender, context) -> platform.executeCommand(MinestomSparkPlugin.this.createCommandSender(sender), new String[0])); + this.setCondition((sender, ignored) -> this.platform.hasPermissionForAnyCommand(MinestomSparkPlugin.this.createCommandSender(sender))); + this.addSyntax(this, arrayArgument); + this.setDefaultExecutor((sender, context) -> platform.executeCommand(MinestomSparkPlugin.this.createCommandSender(sender), new String[0])); } // execute @Override public void apply(@NotNull CommandSender sender, @NotNull CommandContext context) { String[] args = processArgs(context, false); - if (args == null) { - return; - } + if (args == null) return; this.platform.executeCommand(MinestomSparkPlugin.this.createCommandSender(sender), args); } @@ -188,21 +187,15 @@ public void apply(@NotNull CommandSender sender, @NotNull CommandContext context @Override public void apply(@NotNull CommandSender sender, @NotNull CommandContext context, @NotNull Suggestion suggestion) { String[] args = processArgs(context, true); - if (args == null) { - return; - } + if (args == null) return; Iterable suggestionEntries = this.platform.tabCompleteCommand(MinestomSparkPlugin.this.createCommandSender(sender), args); - for (String suggestionEntry : suggestionEntries) { - suggestion.addEntry(new SuggestionEntry(suggestionEntry)); - } + for (String suggestionEntry : suggestionEntries) suggestion.addEntry(new SuggestionEntry(suggestionEntry)); } private static String [] processArgs(CommandContext context, boolean tabComplete) { String[] split = context.getInput().split(" ", tabComplete ? -1 : 0); - if (split.length == 0 || !split[0].equals("/spark") && !split[0].equals("spark")) { - return null; - } + if (split.length == 0 || !split[0].equals("/spark") && !split[0].equals("spark")) return null; return Arrays.copyOfRange(split, 1, split.length); }