1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
package net.ess3.commands;
import java.util.*;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import net.ess3.utils.FormatUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandlist extends EssentialsCommand
{
@Override
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
String online;
boolean showhidden = false;
if (Permissions.LIST_HIDDEN.isAuthorized(sender))
{
showhidden = true;
}
Player userPlayer = getPlayerOrNull(sender);
if (userPlayer != null)
{
int playerHidden = 0;
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (!userPlayer.canSee(onlinePlayer))
{
playerHidden++;
}
}
if (showhidden && playerHidden > 0)
{
online = _("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers());
}
else
{
online = _("listAmount", server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers());
}
}
else
{
online = _("listAmount", server.getOnlinePlayers().length, server.getMaxPlayers());
}
sender.sendMessage(online);
ISettings settings = ess.getSettings();
boolean sortListByGroups = sortListByGroups = settings.getData().getCommands().getList().isSortByGroups();
if (sortListByGroups)
{
Map<String, List<IUser>> sort = new HashMap<String, List<IUser>>();
Set<String> hiddenPlayers = new HashSet<String>();
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (userPlayer != null
&& !userPlayer.canSee(onlinePlayer))
{
hiddenPlayers.add(onlinePlayer.getName());
if (!showhidden)
{
continue;
}
}
final String group = ess.getRanks().getMainGroup(onlinePlayer);
List<IUser> list = sort.get(group);
if (list == null)
{
list = new ArrayList<IUser>();
sort.put(group, list);
}
list.add(getUser(onlinePlayer));
}
final String[] groups = sort.keySet().toArray(new String[0]);
Arrays.sort(groups, String.CASE_INSENSITIVE_ORDER);
for (String group : groups)
{
final StringBuilder groupString = new StringBuilder();
groupString.append(_("listGroupTag", FormatUtil.replaceFormat(group)));
final List<IUser> users = sort.get(group);
Collections.sort(users);
boolean first = true;
for (IUser user : users)
{
if (!first)
{
groupString.append(", ");
}
else
{
first = false;
}
if (user.getData().isAfk())
{
groupString.append(_("listAfkTag"));
}
if (hiddenPlayers.contains(user.getName()))
{
groupString.append(_("listHiddenTag"));
}
user.setDisplayNick();
groupString.append(user.getPlayer().getDisplayName());
groupString.append("§f");
}
sender.sendMessage(groupString.toString());
}
}
else
{
final List<IUser> users = new ArrayList<IUser>();
Set<String> hiddenPlayers = new HashSet<String>();
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (userPlayer != null
&& !userPlayer.canSee(onlinePlayer))
{
hiddenPlayers.add(onlinePlayer.getName());
if (!showhidden)
{
continue;
}
}
users.add(getUser(onlinePlayer));
}
Collections.sort(users);
final StringBuilder onlineUsers = new StringBuilder();
onlineUsers.append(_("connectedPlayers"));
boolean first = true;
for (IUser user : users)
{
if (!first)
{
onlineUsers.append(", ");
}
else
{
first = false;
}
if (user.getData().isAfk())
{
onlineUsers.append(_("listAfkTag"));
}
if (hiddenPlayers.contains(user.getName()))
{
onlineUsers.append(_("listHiddenTag"));
}
user.setDisplayNick();
onlineUsers.append(user.getPlayer().getDisplayName());
onlineUsers.append("§f");
}
sender.sendMessage(onlineUsers.toString());
}
}
}
|