mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 14:38:58 +00:00
- 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.
This commit is contained in:
1 parent
93df8fb296
commit
4524260ce1
3 files changed
+18
-13
No files matched your search
@@ -7,7 +7,7 @@
|
|||||||
<groupId>com.palmergames.bukkit</groupId>
|
<groupId>com.palmergames.bukkit</groupId>
|
||||||
<artifactId>TownyChat</artifactId>
|
<artifactId>TownyChat</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.110</version>
|
<version>0.111</version>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
|
|||||||
@@ -479,3 +479,6 @@ v0.110:
|
|||||||
- Add CommentedConfiguration support to the channels.yml.
|
- Add CommentedConfiguration support to the channels.yml.
|
||||||
- The Comments in the file have been updated to include missing channel flags.
|
- 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.
|
||||||
@@ -37,7 +37,7 @@ public class ChannelsSettings {
|
|||||||
if (FileMgmt.checkOrCreateFile(filepath)) {
|
if (FileMgmt.checkOrCreateFile(filepath)) {
|
||||||
File file = new File(filepath);
|
File file = new File(filepath);
|
||||||
|
|
||||||
// read the config.yml into memory
|
// read the channels.yml into memory
|
||||||
channelConfig = new CommentedConfiguration(file.toPath());
|
channelConfig = new CommentedConfiguration(file.toPath());
|
||||||
if (!channelConfig.load()) {
|
if (!channelConfig.load()) {
|
||||||
Bukkit.getLogger().severe("[TownyChat] Failed to load Channels.yml!");
|
Bukkit.getLogger().severe("[TownyChat] Failed to load Channels.yml!");
|
||||||
@@ -91,7 +91,6 @@ public class ChannelsSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void tryAndSetDefaultChannels() {
|
private static void tryAndSetDefaultChannels() {
|
||||||
|
|
||||||
if (channelConfig.contains(CHANNELS_ROOT)) {
|
if (channelConfig.contains(CHANNELS_ROOT)) {
|
||||||
// There is already a root channels present, not our first run.
|
// There is already a root channels present, not our first run.
|
||||||
newChannelConfig.set(CHANNELS_ROOT, channelConfig.get(CHANNELS_ROOT));
|
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.");
|
Chat.getTownyChat().getLogger().info("TownyChat creating default channels.yml file.");
|
||||||
|
|
||||||
newChannelConfig.createSection(CHANNELS_ROOT);
|
newChannelConfig.createSection(CHANNELS_ROOT);
|
||||||
for (String channel : DEFAULT_CHANNELS)
|
DEFAULT_CHANNELS.forEach(channel -> newChannelConfig.createSection(CHANNELS_ROOT + "." + channel));
|
||||||
newChannelConfig.createSection(CHANNELS_ROOT + "." + channel);
|
|
||||||
|
|
||||||
ConfigurationSection configurationSection = newChannelConfig.getConfigurationSection(CHANNELS_ROOT);
|
setConfigSection("general", generalDefaults());
|
||||||
configurationSection.set("general", generalDefaults());
|
setConfigSection("town", townDefaults());
|
||||||
configurationSection.set("town", townDefaults());
|
setConfigSection("nation", nationDefaults());
|
||||||
configurationSection.set("nation", nationDefaults());
|
setConfigSection("alliance", allianceDefaults());
|
||||||
configurationSection.set("alliance", allianceDefaults());
|
setConfigSection("admin", adminDefaults());
|
||||||
configurationSection.set("admin", adminDefaults());
|
setConfigSection("mod", modDefaults());
|
||||||
configurationSection.set("mod", modDefaults());
|
setConfigSection("local", localDefaults());
|
||||||
configurationSection.set("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() {
|
private static Map<String, Object> generalDefaults() {
|
||||||
Map<String, Object> channelMap = new LinkedHashMap<>();
|
Map<String, Object> channelMap = new LinkedHashMap<>();
|
||||||
channelMap.put("commands", "g");
|
channelMap.put("commands", "g");
|
||||||
|
|||||||
Reference in new issue
Block a user