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 " ".

This commit is contained in:
Brettflan 2011-06-03 13:06:41 -05:00
parent be177902fd
commit 0859854af0
2 changed files with 35 additions and 10 deletions

View File

@ -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;

View File

@ -67,14 +67,35 @@ public class FactionsPlayerListener extends PlayerListener{
return;
}
int InsertIndex = Conf.chatTagInsertIndex;
if (InsertIndex > event.getFormat().length())
return;
int InsertIndex = 0;
String eventFormat = event.getFormat();
String formatStart = event.getFormat().substring(0, InsertIndex);
String formatEnd = event.getFormat().substring(InsertIndex);
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 nonColoredMsgFormat = formatStart + me.getChatTag() + formatEnd;
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));
}