Skip to content

Commit

Permalink
- Fix creation of channels.yml, opting to make channels into proper (#55
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
LlmDl authored Jan 18, 2024
1 parent 93df8fb commit 4524260
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit</groupId>
<artifactId>TownyChat</artifactId>
<packaging>jar</packaging>
<version>0.110</version>
<version>0.111</version>

<licenses>
<license>
Expand Down
5 changes: 4 additions & 1 deletion resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
28 changes: 15 additions & 13 deletions src/com/palmergames/bukkit/TownyChat/config/ChannelsSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static boolean loadCommentedChannelsConfig() {
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!");
Expand Down Expand Up @@ -91,7 +91,6 @@ private static void setNewProperty(String root, Object value) {
}

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));
Expand All @@ -100,20 +99,23 @@ private static void tryAndSetDefaultChannels() {
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<String,Object> settings) {
ConfigurationSection configurationSection = newChannelConfig.getConfigurationSection(CHANNELS_ROOT + "." + section);
settings.entrySet().stream().forEach(entry -> configurationSection.set(entry.getKey(), entry.getValue()));
}

private static Map<String, Object> generalDefaults() {
Map<String, Object> channelMap = new LinkedHashMap<>();
channelMap.put("commands", "g");
Expand Down

0 comments on commit 4524260

Please sign in to comment.