diff --git a/src/main/java/de/rayzs/pat/api/storage/Storage.java b/src/main/java/de/rayzs/pat/api/storage/Storage.java index b8af13fe..0c46fc73 100644 --- a/src/main/java/de/rayzs/pat/api/storage/Storage.java +++ b/src/main/java/de/rayzs/pat/api/storage/Storage.java @@ -112,6 +112,7 @@ public class Storage { public static NotificationSection NOTIFICATION = new NotificationSection(); public static OnlyForProxySection NO_PROXY = new OnlyForProxySection(); public static ReloadSection RELOAD = new ReloadSection(); + public static ServerListSection SERV_LIST = new ServerListSection(); public static StatsSection STATS = new StatsSection(); public static void initialize() {} diff --git a/src/main/java/de/rayzs/pat/api/storage/config/messages/ServerListSection.java b/src/main/java/de/rayzs/pat/api/storage/config/messages/ServerListSection.java new file mode 100644 index 00000000..066a48c9 --- /dev/null +++ b/src/main/java/de/rayzs/pat/api/storage/config/messages/ServerListSection.java @@ -0,0 +1,32 @@ +package de.rayzs.pat.api.storage.config.messages; + +import de.rayzs.pat.api.storage.storages.ConfigStorage; +import de.rayzs.pat.utils.Reflection; +import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper; + +public class ServerListSection extends ConfigStorage { + + public String SERVER_DOES_NOT_EXIST, GROUP_DOES_NOT_EXIST; + public String LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER, LIST_SERVER_COMMAND, LIST_GROUP_MESSAGE, LIST_GROUP_SPLITTER, LIST_GROUP_COMMAND; + + public ServerListSection() { + super("server-list"); + } + + @Override + public void load() { + super.load(); + if(!Reflection.isProxyServer()) return; + + SERVER_DOES_NOT_EXIST = new ConfigSectionHelper(this, "server-not-found", "&cThe server %server% does not have any commands!").getOrSet(); + GROUP_DOES_NOT_EXIST = new ConfigSectionHelper(this, "group-does-not-exist", "&cGroup %group% does not exist for %server%!").getOrSet(); + + LIST_SERVER_MESSAGE = new ConfigSectionHelper(this, "list.server.message", "&7Listed commands of %server% (&f%size%&7)&8: &f%commands%").getOrSet(); + LIST_SERVER_SPLITTER = new ConfigSectionHelper(this, "list.server.splitter", "&7, ").getOrSet(); + LIST_SERVER_COMMAND = new ConfigSectionHelper(this, "list.server.command", "&f%command%").getOrSet(); + + LIST_GROUP_MESSAGE = new ConfigSectionHelper(this, "list.group.message", "&7Listed commands of %group% from %server% (&f%size%&7)&8: &f%commands%").getOrSet(); + LIST_GROUP_SPLITTER = new ConfigSectionHelper(this, "list.group.splitter", "&7, ").getOrSet(); + LIST_GROUP_COMMAND = new ConfigSectionHelper(this, "list.group.command", "&f%command%").getOrSet(); + } +} diff --git a/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java b/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java index e8a5f88a..a20ad18a 100644 --- a/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java +++ b/src/main/java/de/rayzs/pat/plugin/process/CommandProcess.java @@ -313,6 +313,29 @@ public class CommandProcess { sender.sendMessage(Storage.ConfigSections.Messages.BLACKLIST.CLEAR_SERVER_CONFIRM.replace("%server%", sub)); } return; + + case "ls": case "list": + if (!Reflection.isProxyServer()) { + sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE); + return; + } + + if(!BlacklistCreator.exist(sub)) { + sender.sendMessage(Storage.ConfigSections.Messages.SERV_LIST.SERVER_DOES_NOT_EXIST.replace("%server%", sub)); + return; + } + + StringBuilder commandsBuilder = new StringBuilder(); + for (int i = 0; i < Storage.Blacklist.getBlacklist(sub).getCommands().size(); i++) { + bool = (i >= Storage.Blacklist.getBlacklist(sub).getCommands().size() - 1); + commandsBuilder.append(Storage.ConfigSections.Messages.SERV_LIST.LIST_SERVER_COMMAND.replace("%command%", Storage.Blacklist.getBlacklist(sub).getCommands().get(i))); + if (!bool) + commandsBuilder.append(Storage.ConfigSections.Messages.SERV_LIST.LIST_SERVER_SPLITTER); + } + + sender.sendMessage(Storage.ConfigSections.Messages.SERV_LIST.LIST_SERVER_MESSAGE.replace("%server%", sub.toLowerCase()).replace("%size%", String.valueOf(Storage.Blacklist.getBlacklist(sub).getCommands().size())).replace("%commands%", commandsBuilder.toString())); + return; + } } @@ -409,6 +432,29 @@ public class CommandProcess { sender.sendMessage(Storage.ConfigSections.Messages.GROUP.CLEAR_SERVER_CONFIRM.replace("%group%", extra).replace("%server%", sub)); } return; + + case "ls": case "list": + if(!BlacklistCreator.exist(sub)) { + sender.sendMessage(Storage.ConfigSections.Messages.SERV_LIST.SERVER_DOES_NOT_EXIST.replace("%server%", sub)); + return; + } + + group = GroupManager.getGroupByName(extra); + if(!BlacklistCreator.exist(extra, sub) || group == null) { + sender.sendMessage(Storage.ConfigSections.Messages.SERV_LIST.GROUP_DOES_NOT_EXIST.replace("%server%", sub)); + return; + } + + StringBuilder commandsBuilder = new StringBuilder(); + for (int i = 0; i < group.getCommands(sub).size(); i++) { + bool = (i >= group.getCommands(sub).size() - 1); + commandsBuilder.append(Storage.ConfigSections.Messages.SERV_LIST.LIST_GROUP_COMMAND.replace("%command%", group.getCommands(sub).get(i))); + if (!bool) + commandsBuilder.append(Storage.ConfigSections.Messages.SERV_LIST.LIST_GROUP_SPLITTER); + } + + sender.sendMessage(Storage.ConfigSections.Messages.SERV_LIST.LIST_GROUP_MESSAGE.replace("%group%", group.getGroupName()).replace("%server%", sub.toLowerCase()).replace("%size%", String.valueOf(group.getCommands(sub).size())).replace("%commands%", commandsBuilder.toString())); + return; } } @@ -512,7 +558,7 @@ public class CommandProcess { if (!backend && Arrays.asList("ls", "list").contains(args[0].toLowerCase()) && PermissionUtil.hasPermission(sender, "list")) suggestions.addAll(GroupManager.getGroupNames()); if (Reflection.isProxyServer() && Arrays.asList("lg", "listgroups").contains(args[0].toLowerCase()) && PermissionUtil.hasPermission(sender, "listgroups")) - suggestions.addAll(ClientCommunication.getRegisteredServerNames()); + suggestions.addAll(Storage.Blacklist.getBlacklistServers()); if (Reflection.isProxyServer() && Arrays.asList("serv", "server").contains(args[0].toLowerCase())) { if (PermissionUtil.hasPermission(sender, "add")) suggestions.add("add"); if (PermissionUtil.hasPermission(sender, "remove")) @@ -538,6 +584,8 @@ public class CommandProcess { suggestions.addAll(Storage.Blacklist.getBlacklistServers()); if (args[1].equals("clear") && PermissionUtil.hasPermission(sender, "clear")) suggestions.addAll(Storage.Blacklist.getBlacklistServers()); + if (Arrays.asList("list", "ls").contains(args[1].toLowerCase()) && PermissionUtil.hasPermission(sender, "list")) + suggestions.addAll(Storage.Blacklist.getBlacklistServers()); } break; @@ -546,6 +594,10 @@ public class CommandProcess { if (Arrays.asList("remove", "rem", "rm").contains(args[1].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove")) { suggestions.addAll(Storage.Blacklist.getBlacklist(args[2]).getCommands()); } + + if (Arrays.asList("list", "ls").contains(args[1].toLowerCase()) && PermissionUtil.hasPermission(sender, "list")) + suggestions.addAll(GroupManager.getGroupNamesByServer(args[2])); + if (args[1].equals("clear") && PermissionUtil.hasPermission(sender, "clear")) suggestions.addAll(GroupManager.getGroupNamesByServer(args[2])); }