Implement tab completion, bump version

This commit is contained in:
Toxi Woxi 2023-11-21 20:46:22 -05:00
parent b5fbfebffd
commit f8ea0bac84
4 changed files with 44 additions and 4 deletions

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> subCommands = Arrays.asList("get", "home", "sethome", "gui", "tp", "addmember", "delmember", "leave", "tnt", "fire", "togglegm", "togglebuild", "toggletp", "togglewe", "info", "reset", "delete");
List<String> playerCompletions = Arrays.asList("addmember", "delmember", "togglegm", "togglebuild", "toggletp", "togglewe", "delete");
List<String> 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;
}
}