3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-17 05:40:06 +01:00

Fix PluginBrigadierCommand suggestions delegation

Dieser Commit ist enthalten in:
Jason Penilla 2022-08-07 16:06:46 -07:00
Ursprung 8af375f4b7
Commit 11b4b845b4

Datei anzeigen

@ -1,9 +1,15 @@
package io.papermc.paperweight.testplugin; package io.papermc.paperweight.testplugin;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.mojang.brigadier.suggestion.Suggestion;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.command.PluginIdentifiableCommand;
@ -11,6 +17,7 @@ import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_19_R1.command.VanillaCommandWrapper;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
@ -40,6 +47,17 @@ final class PluginBrigadierCommand extends Command implements PluginIdentifiable
return true; return true;
} }
@Override
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args, final @Nullable Location location) {
final String joined = String.join(" ", args);
final String argsString = joined.isBlank() ? "" : joined;
final CommandDispatcher<CommandSourceStack> dispatcher = ((CraftServer) Bukkit.getServer()).getServer().getCommands().getDispatcher();
final ParseResults<CommandSourceStack> results = dispatcher.parse(new StringReader(alias + " " + argsString), VanillaCommandWrapper.getListener(sender));
return dispatcher.getCompletionSuggestions(results)
.thenApply(result -> result.getList().stream().map(Suggestion::getText).toList())
.join();
}
@Override @Override
public Plugin getPlugin() { public Plugin getPlugin() {
return this.plugin; return this.plugin;