work on command completions

This commit is contained in:
YouHaveTrouble
2021-07-06 21:31:51 +02:00
parent 050e3e7af4
commit 017011fad0
4 changed files with 30 additions and 22 deletions
@@ -21,6 +21,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class CommandWhitelistBukkit extends JavaPlugin {
@@ -36,16 +36,16 @@ public class CWCommand {
Component component = MiniMessage.markdown().parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
.append(Component.newline());
component = component.append(Component.text("Hover over the command to see what it does!").color(NamedTextColor.AQUA)).decoration(TextDecoration.BOLD, false).append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" help").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Displays this message"))));
component = component.append(Component.text("/" + baseCommand + " help").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Displays this message"))));
if (showReloadCommand) {
component = component.append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" reload").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Reloads plugin configuration"))));
component = component.append(Component.text("/" + baseCommand + " reload").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Reloads plugin configuration"))));
}
if (showAdminCommands) {
component = component.append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" add <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Add a command to selected permission group"))));
component = component.append(Component.text("/" + baseCommand + " add <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Add a command to selected permission group"))));
component = component.append(Component.newline());
component = component.append(Component.text("/"+baseCommand+" remove <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Removes a command from selected permission group"))));
component = component.append(Component.text("/" + baseCommand + " remove <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Removes a command from selected permission group"))));
}
return component;
}
@@ -77,27 +77,27 @@ public class CWCommand {
case 3:
if (args[0].equalsIgnoreCase("remove")) {
if (!adminPerm) return list;
try {
for (String s : config.getGroupList().get(args[1]).getCommands()) {
CWGroup group = config.getGroupList().get(args[1]);
if (group == null) return list;
for (String s : group.getCommands()) {
if (s.startsWith(args[2]))
list.add(s);
}
} catch (NullPointerException ignored) {
}
return list;
}
if (args[0].equalsIgnoreCase("add")) {
if (!adminPerm) return list;
CWGroup group = config.getGroupList().get(args[1]);
if (group == null) return list;
for (String cmd : serverCommands) {
if (!cmd.startsWith("/")) continue;
if (cmd.startsWith("/"))
cmd = cmd.substring(1);
if (cmd.contains(":")) {
String[] cmdSplit = cmd.split(":");
if (cmdSplit.length < 2) continue;
cmd = cmd.split(":")[1];
cmd = cmdSplit[1];
}
cmd = cmd.replace("/", "");
if (config.getGroupList().get(args[1]) == null) continue;
if (config.getGroupList().get(args[1]).getCommands().contains(cmd)) continue;
if (group.getCommands().contains(cmd)) continue;
if (cmd.startsWith(args[2]))
list.add(cmd);
}
@@ -77,12 +77,11 @@ public class VelocityMainCommand implements SimpleCommand {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
return CompletableFuture.supplyAsync(() -> {
List<String> suggestions = new ArrayList<>();
if (args.length == 1) {
if (source.hasPermission(CWPermission.RELOAD.permission()) && "reload".startsWith(args[0]))
suggestions.add("reload");
}
return suggestions;
List<String> serverCommands = new ArrayList<>();
//TODO find out how to get all registered commands
// This is probably very broken now
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()));
});
}
}
@@ -11,6 +11,10 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class BungeeMainCommand extends Command implements TabExecutor {
public BungeeMainCommand(String name) {
@@ -77,6 +81,10 @@ public class BungeeMainCommand extends Command implements TabExecutor {
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
return null;
List<String> serverCommands = new ArrayList<>();
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
serverCommands.add(command.getValue().getName());
}
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()),sender.hasPermission(CWPermission.ADMIN.permission()));
}
}