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
|
package net.ess3.commands;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.api.server.CommandSender;
import net.ess3.api.server.Location;
import net.ess3.api.server.Player;
import net.ess3.api.server.World;
import net.ess3.permissions.Permissions;
public class Commandnear extends EssentialsCommand
{
@Override
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
long radius = 200;
IUser otherUser = null;
if (args.length > 0)
{
try
{
otherUser = ess.getUserMap().matchUser(args[0], false, false);
}
catch (Exception ex)
{
try
{
radius = Long.parseLong(args[0]);
}
catch (NumberFormatException e)
{
}
}
if (args.length > 1 && otherUser != null)
{
try
{
radius = Long.parseLong(args[1]);
}
catch (NumberFormatException e)
{
}
}
}
if (otherUser == null || Permissions.NEAR_OTHERS.isAuthorized(user))
{
user.sendMessage(_("nearbyPlayers", getLocal(otherUser == null ? user : otherUser, radius)));
}
else
{
user.sendMessage(_("noAccessCommand"));
}
}
@Override
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length == 0)
{
throw new NotEnoughArgumentsException();
}
final IUser otherUser = ess.getUserMap().matchUser(args[0], false, false);
long radius = 200;
if (args.length > 1)
{
try
{
radius = Long.parseLong(args[1]);
}
catch (NumberFormatException e)
{
}
}
sender.sendMessage(_("nearbyPlayers", getLocal(otherUser, radius)));
}
private String getLocal(final IUser user, final long radius)
{
final Location loc = user.getLocation();
final World world = loc.getWorld();
final StringBuilder output = new StringBuilder();
final long radiusSquared = radius * radius;
for (Player onlinePlayer : server.getOnlinePlayers())
{
final IUser player = ess.getUserMap().getUser(onlinePlayer);
if (!player.equals(user) && !player.isHidden())
{
final Location playerLoc = player.getLocation();
if (playerLoc.getWorld() != world)
{
continue;
}
final long delta = (long)playerLoc.distanceSquared(loc);
if (delta < radiusSquared)
{
if (output.length() > 0)
{
output.append(", ");
}
output.append(player.getDisplayName()).append("§f(§4").append((long)Math.sqrt(delta)).append("m§f)");
}
}
}
return output.length() > 1 ? output.toString() : _("none");
}
}
|