Minor code cleanup

This commit is contained in:
KHobbits 2013-03-18 23:14:20 +00:00
parent 4b5cc8cfd8
commit 66e87bdd1c
3 changed files with 36 additions and 41 deletions

View file

@ -462,7 +462,7 @@ public class Settings implements ISettings
return config.getConfigurationSection("list").getValues(false); return config.getConfigurationSection("list").getValues(false);
} }
Map<String, Object> defaultMap = new HashMap<String, Object>(); Map<String, Object> defaultMap = new HashMap<String, Object>();
defaultMap.put("User", "*"); defaultMap.put("Players", "*");
return defaultMap; return defaultMap;
} }

View file

@ -109,23 +109,23 @@ public class Commandlist extends EssentialsCommand
Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet(); Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
final List<User> users = new ArrayList<User>(); final List<User> users = new ArrayList<User>();
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(" "); String[] groupValues = ess.getSettings().getListGroupConfig().get(configGroup).toString().trim().split(" ");
for (String g : groups) for (String groupValue : groupValues)
{ {
if (g == null || g.equals("")) if (groupValue == null || groupValue.equals(""))
{ {
continue; continue;
} }
List<User> u = playerList.get(g.trim()); List<User> u = playerList.get(groupValue.trim());
if (u == null || u.isEmpty()) if (u == null || u.isEmpty())
{ {
continue; continue;
} }
playerList.remove(g); playerList.remove(groupValue);
users.addAll(u); users.addAll(u);
} }
} }
@ -133,23 +133,22 @@ public class Commandlist extends EssentialsCommand
return users; 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<String, List<User>> playerList) private void sendGroupedList(CommandSender sender, String commandLabel, Map<String, List<User>> playerList)
{ {
final StringBuilder outputString = new StringBuilder();
Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet(); Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
List<String> asterisk = new ArrayList<String>(); List<String> asterisk = new ArrayList<String>();
// Loop through the custom defined groups and display them // 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(); String groupValue = ess.getSettings().getListGroupConfig().get(configGroup).toString().trim();
group = group.toLowerCase(); configGroup = configGroup.toLowerCase();
// If the group value is an asterisk, then skip it, and handle it later // If the group value is an asterisk, then skip it, and handle it later
if (groupValue.equals("*")) if (groupValue.equals("*"))
{ {
asterisk.add(group); asterisk.add(configGroup);
continue; continue;
} }
@ -160,37 +159,37 @@ public class Commandlist extends EssentialsCommand
continue; continue;
} }
List<User> users = new ArrayList<User>(); List<User> outputUserList = new ArrayList<User>();
List<User> u = playerList.get(group); List<User> matchedList = playerList.get(configGroup);
// If the group value is an int, then we might need to truncate it // If the group value is an int, then we might need to truncate it
if (Util.isInt(groupValue)) if (Util.isInt(groupValue))
{ {
if (u != null && !u.isEmpty()) if (matchedList != null && !matchedList.isEmpty())
{ {
playerList.remove(group); playerList.remove(configGroup);
users.addAll(u); outputUserList.addAll(matchedList);
int limit = Integer.parseInt(groupValue); 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 { else {
sender.sendMessage(outputFormat(group, listUsers(users))); sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList)));
} }
continue; 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 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; continue;
} }
sender.sendMessage(outputFormat(group, listUsers(users))); sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList)));
} }
String[] onlineGroups = playerList.keySet().toArray(new String[0]); String[] onlineGroups = playerList.keySet().toArray(new String[0]);
@ -200,9 +199,9 @@ public class Commandlist extends EssentialsCommand
if (!asterisk.isEmpty()) if (!asterisk.isEmpty())
{ {
List<User> asteriskUsers = new ArrayList<User>(); List<User> asteriskUsers = new ArrayList<User>();
for (String group : onlineGroups) for (String onlineGroup : onlineGroups)
{ {
asteriskUsers.addAll(playerList.get(group)); asteriskUsers.addAll(playerList.get(onlineGroup));
} }
for (String key : asterisk) 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 // If we have any groups remaining after the custom groups loop through and display them
for (String group : onlineGroups) for (String onlineGroup : onlineGroups)
{ {
List<User> users = playerList.get(group); List<User> users = playerList.get(onlineGroup);
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions")) if (ess.getPermissionsHandler().getName().equals("ConfigPermissions"))
{ {
group = _("connectedPlayers"); onlineGroup = _("connectedPlayers");
} }
if (users == null || users.isEmpty()) if (users == null || users.isEmpty())
{ {
continue; 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(); final StringBuilder groupString = new StringBuilder();
Collections.sort(users); Collections.sort(users);
boolean first = true; boolean needComma = false;
for (User user : users) for (User user : users)
{ {
if (!first) if (needComma)
{ {
groupString.append(", "); groupString.append(", ");
} }
else needComma = true;
{
first = false;
}
if (user.isAfk()) if (user.isAfk())
{ {
groupString.append(_("listAfkTag")); groupString.append(_("listAfkTag"));

View file

@ -289,8 +289,8 @@ per-warp-permission: false
# Detailed instructions and examples can be found on the wiki: http://wiki.ess3.net/wiki/List # Detailed instructions and examples can be found on the wiki: http://wiki.ess3.net/wiki/List
list: list:
# To merge groups, list the groups you wish to merge # To merge groups, list the groups you wish to merge
#Staff: owner, admin, moderators #Staff: owner admin moderator
Admins: owner, admin Admins: owner admin
# To limit groups, set a max user limit # To limit groups, set a max user limit
#builder: 20 #builder: 20
# To hide groups, set the group as hidden # To hide groups, set the group as hidden