mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-22 07:21:58 +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;
|
package com.onarandombox.MultiverseCore.commandTools;
|
||||||
|
|
||||||
|
import buscript.Buscript;
|
||||||
import co.aikar.commands.BukkitCommandCompletionContext;
|
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||||
import co.aikar.commands.CommandIssuer;
|
import co.aikar.commands.CommandIssuer;
|
||||||
@ -56,6 +57,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.worldManager = plugin.getMVWorldManager();
|
this.worldManager = plugin.getMVWorldManager();
|
||||||
|
|
||||||
|
registerAsyncCompletion("scripts", this::suggestScripts);
|
||||||
registerAsyncCompletion("subCommands", this::suggestSubCommands);
|
registerAsyncCompletion("subCommands", this::suggestSubCommands);
|
||||||
registerAsyncCompletion("MVWorlds", this::suggestMVWorlds);
|
registerAsyncCompletion("MVWorlds", this::suggestMVWorlds);
|
||||||
registerAsyncCompletion("unloadedWorlds", this::suggestUnloadedWorlds);
|
registerAsyncCompletion("unloadedWorlds", this::suggestUnloadedWorlds);
|
||||||
@ -73,6 +75,21 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
|||||||
registerStaticCompletion("toggles", this::suggestToggles);
|
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
|
@NotNull
|
||||||
private Collection<String> suggestSubCommands(@NotNull BukkitCommandCompletionContext context) {
|
private Collection<String> suggestSubCommands(@NotNull BukkitCommandCompletionContext context) {
|
||||||
String rootCmdName = context.getConfig();
|
String rootCmdName = context.getConfig();
|
||||||
|
@ -33,7 +33,7 @@ public class ScriptCommand extends MultiverseCommand {
|
|||||||
@Subcommand("script")
|
@Subcommand("script")
|
||||||
@CommandPermission("multiverse.core.script")
|
@CommandPermission("multiverse.core.script")
|
||||||
@Syntax("<script> [player]")
|
@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.")
|
@Description("Runs a script.")
|
||||||
public void onScriptCommand(@NotNull CommandSender sender,
|
public void onScriptCommand(@NotNull CommandSender sender,
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class ScriptCommand extends MultiverseCommand {
|
|||||||
|
|
||||||
@Syntax("[player]")
|
@Syntax("[player]")
|
||||||
@Description("Player that you want to execute the script on.")
|
@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();
|
Buscript scriptAPI = this.plugin.getScriptAPI();
|
||||||
if (scriptAPI == null) {
|
if (scriptAPI == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user