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
|
package com.earth2me.essentials.commands;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Server;
import org.bukkit.entity.Player;
public abstract class EssentialsLoopCommand extends EssentialsCommand
{
public EssentialsLoopCommand(String command)
{
super(command);
}
protected void loopOfflinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, boolean matchWildcards, final String searchTerm, final String[] commandArgs)
throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException
{
if (searchTerm.isEmpty())
{
throw new PlayerNotFoundException();
}
if (matchWildcards && searchTerm.contentEquals("**"))
{
for (UUID sUser : ess.getUserMap().getAllUniqueUsers())
{
final User matchedUser = ess.getUser(sUser);
updatePlayer(server, sender, matchedUser, commandArgs);
}
}
else if (matchWildcards && searchTerm.contentEquals("*"))
{
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User onlineUser = ess.getUser(onlinePlayer);
if (skipHidden && onlineUser.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
{
continue;
}
updatePlayer(server, sender, onlineUser, commandArgs);
}
}
else if (multipleStringMatches)
{
if (searchTerm.trim().length() < 3)
{
throw new PlayerNotFoundException();
}
final List<Player> matchedPlayers = server.matchPlayer(searchTerm);
if (matchedPlayers.isEmpty())
{
final User matchedUser = getPlayer(server, searchTerm, true, true);
updatePlayer(server, sender, matchedUser, commandArgs);
}
for (Player matchPlayer : matchedPlayers)
{
final User matchedUser = ess.getUser(matchPlayer);
updatePlayer(server, sender, matchedUser, commandArgs);
}
}
else
{
final User user = getPlayer(server, searchTerm, true, true);
updatePlayer(server, sender, user, commandArgs);
}
}
protected void loopOnlinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, boolean matchWildcards, final String searchTerm, final String[] commandArgs)
throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException
{
if (searchTerm.isEmpty())
{
throw new PlayerNotFoundException();
}
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
if (matchWildcards && (searchTerm.contentEquals("**") || searchTerm.contentEquals("*")))
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User onlineUser = ess.getUser(onlinePlayer);
if (skipHidden && onlineUser.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
{
continue;
}
updatePlayer(server, sender, onlineUser, commandArgs);
}
}
else if (multipleStringMatches)
{
if (searchTerm.trim().length() < 2)
{
throw new PlayerNotFoundException();
}
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(searchTerm);
if (matchedPlayers.isEmpty())
{
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User player = ess.getUser(onlinePlayer);
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
{
continue;
}
final String displayName = FormatUtil.stripFormat(player.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(matchText))
{
foundUser = true;
updatePlayer(server, sender, player, commandArgs);
}
}
}
else
{
for (Player matchPlayer : matchedPlayers)
{
final User player = ess.getUser(matchPlayer);
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
{
continue;
}
foundUser = true;
updatePlayer(server, sender, player, commandArgs);
}
}
if (!foundUser)
{
throw new PlayerNotFoundException();
}
}
else
{
final User player = getPlayer(server, sender, searchTerm);
updatePlayer(server, sender, player, commandArgs);
}
}
protected abstract void updatePlayer(Server server, CommandSource sender, User user, String[] args)
throws NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException;
}
|