From 4524260ce13aae163442cef45777cfbcb06a3c5a Mon Sep 17 00:00:00 2001 From: LlmDl Date: Thu, 18 Jan 2024 11:00:02 -0600 Subject: [PATCH 1/2] - Fix creation of channels.yml, opting to make channels into proper (#55) ConfigurationSections rather than Maps which aren't easily read on their first creation and then subsequent load. - It is no longer recommended to delete your channels.yml when updating from TownyChat 0.109 or earlier. --- pom.xml | 2 +- resources/changelog.txt | 5 +++- .../TownyChat/config/ChannelsSettings.java | 28 ++++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 892b2d2..e99fab4 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.palmergames.bukkit TownyChat jar - 0.110 + 0.111 diff --git a/resources/changelog.txt b/resources/changelog.txt index 90d3785..c8ece52 100644 --- a/resources/changelog.txt +++ b/resources/changelog.txt @@ -478,4 +478,7 @@ v0.110: - Update min. Towny version to 0.100.0.0. - Add CommentedConfiguration support to the channels.yml. - The Comments in the file have been updated to include missing channel flags. - - It is now possible to update the file comments as new flags are added. \ No newline at end of file + - It is now possible to update the file comments as new flags are added. +v0.111: + - Fix creation of channels.yml, opting to make channels into proper ConfigurationSections rather than Maps which aren't easily read on their first creation and then subsequent load. + - It is no longer recommended to delete your channels.yml when updating from TownyChat 0.109 or earlier. \ No newline at end of file diff --git a/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java b/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java index 1d7a286..5f02e37 100644 --- a/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java +++ b/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java @@ -37,7 +37,7 @@ public class ChannelsSettings { if (FileMgmt.checkOrCreateFile(filepath)) { File file = new File(filepath); - // read the config.yml into memory + // read the channels.yml into memory channelConfig = new CommentedConfiguration(file.toPath()); if (!channelConfig.load()) { Bukkit.getLogger().severe("[TownyChat] Failed to load Channels.yml!"); @@ -91,7 +91,6 @@ public class ChannelsSettings { } private static void tryAndSetDefaultChannels() { - if (channelConfig.contains(CHANNELS_ROOT)) { // There is already a root channels present, not our first run. newChannelConfig.set(CHANNELS_ROOT, channelConfig.get(CHANNELS_ROOT)); @@ -100,20 +99,23 @@ public class ChannelsSettings { Chat.getTownyChat().getLogger().info("TownyChat creating default channels.yml file."); newChannelConfig.createSection(CHANNELS_ROOT); - for (String channel : DEFAULT_CHANNELS) - newChannelConfig.createSection(CHANNELS_ROOT + "." + channel); - - ConfigurationSection configurationSection = newChannelConfig.getConfigurationSection(CHANNELS_ROOT); - configurationSection.set("general", generalDefaults()); - configurationSection.set("town", townDefaults()); - configurationSection.set("nation", nationDefaults()); - configurationSection.set("alliance", allianceDefaults()); - configurationSection.set("admin", adminDefaults()); - configurationSection.set("mod", modDefaults()); - configurationSection.set("local", localDefaults()); + DEFAULT_CHANNELS.forEach(channel -> newChannelConfig.createSection(CHANNELS_ROOT + "." + channel)); + + setConfigSection("general", generalDefaults()); + setConfigSection("town", townDefaults()); + setConfigSection("nation", nationDefaults()); + setConfigSection("alliance", allianceDefaults()); + setConfigSection("admin", adminDefaults()); + setConfigSection("mod", modDefaults()); + setConfigSection("local", localDefaults()); } } + private static void setConfigSection(String section, Map settings) { + ConfigurationSection configurationSection = newChannelConfig.getConfigurationSection(CHANNELS_ROOT + "." + section); + settings.entrySet().stream().forEach(entry -> configurationSection.set(entry.getKey(), entry.getValue())); + } + private static Map generalDefaults() { Map channelMap = new LinkedHashMap<>(); channelMap.put("commands", "g"); From 5f0ef74b2093826dba37cccc473aff3c0d149a04 Mon Sep 17 00:00:00 2001 From: LlmDl Date: Mon, 22 Jan 2024 08:40:04 -0600 Subject: [PATCH 2/2] Fix local channel having default: true, enable upper-case channel names. (#56) * Fix local channel having default: true, enable upper-case channel names. * remove commented-out code. --- pom.xml | 2 +- .../bukkit/TownyChat/config/ChannelsSettings.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e99fab4..54c1d73 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.palmergames.bukkit TownyChat jar - 0.111 + 0.112 diff --git a/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java b/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java index 5f02e37..b9c1f83 100644 --- a/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java +++ b/src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java @@ -17,7 +17,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; @@ -194,7 +193,6 @@ public class ChannelsSettings { channelMap.put("channelTag", "&f[local]"); channelMap.put("messagecolour", "&f"); channelMap.put("permission", "towny.chat.local"); - channelMap.put("default", "true"); channelMap.put("range", "100"); return channelMap; } @@ -220,7 +218,7 @@ public class ChannelsSettings { Chat plugin = Chat.getTownyChat(); channelsKeys.forEach((channelName)-> { - Channel channel = new StandardChannel(plugin, channelName.toLowerCase(Locale.ROOT)); + Channel channel = new StandardChannel(plugin, channelName); loadChannelSettings(channelName, channel); plugin.getChannelsHandler().addChannel(channel); }); @@ -275,7 +273,7 @@ public class ChannelsSettings { */ public ChannelDetails(CommentedConfiguration channelsConfig, String name) { super(); - this.name = name.toLowerCase(Locale.ROOT); + this.name = name; String path = CHANNELS_ROOT + "." + this.name; for (String key : channelsConfig.getConfigurationSection(path).getKeys(true)) { String innerPath = path + "." + key;