From 8cba8da516ffbc880ed2f4d80de2f43f82e0b44d Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 18 Aug 2013 22:08:57 +0100 Subject: Fix a few issues with /list and group formatting. --- .../earth2me/essentials/commands/Commandlist.java | 23 ++++++++++++---------- .../com/earth2me/essentials/utils/FormatUtil.java | 12 ++++++++++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 9fea6846c..18fa0a673 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -27,7 +27,7 @@ public class Commandlist extends EssentialsCommand } sender.sendMessage(listSummary(server, showHidden)); - Map> playerList = getPlayerLists(server, showHidden); + final Map> playerList = getPlayerLists(server, showHidden); if (args.length > 0) { @@ -66,7 +66,7 @@ public class Commandlist extends EssentialsCommand // Build the basic player list, divided by groups. private Map> getPlayerLists(final Server server, final boolean showHidden) { - Map> playerList = new HashMap>(); + final Map> playerList = new HashMap>(); for (Player onlinePlayer : server.getOnlinePlayers()) { final User onlineUser = ess.getUser(onlinePlayer); @@ -74,7 +74,7 @@ public class Commandlist extends EssentialsCommand { continue; } - final String group = FormatUtil.stripFormat(onlineUser.getGroup().toLowerCase()); + final String group = FormatUtil.stripFormat(FormatUtil.stripEssentialsFormat(onlineUser.getGroup().toLowerCase())); List list = playerList.get(group); if (list == null) { @@ -91,7 +91,7 @@ public class Commandlist extends EssentialsCommand { final List users = getMergedList(playerList, groupName); - List groupUsers = playerList.get(groupName); + final List groupUsers = playerList.get(groupName); if (groupUsers != null && !groupUsers.isEmpty()) { users.addAll(groupUsers); @@ -101,13 +101,16 @@ public class Commandlist extends EssentialsCommand throw new Exception(_("groupDoesNotExist")); } - return outputFormat(groupName, listUsers(users)); + final StringBuilder displayGroupName = new StringBuilder(); + displayGroupName.append(Character.toTitleCase(groupName.charAt(0))); + displayGroupName.append(groupName.substring(1)); + return outputFormat(displayGroupName.toString(), listUsers(users)); } // Handle the merging of groups private List getMergedList(final Map> playerList, final String groupName) { - Set configGroups = ess.getSettings().getListGroupConfig().keySet(); + final Set configGroups = ess.getSettings().getListGroupConfig().keySet(); final List users = new ArrayList(); for (String configGroup : configGroups) @@ -117,6 +120,7 @@ public class Commandlist extends EssentialsCommand String[] groupValues = ess.getSettings().getListGroupConfig().get(configGroup).toString().trim().split(" "); for (String groupValue : groupValues) { + groupValue = groupValue.toLowerCase(Locale.ENGLISH); if (groupValue == null || groupValue.equals("")) { continue; @@ -137,8 +141,8 @@ public class Commandlist extends EssentialsCommand // Output the standard /list output, when no group is specified private void sendGroupedList(CommandSender sender, String commandLabel, Map> playerList) { - Set configGroups = ess.getSettings().getListGroupConfig().keySet(); - List asterisk = new ArrayList(); + final Set configGroups = ess.getSettings().getListGroupConfig().keySet(); + final List asterisk = new ArrayList(); // Loop through the custom defined groups and display them for (String oConfigGroup : configGroups) @@ -161,7 +165,7 @@ public class Commandlist extends EssentialsCommand } List outputUserList = new ArrayList(); - List matchedList = playerList.get(configGroup); + final List matchedList = playerList.get(configGroup); // If the group value is an int, then we might need to truncate it if (NumberUtil.isInt(groupValue)) @@ -265,7 +269,6 @@ public class Commandlist extends EssentialsCommand final StringBuilder outputString = new StringBuilder(); outputString.append(_("listGroupTag", FormatUtil.replaceFormat(group))); outputString.append(message); - outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); return outputString.toString(); } } diff --git a/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java b/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java index b598b8c86..9d3ef7cb0 100644 --- a/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java @@ -25,7 +25,17 @@ public class FormatUtil { return null; } - return VANILLA_PATTERN.matcher(input).replaceAll(""); + return stripColor(input, VANILLA_PATTERN); + } + + //This method is used to simply strip the & convention colour codes + public static String stripEssentialsFormat(final String input) + { + if (input == null) + { + return null; + } + return stripColor(input, REPLACE_PATTERN); } //This is the general permission sensitive message format function, checks for urls. -- cgit v1.2.3