aboutsummaryrefslogtreecommitdiff
path: root/spark-forge/src/main/java
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2021-01-19 18:28:33 +0000
committerLuck <git@lucko.me>2021-01-19 18:28:57 +0000
commit6f6b0b03ae447906574b9b30b957a5e25650315a (patch)
tree06804e5108810dfb88d9911ec050edaa1ac34b76 /spark-forge/src/main/java
parentb2a4b74f9e70eb3209ad0f736052ea02c113fcad (diff)
downloadspark-6f6b0b03ae447906574b9b30b957a5e25650315a.tar.gz
spark-6f6b0b03ae447906574b9b30b957a5e25650315a.tar.bz2
spark-6f6b0b03ae447906574b9b30b957a5e25650315a.zip
Fix tab complete on Forge/Fabric
Diffstat (limited to 'spark-forge/src/main/java')
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java25
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java8
2 files changed, 19 insertions, 14 deletions
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;
}