From 0859854af0f49d85f8051fd531abbe9e40cae15b Mon Sep 17 00:00:00 2001 From: Brettflan Date: Fri, 3 Jun 2011 13:06:41 -0500 Subject: [PATCH] New chat tag placement options to have it replace a specified string (such as the default "{FACTION}"), put the tag before or after a specified string (such as "<" or ">"), and whether to pad the front or back of the tag with an extra " ". --- src/org/mcteam/factions/Conf.java | 8 +++- .../listeners/FactionsPlayerListener.java | 37 +++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index 11e30fdf..674c5663 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -43,12 +43,16 @@ public class Conf { public static boolean CanLeaveWithNegativePower = true; // Configuration on the Faction tag in chat messages. - public static boolean preloadChatPlugins = true; public static boolean chatTagEnabled = true; public static boolean chatTagRelationColored = true; + public static String chatTagReplaceString = "{FACTION}"; + public static String chatTagInsertAfterString = ""; + public static String chatTagInsertBeforeString = ""; public static int chatTagInsertIndex = 1; - public static String chatTagFormat = "%s"+ChatColor.WHITE+" "; + public static boolean chatTagPadBefore = false; + public static boolean chatTagPadAfter = true; + public static String chatTagFormat = "%s"+ChatColor.WHITE; public static String factionChatFormat = "%s"+ChatColor.WHITE+" %s"; public static boolean allowNoSlashCommand = true; diff --git a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java index 812aa441..1e1ad765 100644 --- a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java @@ -67,14 +67,35 @@ public class FactionsPlayerListener extends PlayerListener{ return; } - int InsertIndex = Conf.chatTagInsertIndex; - if (InsertIndex > event.getFormat().length()) - return; - - String formatStart = event.getFormat().substring(0, InsertIndex); - String formatEnd = event.getFormat().substring(InsertIndex); + int InsertIndex = 0; + String eventFormat = event.getFormat(); - String nonColoredMsgFormat = formatStart + me.getChatTag() + formatEnd; + if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) { + // we're using the "replace" method of inserting the faction tags + InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString); + eventFormat = eventFormat.replace(Conf.chatTagReplaceString, ""); + Conf.chatTagPadAfter = false; + Conf.chatTagPadBefore = false; + } + else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString)) { + // we're using the "insert after string" method + InsertIndex = eventFormat.indexOf(Conf.chatTagInsertAfterString) + Conf.chatTagInsertAfterString.length(); + } + else if (!Conf.chatTagInsertBeforeString.isEmpty() && eventFormat.contains(Conf.chatTagInsertBeforeString)) { + // we're using the "insert before string" method + InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString); + } + else { + // we'll fall back to using the index place method + InsertIndex = Conf.chatTagInsertIndex; + if (InsertIndex > eventFormat.length()) + return; + } + + String formatStart = eventFormat.substring(0, InsertIndex) + (Conf.chatTagPadBefore ? " " : ""); + String formatEnd = (Conf.chatTagPadAfter ? " " : "") + eventFormat.substring(InsertIndex); + + String nonColoredMsgFormat = formatStart + me.getChatTag().trim() + formatEnd; // Relation Colored? if (Conf.chatTagRelationColored) { @@ -84,7 +105,7 @@ public class FactionsPlayerListener extends PlayerListener{ for (Player listeningPlayer : Factions.instance.getServer().getOnlinePlayers()) { FPlayer you = FPlayer.get(listeningPlayer); - String yourFormat = formatStart + me.getChatTag(you) + formatEnd; + String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd; listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg)); }