From 38d71e5ef914c58cd06207e2e389c9e7a7f13f77 Mon Sep 17 00:00:00 2001 From: Draycia Date: Mon, 29 Jun 2020 09:03:34 -0700 Subject: [PATCH] Config improvements --- .../simplechat/managers/ChannelManager.java | 27 ++++++++++++++ src/main/resources/config.yml | 35 ++++++++++++------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/draycia/simplechat/managers/ChannelManager.java b/src/main/java/net/draycia/simplechat/managers/ChannelManager.java index c17b0c20..379b47cc 100644 --- a/src/main/java/net/draycia/simplechat/managers/ChannelManager.java +++ b/src/main/java/net/draycia/simplechat/managers/ChannelManager.java @@ -24,6 +24,7 @@ public class ChannelManager { ChatChannel.Builder builder; ConfigurationSection section = simpleChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key); + ConfigurationSection defaults = simpleChat.getConfig().getConfigurationSection("default"); if (section.contains("is-town-chat")) { builder = TownChatChannel.townBuilder(key); @@ -54,6 +55,16 @@ public class ChannelManager { formats.put(group, formatSection.getString(group)); } + builder.setFormats(formats); + } else if (defaults != null && defaults.contains("formats")) { + HashMap formats = new HashMap<>(); + + ConfigurationSection formatSection = defaults.getConfigurationSection("formats"); + + for (String group : formatSection.getKeys(false)) { + formats.put(group, formatSection.getString(group)); + } + builder.setFormats(formats); } @@ -63,10 +74,14 @@ public class ChannelManager { if (section.contains("switch-message")) { builder.setSwitchMessage(section.getString("switch-message")); + } else if (defaults != null && defaults.contains("switch-message")) { + builder.setSwitchMessage(defaults.getString("switch-message")); } if (section.contains("distance")) { builder.setDistance(section.getDouble("distance")); + } else if (defaults != null && defaults.contains("distance")) { + builder.setDistance(defaults.getDouble("distance")); } if (section.contains("name")) { @@ -75,10 +90,14 @@ public class ChannelManager { if (section.contains("color")) { builder.setColor(section.getString("color")); + } else if (defaults != null && defaults.contains("color")) { + builder.setColor(defaults.getString("color")); } if (section.contains("ignorable")) { builder.setIgnorable(section.getBoolean("ignorable")); + } else if (defaults != null && defaults.contains("ignorable")) { + builder.setIgnorable(defaults.getBoolean("ignorable")); } if (section.contains("default")) { @@ -87,18 +106,26 @@ public class ChannelManager { if (section.contains("toggle-on-message")) { builder.setToggleOnMessage(section.getString("toggle-on-message")); + } else if (defaults != null && defaults.contains("toggle-on-message")) { + builder.setToggleOnMessage(defaults.getString("toggle-on-message")); } if (section.contains("toggle-off-message")) { builder.setToggleOffMessage(section.getString("toggle-off-message")); + } else if (defaults != null && defaults.contains("toggle-off-message")) { + builder.setToggleOffMessage(defaults.getString("toggle-off-message")); } if (section.contains("forward-format")) { builder.setShouldForwardFormatting(section.getBoolean("forward-format")); + } else if (defaults != null && defaults.contains("forward-format")) { + builder.setShouldForwardFormatting(defaults.getBoolean("forward-format")); } if (section.contains("should-bungee")) { builder.setShouldBungee(section.getBoolean("should-bungee")); + } else if (defaults != null && defaults.contains("should-bungee")) { + builder.setShouldBungee(defaults.getBoolean("should-bungee")); } ChatChannel channel = builder.build(simpleChat); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9af8bcc5..3b505901 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,23 +3,34 @@ # All placeholders should be prefixed with
 and suffixed with 
# Failure to do so may and likely will result in users being able to inject formatting in messages. +# All of the settings under this 'default' section can be applied to each channel individually to override these. +# These are provided as a way to configure default channel settings. +default: + switch-message: 'You are now in chat!' + toggle-on-message: 'You can now see chat!' + toggle-off-message: 'You can no longer see chat!' + formats: + discord-to-mc: '[Discord] :
' # Placeholders: username, displayname, channel, server, message, primaryrole
+    staff: '{[%vault_prefix%]} %player_displayname% » 
'
+    default: '[%vault_prefix%] %player_displayname%: 
'
+  color: '#FFFFFF' # Removing this option defaults to '#FFFFFF'
+  ignorable: true # Removing this option defaults to 'true'
+  distance: -1 # Set to -1, comment out, or remove to disable distance checking
+  forward-format: true # Removing this option defaults to 'true'. Forces all other servers to use this server's formatting for this channel.
+  should-bungee: true # Removing this option defaults to 'false'. Enables/disables cross server chat for this channel.
+
 channels:
   global:
+    name: 'Global'
     id: -1 # Set to -1, comment out, or remove to disable channel bridge
-    switch-message: 'You are now in  chat!'
-    toggle-on-message: 'You can now see  chat!'
-    toggle-off-message: 'You can no longer see  chat!'
-    formats:
-      discord-to-mc: '[Discord] : 
' # Placeholders: username, displayname, channel, server, message, primaryrole
-      staff: '{[%deluxetags_tag%]} %player_displayname% » 
'
-      default: '[%deluxetags_tag%] %player_displayname%: 
'
     webhook: 'URL_HERE' # Comment out / remove to disable webhook
-    color: '#FFFFFF' # Removing this option defaults to '#FFFFFF'
     default: true # Removing this option defaults to 'false'
-    ignorable: true # Removing this option defaults to 'true'
-    distance: -1 # Set to -1, comment out, or remove to disable distance checking
-    forward-format: true # Removing this option defaults to 'true'. Forces all other servers to use this server's formatting for this channel.
-    should-bungee: true # Removing this option defaults to 'false'. Enables/disables cross server chat for this channel.
+  announcements:
+    name: 'Announcements'
+    formats:
+      default: 'Broadcast: 
' + ignorable: false + should-bungee: false bot-token: -1