diff --git a/src/ChatConfig.yml b/src/ChatConfig.yml deleted file mode 100644 index 3acf11e..0000000 --- a/src/ChatConfig.yml +++ /dev/null @@ -1,103 +0,0 @@ - # The formats below will specify the changes made to the player chat when talking. - # These keys can be used in other plugins that modify the chat format like iChat. - - # {worldname} - Displays the world the player is currently in. - # {town} - Displays town name if a member of a town. - # {townformatted} - Displays town name (if a member of a town) using tag_format.town. - # {towntag} - Displays the formated town tag (if a member of a town) using modify_chat.tag_format.town. - # {towntagoverride} - Displays the formated town tag (if a member of a town and present) or falls back to the full name (using modify_chat.tag_format.town). - - # {nation} - Displays nation name if a member of a nation. - # {nationformatted} - Displays nation name (if a member of a nation) using tag_format.town. - # {nationtag} - Displays the formated nation tag (if a member of a nation) using modify_chat.tag_format.nation. - # {nationtagoverride} - Displays the formated nation tag (if a member of a nation and present) or falls back to the full name (using modify_chat.tag_format.nation). - - # {townytag} - Displays the formated town/nation tag as specified in modify_chat.tag_format.both. - # {townyformatted} - Displays the formated full town/nation names as specified in modify_chat.tag_format.both. - # {townytagoverride} - Displays the formated town/nation tag (if present) or falls back to the full names (using modify_chat.tag_format.both). - - # {title} - Towny resident Title - # {surname} - Towny resident surname - # {townynameprefix} - Towny name prefix taken from the townLevel/nationLevels - # {townynamepostfix} - Towny name postfix taken from the townLevel/nationLevels. - # {townyprefix} - Towny resident title, or townynameprefix if no title exists - # {townypostfix} - Towny resident surname, or townynamepostfix if no surname exists - - # {townycolor} - Towny name colour for king/mayor/resident - # {group} - Players group name pulled from your permissions plugin - # {permuserprefix} - Permission user prefix. - # {permusersuffix} - Permission user suffix. - # {permgroupprefix} - Permission group prefix. - # {permgroupsuffix} - Permission group suffix. - # {permprefix} - Permission group and user prefix. - # {permsuffix} - Permission group and user suffix. - - # {playername} - Default player name. - # {modplayername} - Modified player name (use if Towny is over writing some other plugins changes). - # {msg} - The message sent. - - # {channelTag} - Defined in the channels entry in Channels.yml - # {msgcolour} - Defined in the channels entry in Channels.yml - - # Text colouring - # -------------- - # Black = &0, Navy = &1, Green = &2, Blue = &3, Red = &4 - # Purple = &5, Gold = &6, LightGray = &7, Gray = &8 - # DarkPurple = &9, LightGreen = &a, LightBlue = &b - # Rose = &c, LightPurple = &d, Yellow = &e, White = &f - - # Text altering - # ------------- - # Bold = &l, Italics = &o, Underlined = &n, - # Magic = &k, Strike = &m, Reset = &r - - # Spam_time set the minimum time between messages to be flagged as spam - spam_time: [spam_time] - - # If using our updated HeroicDeath.jar and craftIRC 3.1 (dev), you can - #configure what IRC channels you want death messages relayed to. - HeroicDeathToIRC: - enabled: [hd_enable] - # comma delimited list of craftIRC channel tags 'admin,blah,blah'. - craftIRCTags: '[hd_tags]' - - channel_formats: - # This is the format which will be used for GLOBAL chat/channels. - # This is also the format used when you have modify_chat.enable: true, but use other plugins to handle chat. - global: '[globalformat]' - # TOWN channel types. - town: '[townformat]' - # NATION channel types. - nation: '[nationformat]' - # DEFAULT channel types. - default: '[defaultformat]' - - tag_formats: - world: '[tag_world]' - town: '[tag_town]' - nation: '[tag_nation]' - # First %s is the nation tag, second is the town tag. - # As of v0.50 , you can use %t & %n instead of %s and %s, this allows you to set the town first nation second or ignore the town/nation. - both: '[tag_both]' - - # Chat colours - colour: - king: '[colour_king]' - mayor: '[colour_mayor]' - resident: '[colour_resident]' - - modify_chat: - # This is used for when you don't have another plugin to format chat. - # or you want some other plugin to handle open chat, but want Towny formatting. - # It will cause Towny to overwrite any other plugins alterations to the format. - enable: '[modify_enable]' - # If true the chat formats will be read from below to allow per world formatting. - # These can then be altered individually. - per_world: '[modify_per_world]' - # If true any player who speaks in a channel in which he cannot be heard, - # either by being along in the channel or out-of-range of another player in his chat channel, - # that player will see a message saying they cannot be heard. - alone_message: '[modify_alone_message]' - # This allows you to set your alone message. - alone_message_string: '[modify_alone_message_string]' - worlds: diff --git a/src/changelog.txt b/src/changelog.txt index 0a9ee62..63bf8b6 100644 --- a/src/changelog.txt +++ b/src/changelog.txt @@ -214,4 +214,14 @@ v0.51: - New Permission node: townychat.chat.format.reset - default: everyone - Provides the ability to reset chat formatting to default using &r. - \ No newline at end of file +v0.52: + - Commented configuration now in effect on the ChatConfig.yml + - This means that new config nodes will be automatically added (just like in Towny.) + - pre-0.52 chatconfig files will load but will be slightly out of order. + - It is recommended that you let TownyChat make a brand new chatconfig.yml + - stop your server. + - rename your chatconfig.yml to oldchatconfig.yml and let town. + - start your server. + - compare the two chatconfigs and when your new chatconfig.yml is configured save it and use '/townychat reload'. + - The worlds section of the chatconfig will not auto-generate until the modify_chat.enable setting is set to true. + - If you do not see a worlds section and want to use per-world chat, set the modify_chat.enable setting to true and use '/townychat reload'. \ No newline at end of file diff --git a/src/com/palmergames/bukkit/TownyChat/Chat.java b/src/com/palmergames/bukkit/TownyChat/Chat.java index 454dbe2..2a7b26b 100644 --- a/src/com/palmergames/bukkit/TownyChat/Chat.java +++ b/src/com/palmergames/bukkit/TownyChat/Chat.java @@ -60,7 +60,7 @@ public class Chat extends JavaPlugin { checkPlugins(); try { - ChatSettings.loadNewConfig(getTowny().getDataFolder().getPath() + FileMgmt.fileSeparator() + "settings" + FileMgmt.fileSeparator() + "ChatConfig2.yml", this.getDescription().getVersion()); + ChatSettings.loadNewConfig(getTowny().getDataFolder().getPath() + FileMgmt.fileSeparator() + "settings" + FileMgmt.fileSeparator() + "chatconfig.yml", this.getDescription().getVersion()); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/com/palmergames/bukkit/TownyChat/config/ConfigurationHandler.java b/src/com/palmergames/bukkit/TownyChat/config/ConfigurationHandler.java index 9ac4f30..434eac1 100644 --- a/src/com/palmergames/bukkit/TownyChat/config/ConfigurationHandler.java +++ b/src/com/palmergames/bukkit/TownyChat/config/ConfigurationHandler.java @@ -1,8 +1,5 @@ package com.palmergames.bukkit.TownyChat.config; -import java.io.File; -import java.io.IOException; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -167,7 +164,7 @@ public class ConfigurationHandler { String filename = filepath + FileMgmt.fileSeparator() + defaultRes; // Pass the plugin reference so it can load the defaults if needed. - Map file = FileMgmt.getFile(filename, defaultRes, plugin); + Map file = FileMgmt.getFile(filename); if (file != null) { @@ -176,7 +173,7 @@ public class ConfigurationHandler { if (Key.equalsIgnoreCase("spam_time")) ChatSettings.setSpam_time( Double.parseDouble((file.get(Key)).toString()) ); - if (Key.equalsIgnoreCase("HeroicDeathToIRC")) { + if (Key.equalsIgnoreCase("heroicdeathtoirc")) { Map subNodes = (Map) file.get(Key); for (String element : subNodes.keySet()) { @@ -294,8 +291,8 @@ public class ConfigurationHandler { } - if (ChatSettings.populateWorldFormats()) - saveConfig(filename); +// if (ChatSettings.populateWorldFormats()) +// saveConfig(filename); return true; @@ -304,96 +301,96 @@ public class ConfigurationHandler { return false; } - private void saveConfig(String filepath) { - - File file = new File(filepath); - - if (file.exists() && file.isFile()) { - - String newConfig; - try { - newConfig = FileMgmt.convertStreamToString("/ChatConfig.yml"); - newConfig = setConfigs(newConfig, false); - - FileMgmt.stringToFile(newConfig, filepath); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - - } else { - // Big error. No file found. - } - - } +// private void saveConfig(String filepath) { +// +// File file = new File(filepath); +// +// if (file.exists() && file.isFile()) { +// +// String newConfig; +// try { +// newConfig = FileMgmt.convertStreamToString("/ChatConfig.yml"); +// newConfig = setConfigs(newConfig, false); +// +// FileMgmt.stringToFile(newConfig, filepath); +// +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// +// +// +// } else { +// // Big error. No file found. +// } +// +// } - /** - * Build the new Config file to save. - * - * @param newConfig - * @param defaults apply defaults or data from settings. - * @return the config in a string - */ - public String setConfigs(String newConfig, boolean defaults) { - - String global = "{channelTag} {worldname}{townytagoverride}{townycolor}{permprefix}{group} {townyprefix}{modplayername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}"; - String town = "{channelTag} {townycolor}{permprefix}{townyprefix}{playername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}"; - String nation = "{channelTag}{towntagoverride}{townycolor}{permprefix}{townyprefix}{playername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}"; - String default_ = "{channelTag} {permprefix}{playername}{permsuffix}&f:{msgcolour} {msg}"; - - String tag_world = "&f[&f%s&f] "; - String tag_town = "&f[&3%s&f] "; - String tag_nation = "&f[&e%s&f] "; - String tag_both = "&f[&6%s&f|&3%s&f] "; - - String king = "&6"; - String mayor = "&b"; - String resident = "&f"; - - - newConfig = newConfig.replace("[spam_time]", (defaults)? "0.5" : Double.toString(ChatSettings.getSpam_time())); - - newConfig = newConfig.replace("[hd_enable]", (defaults)? "true" : Boolean.toString(ChatSettings.isHeroicDeathToIRC())); - newConfig = newConfig.replace("[hd_tags]", (defaults)? "admin" : ChatSettings.getHeroicDeathTags()); - - newConfig = newConfig.replace("[globalformat]", (defaults)? global : ChatSettings.getFormatGroup("channel_formats").getGLOBAL()); - newConfig = newConfig.replace("[townformat]", (defaults)? town : ChatSettings.getFormatGroup("channel_formats").getTOWN()); - newConfig = newConfig.replace("[nationformat]", (defaults)? nation : ChatSettings.getFormatGroup("channel_formats").getNATION()); - newConfig = newConfig.replace("[defaultformat]", (defaults)? default_ : ChatSettings.getFormatGroup("channel_formats").getDEFAULT()); - - newConfig = newConfig.replace("[tag_world]", (defaults)? tag_world : ChatSettings.getWorldTag()); - newConfig = newConfig.replace("[tag_town]", (defaults)? tag_town : ChatSettings.getTownTag()); - newConfig = newConfig.replace("[tag_nation]", (defaults)? tag_nation : ChatSettings.getNationTag()); - newConfig = newConfig.replace("[tag_both]", (defaults)? tag_both : ChatSettings.getBothTags()); - - newConfig = newConfig.replace("[colour_king]", (defaults)? king : ChatSettings.getKingColour()); - newConfig = newConfig.replace("[colour_mayor]", (defaults)? mayor : ChatSettings.getMayorColour()); - newConfig = newConfig.replace("[colour_resident]", (defaults)? resident : ChatSettings.getResidentColour()); - - newConfig = newConfig.replace("[modify_enable]", (defaults)? "true" : Boolean.toString(ChatSettings.isModify_chat())); - newConfig = newConfig.replace("[modify_per_world]", (defaults)? "false" : Boolean.toString(ChatSettings.isPer_world())); - newConfig = newConfig.replace("[modify_alone_message]", (defaults)? "false" : Boolean.toString(ChatSettings.isUsingAloneMessage())); - newConfig = newConfig.replace("[modify_alone_message_string]", (defaults)? "No one in range can hear you or you are alone in this channel." : (ChatSettings.getUsingAloneMessageString())); - - for (String key : ChatSettings.getFormatGroups().keySet()) { - if (!key.equalsIgnoreCase("channel_formats")) { - channelFormats world = ChatSettings.getFormatGroup(key); - - newConfig += " '" + key + "':" + System.getProperty("line.separator"); - - newConfig += " global: '" + ((defaults)? global : world.getGLOBAL()) + "'" + System.getProperty("line.separator"); - newConfig += " town: '" + ((defaults)? town : world.getTOWN()) + "'" + System.getProperty("line.separator"); - newConfig += " nation: '" + ((defaults)? nation : world.getNATION()) + "'" + System.getProperty("line.separator"); - newConfig += " default: '" + ((defaults)? default_ : world.getDEFAULT()) + "'" + System.getProperty("line.separator"); - } - - } - - - return newConfig; - } +// /** +// * Build the new Config file to save. +// * +// * @param newConfig +// * @param defaults apply defaults or data from settings. +// * @return the config in a string +// */ +// public String setConfigs(String newConfig, boolean defaults) { +// +// String global = "{channelTag} {worldname}{townytagoverride}{townycolor}{permprefix}{group} {townyprefix}{modplayername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}"; +// String town = "{channelTag} {townycolor}{permprefix}{townyprefix}{playername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}"; +// String nation = "{channelTag}{towntagoverride}{townycolor}{permprefix}{townyprefix}{playername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}"; +// String default_ = "{channelTag} {permprefix}{playername}{permsuffix}&f:{msgcolour} {msg}"; +// +// String tag_world = "&f[&f%s&f] "; +// String tag_town = "&f[&3%s&f] "; +// String tag_nation = "&f[&e%s&f] "; +// String tag_both = "&f[&6%s&f|&3%s&f] "; +// +// String king = "&6"; +// String mayor = "&b"; +// String resident = "&f"; +// +// +// newConfig = newConfig.replace("[spam_time]", (defaults)? "0.5" : Double.toString(ChatSettings.getSpam_time())); +// +// newConfig = newConfig.replace("[hd_enable]", (defaults)? "true" : Boolean.toString(ChatSettings.isHeroicDeathToIRC())); +// newConfig = newConfig.replace("[hd_tags]", (defaults)? "admin" : ChatSettings.getHeroicDeathTags()); +// +// newConfig = newConfig.replace("[globalformat]", (defaults)? global : ChatSettings.getFormatGroup("channel_formats").getGLOBAL()); +// newConfig = newConfig.replace("[townformat]", (defaults)? town : ChatSettings.getFormatGroup("channel_formats").getTOWN()); +// newConfig = newConfig.replace("[nationformat]", (defaults)? nation : ChatSettings.getFormatGroup("channel_formats").getNATION()); +// newConfig = newConfig.replace("[defaultformat]", (defaults)? default_ : ChatSettings.getFormatGroup("channel_formats").getDEFAULT()); +// +// newConfig = newConfig.replace("[tag_world]", (defaults)? tag_world : ChatSettings.getWorldTag()); +// newConfig = newConfig.replace("[tag_town]", (defaults)? tag_town : ChatSettings.getTownTag()); +// newConfig = newConfig.replace("[tag_nation]", (defaults)? tag_nation : ChatSettings.getNationTag()); +// newConfig = newConfig.replace("[tag_both]", (defaults)? tag_both : ChatSettings.getBothTags()); +// +// newConfig = newConfig.replace("[colour_king]", (defaults)? king : ChatSettings.getKingColour()); +// newConfig = newConfig.replace("[colour_mayor]", (defaults)? mayor : ChatSettings.getMayorColour()); +// newConfig = newConfig.replace("[colour_resident]", (defaults)? resident : ChatSettings.getResidentColour()); +// +// newConfig = newConfig.replace("[modify_enable]", (defaults)? "true" : Boolean.toString(ChatSettings.isModify_chat())); +// newConfig = newConfig.replace("[modify_per_world]", (defaults)? "false" : Boolean.toString(ChatSettings.isPer_world())); +// newConfig = newConfig.replace("[modify_alone_message]", (defaults)? "false" : Boolean.toString(ChatSettings.isUsingAloneMessage())); +// newConfig = newConfig.replace("[modify_alone_message_string]", (defaults)? "No one in range can hear you or you are alone in this channel." : (ChatSettings.getUsingAloneMessageString())); +// +// for (String key : ChatSettings.getFormatGroups().keySet()) { +// if (!key.equalsIgnoreCase("channel_formats")) { +// channelFormats world = ChatSettings.getFormatGroup(key); +// +// newConfig += " '" + key + "':" + System.getProperty("line.separator"); +// +// newConfig += " global: '" + ((defaults)? global : world.getGLOBAL()) + "'" + System.getProperty("line.separator"); +// newConfig += " town: '" + ((defaults)? town : world.getTOWN()) + "'" + System.getProperty("line.separator"); +// newConfig += " nation: '" + ((defaults)? nation : world.getNATION()) + "'" + System.getProperty("line.separator"); +// newConfig += " default: '" + ((defaults)? default_ : world.getDEFAULT()) + "'" + System.getProperty("line.separator"); +// } +// +// } +// +// +// return newConfig; +// } } \ No newline at end of file diff --git a/src/com/palmergames/bukkit/TownyChat/util/FileMgmt.java b/src/com/palmergames/bukkit/TownyChat/util/FileMgmt.java index 2d480eb..30e94d1 100644 --- a/src/com/palmergames/bukkit/TownyChat/util/FileMgmt.java +++ b/src/com/palmergames/bukkit/TownyChat/util/FileMgmt.java @@ -31,6 +31,37 @@ public class FileMgmt { } } + @SuppressWarnings("unchecked") + public static Map getFile(String filepath) { + + try { + File f = new File(filepath); + + Yaml yamlChannels = new Yaml(new SafeConstructor()); + Object channelsRootDataNode; + + FileInputStream fileInputStream = new FileInputStream(f); + try { + channelsRootDataNode = yamlChannels.load(new UnicodeReader(fileInputStream)); + if (channelsRootDataNode == null) { + throw new NullPointerException(); + } + } catch (Exception ex) { + throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + f.getPath(), ex); + } finally { + fileInputStream.close(); + } + + if (channelsRootDataNode instanceof Map) + return (Map) channelsRootDataNode; + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } @SuppressWarnings("unchecked") public static Map getFile(String filepath, String resource, Chat plugin) { @@ -41,8 +72,6 @@ public class FileMgmt { try { String resString = convertStreamToString("/" + resource); // If we have a plugin reference pass to load default. - if (plugin != null) - resString = plugin.getConfigurationHandler().setConfigs(resString, true); FileMgmt.stringToFile(resString, filepath);