aboutsummaryrefslogtreecommitdiff
path: root/spark-forge/src/main/java/me
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2021-09-05 17:55:17 +0100
committerLuck <git@lucko.me>2021-09-05 17:55:17 +0100
commit5f2fd93a5de2f44fd1bb05ebeaa1e3ea3df2db13 (patch)
tree9a5e9fa95134f54fbac7c4205eafce38cf7c0581 /spark-forge/src/main/java/me
parentd4082c4d58846346a20e70d1f0ebda500de4152e (diff)
downloadspark-5f2fd93a5de2f44fd1bb05ebeaa1e3ea3df2db13.tar.gz
spark-5f2fd93a5de2f44fd1bb05ebeaa1e3ea3df2db13.tar.bz2
spark-5f2fd93a5de2f44fd1bb05ebeaa1e3ea3df2db13.zip
Fix tab completion on Fabric and Forge (#35)
Diffstat (limited to 'spark-forge/src/main/java/me')
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java7
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java9
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java22
3 files changed, 24 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 8beafc9..95bb2d1 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
@@ -117,12 +117,7 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Suggesti
return Suggestions.empty();
}
- return CompletableFuture.supplyAsync(() -> {
- for (String suggestion : this.platform.tabCompleteCommand(new ForgeCommandSender(this.minecraft.player, this), args)) {
- builder.suggest(suggestion);
- }
- return builder.build();
- });
+ return generateSuggestions(new ForgeCommandSender(this.minecraft.player, this), args, builder);
}
private static String[] processArgs(String input, boolean tabComplete) {
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 ca29505..867be42 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
@@ -40,7 +40,6 @@ import me.lucko.spark.forge.ForgeTickReporter;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
-import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
@@ -102,13 +101,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command<
return Suggestions.empty();
}
- ServerPlayer player = context.getSource().getPlayerOrException();
- return CompletableFuture.supplyAsync(() -> {
- for (String suggestion : this.platform.tabCompleteCommand(new ForgeCommandSender(player, this), args)) {
- builder.suggest(suggestion);
- }
- return builder.build();
- });
+ return generateSuggestions(new ForgeCommandSender(context.getSource().getPlayerOrException(), this), args, builder);
}
private static String [] processArgs(CommandContext<CommandSourceStack> context, boolean tabComplete) {
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java
index 9386cfc..e4e73dd 100644
--- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java
+++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java
@@ -26,10 +26,13 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.suggestion.SuggestionProvider;
+import com.mojang.brigadier.suggestion.Suggestions;
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.SparkPlugin;
+import me.lucko.spark.common.command.sender.CommandSender;
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.util.ClassSourceLookup;
import me.lucko.spark.forge.ForgeClassSourceLookup;
@@ -38,6 +41,7 @@ import me.lucko.spark.forge.ForgeSparkMod;
import net.minecraft.commands.CommandSource;
import java.nio.file.Path;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -113,4 +117,22 @@ public abstract class ForgeSparkPlugin implements SparkPlugin {
public ClassSourceLookup createClassSourceLookup() {
return new ForgeClassSourceLookup();
}
+
+ protected CompletableFuture<Suggestions> generateSuggestions(CommandSender sender, String[] args, SuggestionsBuilder builder) {
+ SuggestionsBuilder suggestions;
+
+ int lastSpaceIdx = builder.getRemaining().lastIndexOf(' ');
+ if (lastSpaceIdx != -1) {
+ suggestions = builder.createOffset(builder.getStart() + lastSpaceIdx + 1);
+ } else {
+ suggestions = builder;
+ }
+
+ return CompletableFuture.supplyAsync(() -> {
+ for (String suggestion : this.platform.tabCompleteCommand(sender, args)) {
+ suggestions.suggest(suggestion);
+ }
+ return suggestions.build();
+ });
+ }
}