Testing getContextValue for CommandCompletions.

This commit is contained in:
benwoo1110 2021-01-07 11:12:35 +08:00
parent cde7ab961f
commit 197764622c
2 changed files with 12 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import co.aikar.commands.CommandIssuer;
import co.aikar.commands.PaperCommandCompletions; import co.aikar.commands.PaperCommandCompletions;
import co.aikar.commands.RegisteredCommand; import co.aikar.commands.RegisteredCommand;
import co.aikar.commands.RootCommand; import co.aikar.commands.RootCommand;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
@ -25,6 +26,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.Console;
import java.io.File; import java.io.File;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Arrays; import java.util.Arrays;
@ -56,6 +58,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
this.plugin = plugin; this.plugin = plugin;
this.worldManager = plugin.getMVWorldManager(); this.worldManager = plugin.getMVWorldManager();
registerAsyncCompletion("worldSettings", this::suggestWorldSettings);
registerAsyncCompletion("scripts", this::suggestScripts); registerAsyncCompletion("scripts", this::suggestScripts);
registerAsyncCompletion("subCommands", this::suggestSubCommands); registerAsyncCompletion("subCommands", this::suggestSubCommands);
registerAsyncCompletion("MVWorlds", this::suggestMVWorlds); registerAsyncCompletion("MVWorlds", this::suggestMVWorlds);
@ -74,6 +77,14 @@ public class MVCommandCompletions extends PaperCommandCompletions {
registerStaticCompletion("toggles", this::suggestToggles); registerStaticCompletion("toggles", this::suggestToggles);
} }
@NotNull
private Collection<String> suggestWorldSettings(@NotNull BukkitCommandCompletionContext context) {
context.getConfig()
final String[] contextValue = context.getContextValue(String[].class);
Logging.info(Arrays.toString(contextValue));
return Collections.emptyList();
}
@NotNull @NotNull
private Collection<String> suggestScripts(@NotNull BukkitCommandCompletionContext context) { private Collection<String> suggestScripts(@NotNull BukkitCommandCompletionContext context) {
Buscript scriptAPI = this.plugin.getScriptAPI(); Buscript scriptAPI = this.plugin.getScriptAPI();

View File

@ -36,7 +36,7 @@ public class CreateCommand extends MultiverseCommand {
@Subcommand("create") @Subcommand("create")
@CommandPermission("multiverse.core.create") @CommandPermission("multiverse.core.create")
@Syntax("<name> <env> -s [seed] -g [generator[:id]] -t [worldtype] [-n] -a [true|false]") @Syntax("<name> <env> -s [seed] -g [generator[:id]] -t [worldtype] [-n] -a [true|false]")
@CommandCompletion("@empty @environments -s|-g|-t|-n|-a") @CommandCompletion("@empty @environments @worldSettings")
@Description("Creates a new world and loads it.") @Description("Creates a new world and loads it.")
public void onCreateCommand(@NotNull CommandSender sender, public void onCreateCommand(@NotNull CommandSender sender,