From 66e87bdd1c77f6cbcf1da88cb4e116a20b893581 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 18 Mar 2013 23:14:20 +0000 Subject: Minor code cleanup --- .../src/com/earth2me/essentials/Settings.java | 2 +- .../earth2me/essentials/commands/Commandlist.java | 71 ++++++++++------------ Essentials/src/config.yml | 4 +- 3 files changed, 36 insertions(+), 41 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 defaultMap = new HashMap(); - 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 e5c3598e5..196b1baca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -109,23 +109,23 @@ public class Commandlist extends EssentialsCommand Set configGroups = ess.getSettings().getListGroupConfig().keySet(); final List users = new ArrayList(); - for (String key : configGroups) + for (String configGroup : configGroups) { - if (key.equalsIgnoreCase(groupName)) + if (configGroup.equalsIgnoreCase(groupName)) { - String[] groups = ess.getSettings().getListGroupConfig().get(key).toString().trim().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 u = playerList.get(g.trim()); + List u = playerList.get(groupValue.trim()); if (u == null || u.isEmpty()) { continue; } - playerList.remove(g); + playerList.remove(groupValue); users.addAll(u); } } @@ -133,23 +133,22 @@ public class Commandlist extends EssentialsCommand return users; } - // Output the standard /list output, when no group is specififed + // Output the standard /list output, when no group is specified private void sendGroupedList(CommandSender sender, String commandLabel, Map> playerList) { - final StringBuilder outputString = new StringBuilder(); Set configGroups = ess.getSettings().getListGroupConfig().keySet(); List asterisk = new ArrayList(); // Loop through the custom defined groups and display them - for (String group : configGroups) + 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; } @@ -160,37 +159,37 @@ public class Commandlist extends EssentialsCommand continue; } - List users = new ArrayList(); - List u = playerList.get(group); + List outputUserList = new ArrayList(); + List 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()) { - playerList.remove(group); - users.addAll(u); + playerList.remove(configGroup); + outputUserList.addAll(matchedList); int limit = Integer.parseInt(groupValue); - if (u.size() > limit) + if (matchedList.size() > limit) { - sender.sendMessage(outputFormat(group, _("groupNumber", u.size(), commandLabel, group))); + sender.sendMessage(outputFormat(configGroup, _("groupNumber", matchedList.size(), commandLabel, configGroup))); } else { - sender.sendMessage(outputFormat(group, listUsers(users))); + sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList))); } continue; } } - users = getMergedList(playerList, group); + 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; } - sender.sendMessage(outputFormat(group, listUsers(users))); + sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList))); } String[] onlineGroups = playerList.keySet().toArray(new String[0]); @@ -200,9 +199,9 @@ public class Commandlist extends EssentialsCommand if (!asterisk.isEmpty()) { List asteriskUsers = new ArrayList(); - for (String group : onlineGroups) + for (String onlineGroup : onlineGroups) { - asteriskUsers.addAll(playerList.get(group)); + asteriskUsers.addAll(playerList.get(onlineGroup)); } for (String key : asterisk) { @@ -212,21 +211,20 @@ public class Commandlist extends EssentialsCommand } // If we have any groups remaining after the custom groups loop through and display them - for (String group : onlineGroups) + for (String onlineGroup : onlineGroups) { - List users = playerList.get(group); + List users = playerList.get(onlineGroup); if (ess.getPermissionsHandler().getName().equals("ConfigPermissions")) { - group = _("connectedPlayers"); - } - + onlineGroup = _("connectedPlayers"); + } if (users == null || users.isEmpty()) { continue; } - sender.sendMessage(outputFormat(group, listUsers(users))); + sender.sendMessage(outputFormat(onlineGroup, listUsers(users))); } } @@ -235,17 +233,14 @@ public class Commandlist extends EssentialsCommand { 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")); 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 -- cgit v1.2.3