diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-01-29 03:09:59 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-01-29 03:09:59 +0000 |
commit | 9438375c4952208a685879b702e4128a8bf767ce (patch) | |
tree | 8c195deedbc211b4a42331dcf014fe7bd1cc3527 | |
parent | ba8aa8bf28971504d61dab142f0617837b3f4eb0 (diff) | |
download | Essentials-9438375c4952208a685879b702e4128a8bf767ce.tar Essentials-9438375c4952208a685879b702e4128a8bf767ce.tar.gz Essentials-9438375c4952208a685879b702e4128a8bf767ce.tar.lz Essentials-9438375c4952208a685879b702e4128a8bf767ce.tar.xz Essentials-9438375c4952208a685879b702e4128a8bf767ce.zip |
Switch /near priority to check for int first.
Test #1269
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandnear.java | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index 0afcf1650..c13c1489d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -15,38 +15,38 @@ public class Commandnear extends EssentialsCommand { super("near"); } - + @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { long radius = 200; User otherUser = null; - + if (args.length > 0) { try { - otherUser = getPlayer(server, args, 0); + radius = Long.parseLong(args[0]); } - catch (Exception ex) + catch (NumberFormatException e) { try { - radius = Long.parseLong(args[0]); + otherUser = getPlayer(server, args, 0); } - catch (NumberFormatException e) + catch (Exception ex) { } } - } - if (args.length > 1 && otherUser != null) - { - try - { - radius = Long.parseLong(args[1]); - } - 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")) @@ -58,20 +58,15 @@ public class Commandnear extends EssentialsCommand user.sendMessage(_("noAccessCommand")); } } - + @Override protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - - User otherUser = null; - if (args.length > 0) - { - otherUser = getPlayer(server, args, 0); - } - else + if (args.length == 0) { throw new NotEnoughArgumentsException(); } + final User otherUser = getPlayer(server, args, 0); long radius = 200; if (args.length > 1) { @@ -85,14 +80,14 @@ public class Commandnear extends EssentialsCommand } sender.sendMessage(_("nearbyPlayers", getLocal(server, otherUser, radius))); } - + private String getLocal(final Server server, final User 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 User player = ess.getUser(onlinePlayer); @@ -103,7 +98,7 @@ public class Commandnear extends EssentialsCommand { continue; } - + final long delta = (long)playerLoc.distanceSquared(loc); if (delta < radiusSquared) { |