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
|
|
|
{
|
2011-07-18 01:42:21 +00:00
|
|
|
boolean showhidden = false;
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
|
|
|
if (ess.getUser(sender).isAuthorized("essentials.list.hidden"))
|
|
|
|
{
|
|
|
|
showhidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
showhidden = true;
|
|
|
|
}
|
|
|
|
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-13 15:49:00 +00:00
|
|
|
String online;
|
2011-07-18 03:45:05 +00:00
|
|
|
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
|
|
|
}
|
2011-11-26 14:26:48 +00:00
|
|
|
sender.sendMessage(online);
|
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
|
|
|
|
|
|
|
Map<String, List<User>> sort = 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-13 15:49:00 +00:00
|
|
|
final User player = ess.getUser(OnlinePlayer);
|
|
|
|
if (player.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-13 15:49:00 +00:00
|
|
|
final String group = player.getGroup().toLowerCase();
|
|
|
|
List<User> list = sort.get(group);
|
|
|
|
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>();
|
|
|
|
sort.put(group, list);
|
|
|
|
}
|
|
|
|
list.add(player);
|
|
|
|
}
|
|
|
|
final StringBuilder groupString = new StringBuilder();
|
|
|
|
Set<String> keys = ess.getSettings().getListGroupConfig().keySet();
|
|
|
|
if (args.length > 0)
|
|
|
|
{
|
|
|
|
final List<User> users = new ArrayList<User>();
|
|
|
|
String group = args[0].toLowerCase();
|
|
|
|
for (String key : keys)
|
|
|
|
{
|
|
|
|
String groupValue = ess.getSettings().getListGroupConfig().get(key).toString().trim();
|
|
|
|
if(key.equalsIgnoreCase(group) && groupValue.contains(","))
|
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
|
|
|
String[] groups = groupValue.split(",");
|
|
|
|
for (String g : groups)
|
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
|
|
|
if (g == null || g.equals(""))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
List<User> u = sort.get(g.trim());
|
|
|
|
if (u == null || u.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
users.addAll(u);
|
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
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
List<User> groupUsers = sort.get(group);
|
|
|
|
if (groupUsers != null && !groupUsers.isEmpty())
|
|
|
|
{
|
|
|
|
users.addAll(groupUsers);
|
|
|
|
}
|
|
|
|
if (users == null || users.isEmpty())
|
|
|
|
{
|
|
|
|
throw new Exception(_("groupDoesNotExist"));
|
|
|
|
}
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-13 15:49:00 +00:00
|
|
|
Map<String, String> usedGroups = new HashMap();
|
|
|
|
for (String group : keys)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2013-03-13 15:49:00 +00:00
|
|
|
boolean userLimit = false;
|
|
|
|
String groupValue = ess.getSettings().getListGroupConfig().get(group).toString().trim();
|
|
|
|
usedGroups.put(group.toLowerCase(), groupValue);
|
|
|
|
if (groupValue.equals("hidden"))
|
2011-07-18 01:42:21 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
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())
|
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
|
|
|
users.addAll(u);
|
|
|
|
if (userLimit)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (groupValue.contains(",") || sort.containsKey(groupValue.toLowerCase()))
|
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
|
|
|
if (sort.containsKey(groupValue))
|
|
|
|
{
|
|
|
|
u = sort.get(groupValue);
|
|
|
|
if (u == null || u.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
users.addAll(u);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String[] groups = groupValue.split(",");
|
|
|
|
for (String g : groups)
|
|
|
|
{
|
|
|
|
if (g == null || g.equals(""))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
u = sort.get(g.trim());
|
|
|
|
if (u == null || u.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
users.addAll(u);
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
if (users == null || users.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-13 15:49:00 +00:00
|
|
|
continue;
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
final String[] groups = sort.keySet().toArray(new String[0]);
|
|
|
|
Arrays.sort(groups, String.CASE_INSENSITIVE_ORDER);
|
|
|
|
for (String group : groups)
|
|
|
|
{
|
|
|
|
group = group.toLowerCase();
|
|
|
|
if (usedGroups.containsKey(group))
|
2011-07-18 01:42:21 +00:00
|
|
|
{
|
2013-03-13 15:49:00 +00:00
|
|
|
continue;
|
2011-07-18 01:42:21 +00:00
|
|
|
}
|
2013-03-13 15:49:00 +00:00
|
|
|
groupString.append(_("listGroupTag", Util.replaceFormat(group)));
|
|
|
|
final List<User> users = sort.get(group);
|
|
|
|
groupString.append(listUsers(users));
|
|
|
|
groupString.setCharAt(0, Character.toTitleCase(groupString.charAt(0)));
|
|
|
|
sender.sendMessage(groupString.toString());
|
|
|
|
groupString.setLength(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String listUsers(List<User> users)
|
|
|
|
{
|
|
|
|
final StringBuilder groupString = new StringBuilder();
|
|
|
|
Collections.sort(users);
|
|
|
|
boolean first = true;
|
|
|
|
for (User user : users)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
groupString.append(", ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|