diff options
4 files changed, 45 insertions, 33 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) { diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 7b32f5b..1903c69 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -37,6 +37,7 @@ import me.lucko.spark.forge.ForgeTickHook; import me.lucko.spark.forge.ForgeTickReporter; import net.minecraft.client.Minecraft; import net.minecraft.client.network.play.ClientPlayNetHandler; +import net.minecraft.command.CommandSource; import net.minecraft.command.ICommandSource; import net.minecraft.command.ISuggestionProvider; import net.minecraftforge.client.event.ClientChatEvent; @@ -97,28 +98,23 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Suggesti @SubscribeEvent public void onClientChat(ClientChatEvent event) { - String chat = event.getMessage(); - String[] split = chat.split(" "); - if (split.length == 0 || (!split[0].equals("/sparkc") && !split[0].equals("/sparkclient"))) { + String[] args = processArgs(event.getMessage(), false); + if (args == null) { return; } - String[] args = Arrays.copyOfRange(split, 1, split.length); this.platform.executeCommand(new ForgeCommandSender(this.minecraft.player, this), args); - this.minecraft.ingameGUI.getChatGUI().addToSentMessages(chat); + this.minecraft.ingameGUI.getChatGUI().addToSentMessages(event.getMessage()); event.setCanceled(true); } @Override public CompletableFuture<Suggestions> getSuggestions(CommandContext<ISuggestionProvider> context, SuggestionsBuilder builder) throws CommandSyntaxException { - String chat = context.getInput(); - String[] split = chat.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 ForgeCommandSender(this.minecraft.player, this), args)) { builder.suggest(suggestion); @@ -127,6 +123,15 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Suggesti }); } + 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(ICommandSource sender, String permission) { return true; diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index 42309c1..b4c28b2 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -83,7 +83,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< @Override public int run(CommandContext<CommandSource> context) throws CommandSyntaxException { - String[] args = processArgs(context); + String[] args = processArgs(context, false); if (args == null) { return 0; } @@ -94,7 +94,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< @Override public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException { - String[] args = processArgs(context); + String[] args = processArgs(context, true); if (args == null) { return Suggestions.empty(); } @@ -108,8 +108,8 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< }); } - private static String /* Nullable */[] processArgs(CommandContext<CommandSource> context) { - String[] split = context.getInput().split(" "); + private static String [] processArgs(CommandContext<CommandSource> 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; } |