mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-20 14:32:18 +01:00
Add tab complete for scripts.
This commit is contained in:
parent
8f99d2c560
commit
22afd094b2
@ -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();
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user