cleanup&fixup

This commit is contained in:
YouHaveTrouble
2021-07-17 17:41:44 +02:00
parent 017011fad0
commit 14f15aa754
5 changed files with 13 additions and 16 deletions
@@ -26,7 +26,6 @@ public class MainCommandExecutor implements TabExecutor {
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
return true; return true;
} }
try { try {
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase()); CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
switch (commandType) { switch (commandType) {
@@ -16,8 +16,7 @@ public class CWCommand {
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) { public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
CWGroup cwGroup = configCache.getGroupList().get(group); CWGroup cwGroup = configCache.getGroupList().get(group);
if (cwGroup == null) if (cwGroup == null) return false;
return false;
cwGroup.addCommand(command); cwGroup.addCommand(command);
configCache.saveCWGroup(group, cwGroup); configCache.saveCWGroup(group, cwGroup);
return true; return true;
@@ -57,6 +56,7 @@ public class CWCommand {
public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) { public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
switch (args.length) { switch (args.length) {
case 0:
case 1: case 1:
if ("reload".startsWith(args[0]) && reloadPerm) if ("reload".startsWith(args[0]) && reloadPerm)
list.add("reload"); list.add("reload");
+1 -1
View File
@@ -82,7 +82,7 @@
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>1.1.0</version> <version>3.0.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -105,10 +105,11 @@ public class CommandWhitelistVelocity {
HashMap<String, CWGroup> groups = configCache.getGroupList(); HashMap<String, CWGroup> groups = configCache.getGroupList();
HashSet<String> commandList = new HashSet<>(); HashSet<String> commandList = new HashSet<>();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
CWGroup group = s.getValue();
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
commandList.addAll(s.getValue().getCommands()); commandList.addAll(group.getCommands());
else if (player.hasPermission(s.getValue().getPermission())) else if (player.hasPermission(group.getPermission()))
commandList.addAll(s.getValue().getCommands()); commandList.addAll(group.getCommands());
} }
return commandList; return commandList;
} }
@@ -42,11 +42,11 @@ public class VelocityMainCommand implements SimpleCommand {
} }
if (args.length == 3) { if (args.length == 3) {
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1])) if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist)); sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
else else
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist)); sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else } else
sender.sendMessage(Component.text("/"+label+" add <group> <command>")); sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
return; return;
case REMOVE: case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) { if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
@@ -55,11 +55,11 @@ public class VelocityMainCommand implements SimpleCommand {
} }
if (args.length == 3) { if (args.length == 3) {
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1])) if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist)); sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
else else
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist)); sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else } else
sender.sendMessage(Component.text("/"+label+" remove <group> <command>")); sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
return; return;
case HELP: case HELP:
default: default:
@@ -78,9 +78,6 @@ public class VelocityMainCommand implements SimpleCommand {
String[] args = invocation.arguments(); String[] args = invocation.arguments();
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
List<String> serverCommands = new ArrayList<>(); 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())); return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()));
}); });
} }