2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-03-19 22:39:51 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2012-03-05 00:08:37 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2011-11-18 17:42:26 +00:00
|
|
|
import java.util.*;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class Commandlist extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandlist()
|
|
|
|
{
|
|
|
|
super("list");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-11-18 13:48:31 +00:00
|
|
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2013-03-18 07:50:36 +00:00
|
|
|
boolean showHidden = true;
|
2011-07-18 01:42:21 +00:00
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
2013-03-18 07:50:36 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-03-18 22:43:05 +00:00
|
|
|
sender.sendMessage(listGroupUsers(playerList, args[0].toLowerCase()));
|
2011-07-18 01:42:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-18 22:43:05 +00:00
|
|
|
sendGroupedList(sender, commandLabel, playerList);
|
2011-07-18 01:42:21 +00:00
|
|
|
}
|
2013-03-18 07:50:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// Produce a user summary: There are 5 out of maximum 10 players online.
|
|
|
|
private String listSummary(final Server server, final boolean showHidden)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2011-07-18 01:42:21 +00:00
|
|
|
int playerHidden = 0;
|
2011-11-18 13:48:31 +00:00
|
|
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
2011-07-18 01:42:21 +00:00
|
|
|
{
|
2011-11-18 13:48:31 +00:00
|
|
|
if (ess.getUser(onlinePlayer).isHidden())
|
2011-07-18 01:42:21 +00:00
|
|
|
{
|
|
|
|
playerHidden++;
|
|
|
|
}
|
|
|
|
}
|
2011-11-26 14:26:48 +00:00
|
|
|
|
2013-03-18 07:50:36 +00:00
|
|
|
String online;
|
|
|
|
if (showHidden && playerHidden > 0)
|
2011-07-18 01:42:21 +00:00
|
|
|
{
|
2011-11-26 14:26:48 +00:00
|
|
|
online = _("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers());
|
2012-03-21 23:54:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
online = _("listAmount", server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers());
|
2011-07-18 01:42:21 +00:00
|
|
|
}
|
2013-03-18 07:50:36 +00:00
|
|
|
return online;
|
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// Build the basic player list, divided by groups.
|
|
|
|
private Map<String, List<User>> getPlayerLists(final Server server, final boolean showHidden)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
|
|
|
Map<String, List<User>> playerList = new HashMap<String, List<User>>();
|
|
|
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
{
|
2013-03-18 07:50:36 +00:00
|
|
|
final User onlineUser = ess.getUser(onlinePlayer);
|
|
|
|
if (onlineUser.isHidden() && !showHidden)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2013-03-13 15:49:00 +00:00
|
|
|
continue;
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2013-03-26 10:43:45 +00:00
|
|
|
final String group = Util.stripFormat(onlineUser.getGroup().toLowerCase());
|
2013-03-18 07:50:36 +00:00
|
|
|
List<User> list = playerList.get(group);
|
2013-03-13 15:49:00 +00:00
|
|
|
if (list == null)
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
{
|
2013-03-13 15:49:00 +00:00
|
|
|
list = new ArrayList<User>();
|
2013-03-18 07:50:36 +00:00
|
|
|
playerList.put(group, list);
|
2013-03-13 15:49:00 +00:00
|
|
|
}
|
2013-03-18 07:50:36 +00:00
|
|
|
list.add(onlineUser);
|
2013-03-13 15:49:00 +00:00
|
|
|
}
|
2013-03-18 07:50:36 +00:00
|
|
|
return playerList;
|
|
|
|
}
|
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// 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)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
|
|
|
Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
|
|
|
|
final List<User> users = new ArrayList<User>();
|
|
|
|
|
2013-03-18 23:14:20 +00:00
|
|
|
for (String configGroup : configGroups)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
if (configGroup.equalsIgnoreCase(groupName))
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
String[] groupValues = ess.getSettings().getListGroupConfig().get(configGroup).toString().trim().split(" ");
|
|
|
|
for (String groupValue : groupValues)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
if (groupValue == null || groupValue.equals(""))
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-18 23:14:20 +00:00
|
|
|
List<User> u = playerList.get(groupValue.trim());
|
2013-03-18 07:50:36 +00:00
|
|
|
if (u == null || u.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-18 23:14:20 +00:00
|
|
|
playerList.remove(groupValue);
|
2013-03-18 07:50:36 +00:00
|
|
|
users.addAll(u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 22:43:05 +00:00
|
|
|
return users;
|
2013-03-18 07:50:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 23:14:20 +00:00
|
|
|
// Output the standard /list output, when no group is specified
|
2013-03-18 22:43:05 +00:00
|
|
|
private void sendGroupedList(CommandSender sender, String commandLabel, Map<String, List<User>> playerList)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
|
|
|
Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
|
2013-03-18 08:53:12 +00:00
|
|
|
List<String> asterisk = new ArrayList<String>();
|
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// Loop through the custom defined groups and display them
|
2013-03-29 02:59:55 +00:00
|
|
|
for (String oConfigGroup : configGroups)
|
2013-03-13 15:49:00 +00:00
|
|
|
{
|
2013-03-29 02:59:55 +00:00
|
|
|
String groupValue = ess.getSettings().getListGroupConfig().get(oConfigGroup).toString().trim();
|
|
|
|
String configGroup = oConfigGroup.toLowerCase();
|
2013-03-18 08:53:12 +00:00
|
|
|
|
2013-03-18 07:50:36 +00:00
|
|
|
// If the group value is an asterisk, then skip it, and handle it later
|
|
|
|
if (groupValue.equals("*"))
|
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
asterisk.add(configGroup);
|
2013-03-18 07:50:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-18 08:53:12 +00:00
|
|
|
|
2013-03-18 07:50:36 +00:00
|
|
|
// If the group value is hidden, we don't need to display it
|
2013-03-18 22:43:05 +00:00
|
|
|
if (groupValue.equalsIgnoreCase("hidden"))
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2013-03-18 22:43:05 +00:00
|
|
|
playerList.remove(groupValue);
|
2013-03-18 07:50:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-18 08:53:12 +00:00
|
|
|
|
2013-03-18 23:14:20 +00:00
|
|
|
List<User> outputUserList = new ArrayList<User>();
|
|
|
|
List<User> matchedList = playerList.get(configGroup);
|
2013-03-18 07:50:36 +00:00
|
|
|
|
2013-03-18 08:53:12 +00:00
|
|
|
// If the group value is an int, then we might need to truncate it
|
|
|
|
if (Util.isInt(groupValue))
|
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
if (matchedList != null && !matchedList.isEmpty())
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
playerList.remove(configGroup);
|
|
|
|
outputUserList.addAll(matchedList);
|
2013-03-18 07:50:36 +00:00
|
|
|
int limit = Integer.parseInt(groupValue);
|
2013-03-18 23:14:20 +00:00
|
|
|
if (matchedList.size() > limit)
|
2013-03-18 22:43:05 +00:00
|
|
|
{
|
2013-03-29 02:59:55 +00:00
|
|
|
sender.sendMessage(outputFormat(oConfigGroup, _("groupNumber", matchedList.size(), commandLabel, Util.stripFormat(configGroup))));
|
2013-03-18 07:50:36 +00:00
|
|
|
}
|
2013-03-18 22:43:05 +00:00
|
|
|
else {
|
2013-03-29 02:59:55 +00:00
|
|
|
sender.sendMessage(outputFormat(oConfigGroup, listUsers(outputUserList)));
|
2013-03-18 22:43:05 +00:00
|
|
|
}
|
|
|
|
continue;
|
2013-03-18 07:50:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-18 23:14:20 +00:00
|
|
|
outputUserList = getMergedList(playerList, configGroup);
|
2013-03-18 08:53:12 +00:00
|
|
|
|
|
|
|
// If we have no users, than we don't need to continue parsing this group
|
2013-03-18 23:14:20 +00:00
|
|
|
if (outputUserList == null || outputUserList.isEmpty())
|
2013-03-13 15:49:00 +00:00
|
|
|
{
|
2013-03-18 07:50:36 +00:00
|
|
|
continue;
|
2013-03-13 15:49:00 +00:00
|
|
|
}
|
2013-03-18 08:53:12 +00:00
|
|
|
|
2013-03-18 23:14:20 +00:00
|
|
|
sender.sendMessage(outputFormat(configGroup, listUsers(outputUserList)));
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
2013-03-18 07:50:36 +00:00
|
|
|
|
2013-03-18 08:53:12 +00:00
|
|
|
String[] onlineGroups = playerList.keySet().toArray(new String[0]);
|
|
|
|
Arrays.sort(onlineGroups, String.CASE_INSENSITIVE_ORDER);
|
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// If we have an asterisk group, then merge all remaining groups
|
2013-03-18 08:53:12 +00:00
|
|
|
if (!asterisk.isEmpty())
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
{
|
2013-03-18 08:53:12 +00:00
|
|
|
List<User> asteriskUsers = new ArrayList<User>();
|
2013-03-18 23:14:20 +00:00
|
|
|
for (String onlineGroup : onlineGroups)
|
2013-03-18 22:43:05 +00:00
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
asteriskUsers.addAll(playerList.get(onlineGroup));
|
2013-03-18 08:53:12 +00:00
|
|
|
}
|
|
|
|
for (String key : asterisk)
|
|
|
|
{
|
|
|
|
playerList.put(key, asteriskUsers);
|
2013-03-18 07:50:36 +00:00
|
|
|
}
|
2013-03-18 08:53:12 +00:00
|
|
|
onlineGroups = asterisk.toArray(new String[0]);
|
2013-03-18 07:50:36 +00:00
|
|
|
}
|
2013-03-18 08:53:12 +00:00
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// If we have any groups remaining after the custom groups loop through and display them
|
2013-03-18 23:14:20 +00:00
|
|
|
for (String onlineGroup : onlineGroups)
|
2013-03-18 07:50:36 +00:00
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
List<User> users = playerList.get(onlineGroup);
|
2013-03-13 15:49:00 +00:00
|
|
|
|
2013-03-18 07:50:36 +00:00
|
|
|
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions"))
|
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
onlineGroup = _("connectedPlayers");
|
|
|
|
}
|
2013-03-18 22:43:05 +00:00
|
|
|
if (users == null || users.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-29 02:59:55 +00:00
|
|
|
String groupName = users.get(0).getGroup();
|
2013-03-19 18:34:28 +00:00
|
|
|
sender.sendMessage(outputFormat(groupName, listUsers(users)));
|
2013-03-13 15:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-18 22:43:05 +00:00
|
|
|
// Cosmetic list formatting
|
2013-03-13 15:49:00 +00:00
|
|
|
private String listUsers(List<User> users)
|
|
|
|
{
|
|
|
|
final StringBuilder groupString = new StringBuilder();
|
|
|
|
Collections.sort(users);
|
2013-03-18 23:14:20 +00:00
|
|
|
boolean needComma = false;
|
2013-03-13 15:49:00 +00:00
|
|
|
for (User user : users)
|
|
|
|
{
|
2013-03-18 23:14:20 +00:00
|
|
|
if (needComma)
|
2013-03-13 15:49:00 +00:00
|
|
|
{
|
|
|
|
groupString.append(", ");
|
|
|
|
}
|
2013-03-18 23:14:20 +00:00
|
|
|
needComma = true;
|
2013-03-13 15:49:00 +00:00
|
|
|
if (user.isAfk())
|
|
|
|
{
|
|
|
|
groupString.append(_("listAfkTag"));
|
|
|
|
}
|
|
|
|
if (user.isHidden())
|
|
|
|
{
|
|
|
|
groupString.append(_("listHiddenTag"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
user.setDisplayNick();
|
|
|
|
groupString.append(user.getDisplayName());
|
|
|
|
groupString.append("§f");
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
return groupString.toString();
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2013-03-18 22:43:05 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|