diff options
Diffstat (limited to 'spark-fabric/src/main')
-rw-r--r-- | spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java | 21 | ||||
-rw-r--r-- | spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java | 24 |
2 files changed, 26 insertions, 19 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java index 5b63904..1bc6707 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java @@ -41,6 +41,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.command.CommandSource; import net.minecraft.server.command.CommandOutput; +import net.minecraft.server.command.ServerCommandSource; import java.util.Arrays; import java.util.Optional; @@ -98,12 +99,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Sugges } public boolean onClientChat(String chat) { - String[] split = chat.split(" "); - if (split.length == 0 || (!split[0].equals("/sparkc") && !split[0].equals("/sparkclient"))) { + String[] args = processArgs(chat, false); + if (args == null) { return false; } - String[] args = Arrays.copyOfRange(split, 1, split.length); this.platform.executeCommand(new FabricCommandSender(this.minecraft.player, this), args); this.minecraft.inGameHud.getChatHud().addToMessageHistory(chat); return true; @@ -111,13 +111,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Sugges @Override public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException { - String[] split = context.getInput().split(" "); - if (split.length == 0 || (!split[0].equals("/sparkc") && !split[0].equals("/sparkclient"))) { + String[] args = processArgs(context.getInput(), true); + if (args == null) { return Suggestions.empty(); } - String[] args = Arrays.copyOfRange(split, 1, split.length); - return CompletableFuture.supplyAsync(() -> { for (String suggestion : this.platform.tabCompleteCommand(new FabricCommandSender(this.minecraft.player, this), args)) { builder.suggest(suggestion); @@ -126,6 +124,15 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Sugges }); } + private static String[] processArgs(String input, boolean tabComplete) { + String[] split = input.split(" ", tabComplete ? -1 : 0); + if (split.length == 0 || !split[0].equals("/sparkc") && !split[0].equals("/sparkclient")) { + return null; + } + + return Arrays.copyOfRange(split, 1, split.length); + } + @Override public boolean hasPermission(CommandOutput sender, String permission) { return true; diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java index 7ef0643..08edc82 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java @@ -73,18 +73,9 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman this.server = server; } - private static String /*Nullable*/ [] processArgs(CommandContext<ServerCommandSource> context) { - String[] split = context.getInput().split(" "); - if (split.length == 0 || !split[0].equals("/spark") && !split[0].equals("spark")) { - return null; - } - - return Arrays.copyOfRange(split, 1, split.length); - } - @Override public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { - String[] args = processArgs(context); + String[] args = processArgs(context, false); if (args == null) { return 0; } @@ -96,12 +87,12 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman @Override public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException { - String[] args = processArgs(context); + String[] args = processArgs(context, true); if (args == null) { return Suggestions.empty(); } - ServerPlayerEntity player = context.getSource().getPlayer(); + ServerPlayerEntity player = context.getSource().getPlayer(); return CompletableFuture.supplyAsync(() -> { for (String suggestion : this.platform.tabCompleteCommand(new FabricCommandSender(player, this), args)) { builder.suggest(suggestion); @@ -110,6 +101,15 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman }); } + private static String[] processArgs(CommandContext<ServerCommandSource> 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; + } + + return Arrays.copyOfRange(split, 1, split.length); + } + @Override public boolean hasPermission(CommandOutput sender, String permission) { if (sender instanceof PlayerEntity) { |