diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Settings.java | 2 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandlist.java | 203 | ||||
-rw-r--r-- | Essentials/src/config.yml | 4 |
3 files changed, 89 insertions, 120 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 059da4e65..d49d5bac7 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -462,7 +462,7 @@ public class Settings implements ISettings return config.getConfigurationSection("list").getValues(false); } Map<String, Object> defaultMap = new HashMap<String, Object>(); - defaultMap.put("User", "*"); + defaultMap.put("Players", "*"); return defaultMap; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 84c33a458..196b1baca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -30,15 +30,16 @@ public class Commandlist extends EssentialsCommand if (args.length > 0) { - sender.sendMessage(listGroupUsers(server, playerList, args[0].toLowerCase())); + sender.sendMessage(listGroupUsers(playerList, args[0].toLowerCase())); } else { - sendGroupedList(server, sender, commandLabel, playerList); + sendGroupedList(sender, commandLabel, playerList); } } - private String listSummary(Server server, boolean showHidden) + // Produce a user summary: There are 5 out of maximum 10 players online. + private String listSummary(final Server server, final boolean showHidden) { int playerHidden = 0; for (Player onlinePlayer : server.getOnlinePlayers()) @@ -61,7 +62,8 @@ public class Commandlist extends EssentialsCommand return online; } - private Map<String, List<User>> getPlayerLists(Server server, boolean showHidden) + // Build the basic player list, divided by groups. + private Map<String, List<User>> getPlayerLists(final Server server, final boolean showHidden) { Map<String, List<User>> playerList = new HashMap<String, List<User>>(); for (Player onlinePlayer : server.getOnlinePlayers()) @@ -83,159 +85,123 @@ public class Commandlist extends EssentialsCommand return playerList; } - private String listGroupUsers(Server server, Map<String, List<User>> playerList, String groupName) throws Exception + // Output a playerlist of just a single group, /list <groupname> + private String listGroupUsers(final Map<String, List<User>> playerList, final String groupName) throws Exception + { + final List<User> users = getMergedList(playerList, groupName); + + List<User> groupUsers = playerList.get(groupName); + if (groupUsers != null && !groupUsers.isEmpty()) + { + users.addAll(groupUsers); + } + if (users == null || users.isEmpty()) + { + throw new Exception(_("groupDoesNotExist")); + } + + return outputFormat(groupName, listUsers(users)); + } + + // Handle the merging of groups + private List<User> getMergedList(final Map<String, List<User>> playerList, final String groupName) { - final StringBuilder outputString = new StringBuilder(); Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet(); final List<User> users = new ArrayList<User>(); - for (String key : configGroups) + for (String configGroup : configGroups) { - String groupValue = ess.getSettings().getListGroupConfig().get(key).toString().trim(); - if (key.equalsIgnoreCase(groupName) && groupValue.contains(",")) + if (configGroup.equalsIgnoreCase(groupName)) { - String[] groups = groupValue.split(","); - for (String g : groups) + String[] groupValues = ess.getSettings().getListGroupConfig().get(configGroup).toString().trim().split(" "); + for (String groupValue : groupValues) { - if (g == null || g.equals("")) + if (groupValue == null || groupValue.equals("")) { continue; } - List<User> u = playerList.get(g.trim()); + List<User> u = playerList.get(groupValue.trim()); if (u == null || u.isEmpty()) { continue; } + playerList.remove(groupValue); users.addAll(u); } } } - List<User> groupUsers = playerList.get(groupName); - if (groupUsers != null && !groupUsers.isEmpty()) - { - users.addAll(groupUsers); - } - if (users == null || users.isEmpty()) - { - throw new Exception(_("groupDoesNotExist")); - } - outputString.append(_("listGroupTag", Util.replaceFormat(groupName))); - outputString.append(listUsers(users)); - outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); - return outputString.toString(); + return users; } - private void sendGroupedList(Server server, CommandSender sender, String commandLabel, Map<String, List<User>> playerList) + // Output the standard /list output, when no group is specified + private void sendGroupedList(CommandSender sender, String commandLabel, Map<String, List<User>> playerList) { - final StringBuilder outputString = new StringBuilder(); Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet(); - List<String> usedGroups = new ArrayList<String>(); List<String> asterisk = new ArrayList<String>(); - for (String group : configGroups) + // Loop through the custom defined groups and display them + for (String configGroup : configGroups) { - String groupValue = ess.getSettings().getListGroupConfig().get(group).toString().trim(); - group = group.toLowerCase(); + String groupValue = ess.getSettings().getListGroupConfig().get(configGroup).toString().trim(); + configGroup = configGroup.toLowerCase(); // If the group value is an asterisk, then skip it, and handle it later if (groupValue.equals("*")) { - asterisk.add(group); + asterisk.add(configGroup); continue; } - usedGroups.add(group); - // If the group value is hidden, we don't need to display it - if (groupValue.equals("hidden")) + if (groupValue.equalsIgnoreCase("hidden")) { + playerList.remove(groupValue); continue; } - final List<User> users = new ArrayList<User>(); - List<User> u = playerList.get(group); + List<User> outputUserList = new ArrayList<User>(); + List<User> matchedList = playerList.get(configGroup); // If the group value is an int, then we might need to truncate it if (Util.isInt(groupValue)) { - if (u != null && !u.isEmpty()) + if (matchedList != null && !matchedList.isEmpty()) { - users.addAll(u); + playerList.remove(configGroup); + outputUserList.addAll(matchedList); int limit = Integer.parseInt(groupValue); - if (u.size() > limit) - { - outputString.append(_("listGroupTag", Util.replaceFormat(group))); - outputString.append(_("groupNumber", u.size(), commandLabel, group)); - outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); - sender.sendMessage(outputString.toString()); - outputString.setLength(0); - continue; + if (matchedList.size() > limit) + { + sender.sendMessage(outputFormat(configGroup, _("groupNumber", matchedList.size(), commandLabel, configGroup))); } + else { + sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList))); + } + continue; } - } - // If the group value is a list, we need to merge groups together. - if (groupValue.contains(",") || playerList.containsKey(groupValue.toLowerCase())) - { - if (playerList.containsKey(groupValue)) - { - u = playerList.get(groupValue); - if (u == null || u.isEmpty()) - { - continue; - } - users.addAll(u); - } - else - { - String[] groups = groupValue.split(","); - for (String g : groups) - { - g = g.trim().toLowerCase(); - if (g == null || g.equals("")) - { - continue; - } - u = playerList.get(g); - if (u == null || u.isEmpty()) - { - continue; - } - users.addAll(u); - } - } - } + outputUserList = getMergedList(playerList, configGroup); // If we have no users, than we don't need to continue parsing this group - if (users == null || users.isEmpty()) + if (outputUserList == null || outputUserList.isEmpty()) { continue; } - outputString.append(_("listGroupTag", Util.replaceFormat(group))); - outputString.append(listUsers(users)); - outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); - sender.sendMessage(outputString.toString()); - outputString.setLength(0); + sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList))); } String[] onlineGroups = playerList.keySet().toArray(new String[0]); Arrays.sort(onlineGroups, String.CASE_INSENSITIVE_ORDER); - + // If we have an asterisk group, then merge all remaining groups if (!asterisk.isEmpty()) { List<User> asteriskUsers = new ArrayList<User>(); - - for (String group : onlineGroups) - { - group = group.toLowerCase().trim(); - if (usedGroups.contains(group)) - { - continue; - } - asteriskUsers.addAll(playerList.get(group)); + for (String onlineGroup : onlineGroups) + { + asteriskUsers.addAll(playerList.get(onlineGroup)); } for (String key : asterisk) { @@ -244,44 +210,37 @@ public class Commandlist extends EssentialsCommand onlineGroups = asterisk.toArray(new String[0]); } - for (String group : onlineGroups) + // If we have any groups remaining after the custom groups loop through and display them + for (String onlineGroup : onlineGroups) { - group = group.toLowerCase().trim(); - if (usedGroups.contains(group)) - { - continue; - } - - List<User> users = playerList.get(group); + List<User> users = playerList.get(onlineGroup); if (ess.getPermissionsHandler().getName().equals("ConfigPermissions")) { - group = _("connectedPlayers"); + onlineGroup = _("connectedPlayers"); + } + if (users == null || users.isEmpty()) + { + continue; } - - outputString.append(_("listGroupTag", Util.replaceFormat(group))); - outputString.append(listUsers(users)); - outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); - sender.sendMessage(outputString.toString()); - outputString.setLength(0); + + sender.sendMessage(outputFormat(onlineGroup, listUsers(users))); } } + // Cosmetic list formatting private String listUsers(List<User> users) { final StringBuilder groupString = new StringBuilder(); Collections.sort(users); - boolean first = true; + boolean needComma = false; for (User user : users) { - if (!first) + if (needComma) { groupString.append(", "); } - else - { - first = false; - } + needComma = true; if (user.isAfk()) { groupString.append(_("listAfkTag")); @@ -296,4 +255,14 @@ public class Commandlist extends EssentialsCommand } return groupString.toString(); } + + // Build the output string + private String outputFormat(String group, String message) + { + final StringBuilder outputString = new StringBuilder(); + outputString.append(_("listGroupTag", Util.replaceFormat(group))); + outputString.append(message); + outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); + return outputString.toString(); + } } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 15db4819a..7d31aaee3 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -289,8 +289,8 @@ per-warp-permission: false # Detailed instructions and examples can be found on the wiki: http://wiki.ess3.net/wiki/List list: # To merge groups, list the groups you wish to merge - #Staff: owner, admin, moderators - Admins: owner, admin + #Staff: owner admin moderator + Admins: owner admin # To limit groups, set a max user limit #builder: 20 # To hide groups, set the group as hidden |