From 94dcd640a14a3ee7f0c9ee84e460280ca0bd6a65 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Mon, 5 Jul 2021 03:38:12 +0200 Subject: [PATCH] update CM --- CommandWhitelistCommon/pom.xml | 2 +- .../commandwhitelist/common/ConfigCache.java | 32 +++++++++---------- .../common/commands/CWCommand.java | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CommandWhitelistCommon/pom.xml b/CommandWhitelistCommon/pom.xml index 8dea14a..286a375 100644 --- a/CommandWhitelistCommon/pom.xml +++ b/CommandWhitelistCommon/pom.xml @@ -62,7 +62,7 @@ com.github.Thatsmusic99 ConfigurationMaster - v2.0.0-ALPHA-2 + v2.0.0-ALPHA-3 compile diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java index 6c4b7f0..ee9e3af 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java @@ -17,7 +17,7 @@ public class ConfigCache { removed_from_whitelist, group_doesnt_exist, subcommand_denied; public boolean useProtocolLib = false; - public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger){ + public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) { this.configFile = configFile; this.canDoProtocolLib = canDoProtocolLib; this.logger = logger; @@ -27,7 +27,7 @@ public class ConfigCache { public boolean reloadConfig() { - boolean firstLoad = createFiles(); + createFiles(); config = ConfigFile.loadConfig(configFile); config.addDefault("messages.prefix", "CommandWhitelist > "); @@ -45,17 +45,18 @@ public class ConfigCache { if (canDoProtocolLib) config.addDefault("use_protocollib", false, "Do not enable if you don't have issues with aliased commands.\nThis requires server restart to take effect."); - if (firstLoad) { + if (config.isNew()) { List exampleCommands = new ArrayList<>(); exampleCommands.add("example"); List exampleSubCommands = new ArrayList<>(); exampleSubCommands.add("example of"); - config.addDefault("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\""); - config.addDefault("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\""); + config.addExample("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\""); + config.addExample("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\""); config.addComment("groups.example", "All groups except from default require commandwhitelist.group. permission\ncommandwhitelist.group.example in this case\n If you wish to leave the list empty, put \"commands: []\" or \"subcommands: []\""); } + config.makeSectionLenient("groups"); List defaultCommands = new ArrayList<>(); defaultCommands.add("help"); defaultCommands.add("spawn"); @@ -102,40 +103,39 @@ public class ConfigCache { } } - private boolean createFiles() { - boolean creatingFiles = false; + private void createFiles() { try { File parent = new File(configFile.getParent()); if (!parent.exists()) parent.mkdir(); - if (!configFile.exists()) { + if (!configFile.exists()) configFile.createNewFile(); - creatingFiles = true; - } - return creatingFiles; } catch (IOException e) { e.printStackTrace(); - return false; } } public CWGroup loadCWGroup(String id, ConfigSection section) { HashSet commands = new HashSet<>(); - for (String cmd : section.getStringList(id+".commands")) { + for (String cmd : section.getStringList(id + ".commands")) { if (cmd.contains(" ")) { String[] cmdSplit = cmd.split(" "); - warn("CommandWhitelist - \""+cmd+"\" is not a command. Loading it as \""+cmdSplit[0]+"\"."); + warn("CommandWhitelist - \"" + cmd + "\" is not a command. Loading it as \"" + cmdSplit[0] + "\"."); cmd = cmdSplit[0]; } - if (commands.contains(cmd)) continue; commands.add(cmd); } - List subCommands = section.getStringList(id+".subcommands"); + List subCommands = section.getStringList(id + ".subcommands"); return new CWGroup(id, commands, subCommands); } + public void saveCWGroup(String id, CWGroup group) { + config.set("groups." + id + ".", group.serialize()); + saveConfig(); + } + public HashMap getGroupList() { return groupList; } diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java index a91c36c..df0380d 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/commands/CWCommand.java @@ -15,7 +15,7 @@ public class CWCommand { if (cwGroup == null) return false; cwGroup.addCommand(command); - configCache.reloadConfig(); + configCache.saveCWGroup(group, cwGroup); return true; } @@ -24,7 +24,7 @@ public class CWCommand { if (cwGroup == null) return false; cwGroup.removeCommand(command); - configCache.reloadConfig(); + configCache.saveCWGroup(group, cwGroup); return true; }