Skip to content

Commit

Permalink
feat: hide spark command for players who do not have any spark relate…
Browse files Browse the repository at this point in the history
…d permissions
  • Loading branch information
LooFifteen committed Dec 25, 2024
1 parent c85c593 commit 610766e
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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<String> 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);
}
Expand Down

0 comments on commit 610766e

Please sign in to comment.