Implement auto-complete for anchor names

This commit is contained in:
Ben Woo 2023-09-21 17:36:39 +08:00
parent 5337bc75cd
commit e8af526be5
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
2 changed files with 10 additions and 1 deletions

View File

@ -29,7 +29,7 @@ class AnchorDeleteCommand extends MultiverseCommand {
@Subcommand("anchor delete")
@CommandPermission("multiverse.core.anchor.delete")
@CommandCompletion("")
@CommandCompletion("@anchornames")
@Syntax("<name>")
@Description("")
void onAnchorDeleteCommand(

View File

@ -26,6 +26,7 @@ import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.anchor.AnchorManager;
import org.mvplugins.multiverse.core.config.MVCoreConfig;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.ParsedDestination;
@ -38,19 +39,23 @@ class MVCommandCompletions extends PaperCommandCompletions {
private final MVCommandManager commandManager;
private final WorldManager worldManager;
private final AnchorManager anchorManager;
private final DestinationsProvider destinationsProvider;
@Inject
MVCommandCompletions(
@NotNull MVCommandManager mvCommandManager,
@NotNull WorldManager worldManager,
@NotNull AnchorManager anchorManager,
@NotNull DestinationsProvider destinationsProvider,
@NotNull MVCoreConfig config) {
super(mvCommandManager);
this.commandManager = mvCommandManager;
this.worldManager = worldManager;
this.anchorManager = anchorManager;
this.destinationsProvider = destinationsProvider;
registerAsyncCompletion("anchornames", this::suggestAnchorNames);
registerAsyncCompletion("commands", this::suggestCommands);
registerAsyncCompletion("destinations", this::suggestDestinations);
registerStaticCompletion("difficulties", suggestEnums(Difficulty.class));
@ -70,6 +75,10 @@ class MVCommandCompletions extends PaperCommandCompletions {
setDefaultCompletion("mvworlds", LoadedMultiverseWorld.class);
}
private Collection<String> suggestAnchorNames(BukkitCommandCompletionContext context) {
return anchorManager.getAnchors(context.getPlayer());
}
private Collection<String> suggestCommands(BukkitCommandCompletionContext context) {
String rootCmdName = context.getConfig();
if (rootCmdName == null) {