From f8ea0bac84e6c14a1d15fd8c13bce1d2b713e683 Mon Sep 17 00:00:00 2001 From: Toxi Woxi <75816946+ToxiWoxi@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:46:22 -0500 Subject: [PATCH] Implement tab completion, bump version --- build.gradle | 2 +- gradle.properties | 2 +- .../java/de/butzlabben/world/WorldSystem.java | 1 + .../world/command/CommandRegistry.java | 43 ++++++++++++++++++- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index d091636..8ce5fdd 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ ext { mcVersion = "1.20.2" } archivesBaseName = "WorldSystem" -version = "2.4.36" +version = "2.4.37" spigot { group "de.butzlabben" name = "WorldSystem" diff --git a/gradle.properties b/gradle.properties index f027e9e..17e067f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginName = WorldSystem author = Trainerlord, Butzlabben & CrazyCloudCraft mcVersion = 1.20.2 apiVersion = 1.20 -version = 2.4.35 +version = 2.4.37 Vault = Vault WorldEdit = WorldEdit FAWE = FAWE diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java index 1fcaf59..da96041 100644 --- a/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -95,6 +95,7 @@ public class WorldSystem extends JavaPlugin { public void onEnable() { ////// getCommand("ws").setExecutor(new CommandRegistry()); + getCommand("ws").setTabCompleter(new CommandRegistry()); // Set right version if (VersionUtil.getVersion() >= 13) diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index 5e020c4..921bab4 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -5,12 +5,19 @@ import de.butzlabben.world.command.commands.WorldAdministrateCommand; import de.butzlabben.world.command.commands.WorldSettingsCommands; import de.butzlabben.world.util.Worldutils; import de.butzlabben.world.wrapper.WorldTemplateProvider; +import org.bukkit.Bukkit; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; -public class CommandRegistry implements CommandExecutor { +public class CommandRegistry implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -101,4 +108,36 @@ public class CommandRegistry implements CommandExecutor { } } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + List subCommands = Arrays.asList("get", "home", "sethome", "gui", "tp", "addmember", "delmember", "leave", "tnt", "fire", "togglegm", "togglebuild", "toggletp", "togglewe", "info", "reset", "delete"); + List playerCompletions = Arrays.asList("addmember", "delmember", "togglegm", "togglebuild", "toggletp", "togglewe", "delete"); + List completions = null; + + for(String s : subCommands) { + if (args.length == 1) { + if (s.startsWith(args[0].toLowerCase())) { + if (completions == null) { + completions = new ArrayList(); + } + + completions.add(s); + } + } + if (args.length == 2) { + completions = new ArrayList(); + if (playerCompletions.contains(args[0].toLowerCase())) { + for (Player p : Bukkit.getOnlinePlayers()) { + completions.add(p.getName()); + } + } + } + } + if (completions != null) { + Collections.sort(completions); + } + + return completions; + } }