mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-25 18:48:24 +01:00
parent
735f9ce212
commit
9ee78bdaec
@ -15,40 +15,40 @@ public class Commandnear extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
super("near");
|
super("near");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
long radius = 200;
|
long radius = 200;
|
||||||
User otherUser = null;
|
User otherUser = null;
|
||||||
|
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
otherUser = getPlayer(server, args, 0);
|
radius = Long.parseLong(args[0]);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
radius = Long.parseLong(args[0]);
|
otherUser = getPlayer(server, args, 0);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args.length > 1 && otherUser != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
radius = Long.parseLong(args[1]);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args.length > 1 && otherUser != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
radius = Long.parseLong(args[1]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (otherUser == null || user.isAuthorized("essentials.near.others"))
|
if (otherUser == null || user.isAuthorized("essentials.near.others"))
|
||||||
{
|
{
|
||||||
user.sendMessage(_("nearbyPlayers", getLocal(server, otherUser == null ? user : otherUser, radius)));
|
user.sendMessage(_("nearbyPlayers", getLocal(server, otherUser == null ? user : otherUser, radius)));
|
||||||
@ -58,20 +58,15 @@ public class Commandnear extends EssentialsCommand
|
|||||||
user.sendMessage(_("noAccessCommand"));
|
user.sendMessage(_("noAccessCommand"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
|
if (args.length == 0)
|
||||||
User otherUser = null;
|
|
||||||
if (args.length > 0)
|
|
||||||
{
|
|
||||||
otherUser = getPlayer(server, args, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
final User otherUser = getPlayer(server, args, 0);
|
||||||
long radius = 200;
|
long radius = 200;
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
@ -85,14 +80,14 @@ public class Commandnear extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
sender.sendMessage(_("nearbyPlayers", getLocal(server, otherUser, radius)));
|
sender.sendMessage(_("nearbyPlayers", getLocal(server, otherUser, radius)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocal(final Server server, final User user, final long radius)
|
private String getLocal(final Server server, final User user, final long radius)
|
||||||
{
|
{
|
||||||
final Location loc = user.getLocation();
|
final Location loc = user.getLocation();
|
||||||
final World world = loc.getWorld();
|
final World world = loc.getWorld();
|
||||||
final StringBuilder output = new StringBuilder();
|
final StringBuilder output = new StringBuilder();
|
||||||
final long radiusSquared = radius * radius;
|
final long radiusSquared = radius * radius;
|
||||||
|
|
||||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
final User player = ess.getUser(onlinePlayer);
|
final User player = ess.getUser(onlinePlayer);
|
||||||
@ -103,7 +98,7 @@ public class Commandnear extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long delta = (long)playerLoc.distanceSquared(loc);
|
final long delta = (long)playerLoc.distanceSquared(loc);
|
||||||
if (delta < radiusSquared)
|
if (delta < radiusSquared)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user