prevented saving duplicate command entries

This commit is contained in:
YouHaveTrouble
2020-11-25 19:22:51 +01:00
parent 6487255d04
commit 292cac7415
2 changed files with 4 additions and 1 deletions
@@ -52,6 +52,9 @@ public class ConfigCache {
} }
public boolean addCommand(String command, String group) { public boolean addCommand(String command, String group) {
try { try {
if (this.permList.get(group).contains(command)) {
return true;
}
this.permList.get(group).add(command); this.permList.get(group).add(command);
this.config.set("commands."+group, permList.get(group)); this.config.set("commands."+group, permList.get(group));
config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml"); config.save(CommandWhitelist.getPlugin().getDataFolder()+"/config.yml");
@@ -30,7 +30,7 @@ public class PlayerCommandPreProcessListener implements Listener {
String rawCmd = event.getMessage(); String rawCmd = event.getMessage();
List<String> bannedSubCommands = CommandsList.getSuggestions(player); List<String> bannedSubCommands = CommandsList.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) { for (String bannedSubCommand : bannedSubCommands) {
if (rawCmd.equalsIgnoreCase("/"+bannedSubCommand) || rawCmd.equalsIgnoreCase("/"+bannedSubCommand+" ")) { if (rawCmd.startsWith("/"+bannedSubCommand)) {
event.setCancelled(true); event.setCancelled(true);
ConfigCache config = CommandWhitelist.getConfigCache(); ConfigCache config = CommandWhitelist.getConfigCache();
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied()))); player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));