mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-03 14:01:37 +01:00
Cleanup - Split /list into methods
This commit is contained in:
parent
0c82c61574
commit
5b55fd97e6
@ -19,18 +19,27 @@ public class Commandlist extends EssentialsCommand
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
boolean showhidden = false;
|
||||
boolean showHidden = true;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
if (ess.getUser(sender).isAuthorized("essentials.list.hidden"))
|
||||
{
|
||||
showhidden = true;
|
||||
}
|
||||
showHidden = ess.getUser(sender).isAuthorized("essentials.list.hidden");
|
||||
}
|
||||
|
||||
sender.sendMessage(listSummary(server, showHidden));
|
||||
Map<String, List<User>> playerList = getPlayerLists(server, showHidden);
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
sender.sendMessage(listGroupUsers(server, playerList, args[0].toLowerCase()));
|
||||
}
|
||||
else
|
||||
{
|
||||
showhidden = true;
|
||||
sendGroupedList(server, sender, commandLabel, playerList);
|
||||
}
|
||||
}
|
||||
|
||||
private String listSummary(Server server, boolean showHidden)
|
||||
{
|
||||
int playerHidden = 0;
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
@ -40,8 +49,8 @@ public class Commandlist extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
|
||||
String online;
|
||||
if (showhidden && playerHidden > 0)
|
||||
String online;
|
||||
if (showHidden && playerHidden > 0)
|
||||
{
|
||||
online = _("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers());
|
||||
}
|
||||
@ -49,218 +58,232 @@ public class Commandlist extends EssentialsCommand
|
||||
{
|
||||
online = _("listAmount", server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers());
|
||||
}
|
||||
sender.sendMessage(online);
|
||||
return online;
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<User>> sort = new HashMap<String, List<User>>();
|
||||
for (Player OnlinePlayer : server.getOnlinePlayers())
|
||||
private Map<String, List<User>> getPlayerLists(Server server, boolean showHidden)
|
||||
{
|
||||
Map<String, List<User>> playerList = new HashMap<String, List<User>>();
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User player = ess.getUser(OnlinePlayer);
|
||||
if (player.isHidden() && !showhidden)
|
||||
final User onlineUser = ess.getUser(onlinePlayer);
|
||||
if (onlineUser.isHidden() && !showHidden)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final String group = player.getGroup().toLowerCase();
|
||||
List<User> list = sort.get(group);
|
||||
final String group = onlineUser.getGroup().toLowerCase();
|
||||
List<User> list = playerList.get(group);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ArrayList<User>();
|
||||
sort.put(group, list);
|
||||
playerList.put(group, list);
|
||||
}
|
||||
list.add(player);
|
||||
list.add(onlineUser);
|
||||
}
|
||||
final StringBuilder groupString = new StringBuilder();
|
||||
Set<String> keys = ess.getSettings().getListGroupConfig().keySet();
|
||||
|
||||
if (args.length > 0)
|
||||
return playerList;
|
||||
}
|
||||
|
||||
private String listGroupUsers(Server server, Map<String, List<User>> playerList, String groupName) throws Exception
|
||||
{
|
||||
final StringBuilder outputString = new StringBuilder();
|
||||
Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
|
||||
final List<User> users = new ArrayList<User>();
|
||||
|
||||
for (String key : configGroups)
|
||||
{
|
||||
String groupValue = ess.getSettings().getListGroupConfig().get(key).toString().trim();
|
||||
if (key.equalsIgnoreCase(groupName) && groupValue.contains(","))
|
||||
{
|
||||
String[] groups = groupValue.split(",");
|
||||
for (String g : groups)
|
||||
{
|
||||
if (g == null || g.equals(""))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<User> u = playerList.get(g.trim());
|
||||
if (u == null || u.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
private void sendGroupedList(Server server, 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> usedGroupsAsterisk = new ArrayList<String>();
|
||||
Map<String, Boolean> asterisk = new HashMap<String, Boolean>();
|
||||
boolean hasAsterisk = false;
|
||||
|
||||
for (String group : configGroups)
|
||||
{
|
||||
boolean userLimit = false;
|
||||
String groupValue = ess.getSettings().getListGroupConfig().get(group).toString().trim();
|
||||
|
||||
// If the group value is an asterisk, then skip it, and handle it later
|
||||
if (groupValue.equals("*"))
|
||||
{
|
||||
asterisk.put(group, true);
|
||||
hasAsterisk = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
group = group.toLowerCase();
|
||||
usedGroups.add(group);
|
||||
|
||||
// If the group value is hidden, we don't need to display it
|
||||
if (groupValue.equals("hidden"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (Util.isInt(groupValue))
|
||||
{
|
||||
userLimit = true;
|
||||
}
|
||||
|
||||
final List<User> users = new ArrayList<User>();
|
||||
String group = args[0].toLowerCase();
|
||||
for (String key : keys)
|
||||
List<User> u = playerList.get(group);
|
||||
if (u != null && !u.isEmpty())
|
||||
{
|
||||
String groupValue = ess.getSettings().getListGroupConfig().get(key).toString().trim();
|
||||
if(key.equalsIgnoreCase(group) && groupValue.contains(","))
|
||||
|
||||
if (userLimit)
|
||||
{
|
||||
users.addAll(u);
|
||||
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 (groupValue.contains(",") || playerList.containsKey(groupValue.toLowerCase()))
|
||||
{
|
||||
if (playerList.containsKey(groupValue))
|
||||
{
|
||||
u = playerList.get(groupValue);
|
||||
if (u == null || u.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
users.addAll(u);
|
||||
usedGroupsAsterisk.add(groupValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] groups = groupValue.split(",");
|
||||
for (String g : groups)
|
||||
{
|
||||
g = g.trim().toLowerCase();
|
||||
if (g == null || g.equals(""))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<User> u = sort.get(g.trim());
|
||||
u = playerList.get(g);
|
||||
if (u == null || u.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
users.addAll(u);
|
||||
usedGroupsAsterisk.add(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<User> groupUsers = sort.get(group);
|
||||
if (groupUsers != null && !groupUsers.isEmpty())
|
||||
{
|
||||
users.addAll(groupUsers);
|
||||
}
|
||||
if (users == null || users.isEmpty())
|
||||
{
|
||||
throw new Exception(_("groupDoesNotExist"));
|
||||
continue;
|
||||
}
|
||||
groupString.append(_("listGroupTag", Util.replaceFormat(group)));
|
||||
groupString.append(listUsers(users));
|
||||
groupString.setCharAt(0, Character.toTitleCase(groupString.charAt(0)));
|
||||
sender.sendMessage(groupString.toString());
|
||||
groupString.setLength(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<String> usedGroups = new ArrayList<String>();
|
||||
List<String> usedGroupsAsterisk = new ArrayList<String>();
|
||||
Map<String, Boolean> asterisk = new HashMap<String, Boolean>();
|
||||
boolean hasAsterisk = false;
|
||||
for (String group : keys)
|
||||
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions"))
|
||||
{
|
||||
boolean userLimit = false;
|
||||
String groupValue = ess.getSettings().getListGroupConfig().get(group).toString().trim();
|
||||
if (groupValue.equals("*"))
|
||||
{
|
||||
asterisk.put(group, true);
|
||||
hasAsterisk = true;
|
||||
continue;
|
||||
}
|
||||
usedGroups.add(group.toLowerCase());
|
||||
if (groupValue.equals("hidden"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (Util.isInt(groupValue))
|
||||
{
|
||||
userLimit = true;
|
||||
}
|
||||
group = group.toLowerCase();
|
||||
final List<User> users = new ArrayList<User>();
|
||||
List<User> u = sort.get(group);
|
||||
if (u != null && !u.isEmpty())
|
||||
{
|
||||
|
||||
if (userLimit)
|
||||
{
|
||||
users.addAll(u);
|
||||
int limit = Integer.parseInt(groupValue);
|
||||
if (u.size() > limit)
|
||||
{
|
||||
groupString.append(_("listGroupTag", Util.replaceFormat(group)));
|
||||
groupString.append(_("groupNumber", u.size(), commandLabel, group));
|
||||
groupString.setCharAt(0, Character.toTitleCase(groupString.charAt(0)));
|
||||
sender.sendMessage(groupString.toString());
|
||||
groupString.setLength(0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (groupValue.contains(",") || sort.containsKey(groupValue.toLowerCase()))
|
||||
{
|
||||
if (sort.containsKey(groupValue))
|
||||
{
|
||||
u = sort.get(groupValue);
|
||||
if (u == null || u.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
users.addAll(u);
|
||||
usedGroupsAsterisk.add(groupValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] groups = groupValue.split(",");
|
||||
for (String g : groups)
|
||||
{
|
||||
g = g.trim().toLowerCase();
|
||||
if (g == null || g.equals(""))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
u = sort.get(g);
|
||||
if (u == null || u.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
users.addAll(u);
|
||||
usedGroupsAsterisk.add(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (users == null || users.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions"))
|
||||
{
|
||||
group = _("connectedPlayers");
|
||||
}
|
||||
groupString.append(_("listGroupTag", Util.replaceFormat(group)));
|
||||
groupString.append(listUsers(users));
|
||||
groupString.setCharAt(0, Character.toTitleCase(groupString.charAt(0)));
|
||||
sender.sendMessage(groupString.toString());
|
||||
groupString.setLength(0);
|
||||
group = _("connectedPlayers");
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
final String[] groups = playerList.keySet().toArray(new String[0]);
|
||||
Arrays.sort(groups, String.CASE_INSENSITIVE_ORDER);
|
||||
List<User> asteriskUsers = new ArrayList<User>();
|
||||
String asteriskGroup = "";
|
||||
if (hasAsterisk)
|
||||
{
|
||||
for (String key : asterisk.keySet())
|
||||
{
|
||||
if (asterisk.get(key) == true)
|
||||
{
|
||||
asteriskGroup = key.toLowerCase();
|
||||
for (String group : groups)
|
||||
{
|
||||
group = group.toLowerCase().trim();
|
||||
if (usedGroups.contains(group) || usedGroupsAsterisk.contains(group))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
asteriskUsers.addAll(playerList.get(group));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String group : groups)
|
||||
{
|
||||
group = group.toLowerCase().trim();
|
||||
if (usedGroups.contains(group))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<User> users = playerList.get(group);
|
||||
|
||||
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions"))
|
||||
{
|
||||
group = _("connectedPlayers");
|
||||
}
|
||||
final String[] groups = sort.keySet().toArray(new String[0]);
|
||||
Arrays.sort(groups, String.CASE_INSENSITIVE_ORDER);
|
||||
List<User> asteriskUsers = new ArrayList<User>();
|
||||
String asteriskGroup = "";
|
||||
if (hasAsterisk)
|
||||
{
|
||||
for(String key : asterisk.keySet())
|
||||
{
|
||||
if (asterisk.get(key) == true)
|
||||
{
|
||||
asteriskGroup = key.toLowerCase();
|
||||
for (String group : groups)
|
||||
{
|
||||
group = group.toLowerCase().trim();
|
||||
if (usedGroups.contains(group) || usedGroupsAsterisk.contains(group))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
asteriskUsers.addAll(sort.get(group));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String group : groups)
|
||||
{
|
||||
group = group.toLowerCase().trim();
|
||||
if (usedGroups.contains(group))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<User> users = sort.get(group);
|
||||
|
||||
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions"))
|
||||
{
|
||||
group = _("connectedPlayers");
|
||||
}
|
||||
if (hasAsterisk)
|
||||
{
|
||||
if (asteriskUsers == null || asteriskUsers.isEmpty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
users = asteriskUsers;
|
||||
group = asteriskGroup;
|
||||
}
|
||||
groupString.append(_("listGroupTag", Util.replaceFormat(group)));
|
||||
|
||||
groupString.append(listUsers(users));
|
||||
groupString.setCharAt(0, Character.toTitleCase(groupString.charAt(0)));
|
||||
sender.sendMessage(groupString.toString());
|
||||
groupString.setLength(0);
|
||||
if (hasAsterisk)
|
||||
if (asteriskUsers == null || asteriskUsers.isEmpty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
users = asteriskUsers;
|
||||
group = asteriskGroup;
|
||||
}
|
||||
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);
|
||||
if (hasAsterisk)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -285,21 +285,16 @@ backup:
|
||||
per-warp-permission: false
|
||||
|
||||
# Sort output of /list command by groups.
|
||||
# You are not allowed to have duplicate keys.
|
||||
# You can hide and merge the groups displayed in /list by defining the desired behaviour here.
|
||||
# Detailed instructions and examples can be found on the wiki: http://wiki.ess3.net/wiki/List
|
||||
list:
|
||||
# this will merge the two groups owner and co-owner together in the list group "admin",
|
||||
# make sure you set the groups you merge to "hidden" to prevent duplicate names.
|
||||
# this accepts a comma separated list, so simply separate the groups you want merged together with a comma.
|
||||
# like this:
|
||||
Admin: owner, admin
|
||||
# Setting the value to hidden will hide these from /list, they will still show on /list <groupname>
|
||||
# If a group is already defined as a merged group, then you don't need to set it to hidden, so in this case "admin" is automatically hidden.
|
||||
# And they will also show in merged groups, like the ones above.
|
||||
Owner: hidden
|
||||
# Setting the value to a number limits the group.
|
||||
# When there are more users online in the group than your limit it will truncate it to a simple, configurable message,
|
||||
# The message will state how many users are online in that group and how to see a list of users in that group.
|
||||
default: 20
|
||||
# To merge groups, list the groups you wish to merge
|
||||
#Staff: owner, admin, moderators
|
||||
# To limit groups, set a max user limit
|
||||
#builder: 20
|
||||
# To hide groups, set the group as hidden
|
||||
#default: hidden
|
||||
Players: *
|
||||
|
||||
# More output to the console.
|
||||
debug: false
|
||||
|
@ -344,7 +344,7 @@ commands:
|
||||
aliases: [mob,emob,spawnentity,espawnentity,espawnmob]
|
||||
speed:
|
||||
description: Change your speed limits.
|
||||
usage: /<command> <speed> [player]
|
||||
usage: /<command> [type] <speed> [player]
|
||||
aliases: [flyspeed,eflyspeed,fspeed,efspeed,espeed,walkspeed,ewalkspeed,wspeed,ewspeed]
|
||||
sudo:
|
||||
description: Make another user perform a command.
|
||||
|
Loading…
Reference in New Issue
Block a user