Add tab complete for scripts.

This commit is contained in:
benwoo1110 2020-12-28 00:44:22 +08:00
parent 8f99d2c560
commit 22afd094b2
2 changed files with 19 additions and 2 deletions

View File

@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore.commandTools;
import buscript.Buscript;
import co.aikar.commands.BukkitCommandCompletionContext;
import co.aikar.commands.BukkitCommandExecutionContext;
import co.aikar.commands.CommandIssuer;
@ -56,6 +57,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
this.plugin = plugin;
this.worldManager = plugin.getMVWorldManager();
registerAsyncCompletion("scripts", this::suggestScripts);
registerAsyncCompletion("subCommands", this::suggestSubCommands);
registerAsyncCompletion("MVWorlds", this::suggestMVWorlds);
registerAsyncCompletion("unloadedWorlds", this::suggestUnloadedWorlds);
@ -73,6 +75,21 @@ public class MVCommandCompletions extends PaperCommandCompletions {
registerStaticCompletion("toggles", this::suggestToggles);
}
@NotNull
private Collection<String> suggestScripts(@NotNull BukkitCommandCompletionContext context) {
Buscript scriptAPI = this.plugin.getScriptAPI();
if (scriptAPI == null) {
return Collections.emptyList();
}
return Arrays.stream(scriptAPI.getScriptFolder().listFiles())
.unordered()
.filter(File::isFile)
.map(File::getName)
.filter(fileName -> !fileName.equals("scripts.bin"))
.collect(Collectors.toList());
}
@NotNull
private Collection<String> suggestSubCommands(@NotNull BukkitCommandCompletionContext context) {
String rootCmdName = context.getConfig();

View File

@ -33,7 +33,7 @@ public class ScriptCommand extends MultiverseCommand {
@Subcommand("script")
@CommandPermission("multiverse.core.script")
@Syntax("<script> [player]")
@CommandCompletion("@empty @players") //TODO ACF: tab-complete possible scripts.
@CommandCompletion("@scripts @players") //TODO ACF: tab-complete possible scripts.
@Description("Runs a script.")
public void onScriptCommand(@NotNull CommandSender sender,
@ -43,7 +43,7 @@ public class ScriptCommand extends MultiverseCommand {
@Syntax("[player]")
@Description("Player that you want to execute the script on.")
@NotNull @Flags("other|defaultself") Player player) {
@NotNull @Flags("other,defaultself") Player player) {
Buscript scriptAPI = this.plugin.getScriptAPI();
if (scriptAPI == null) {