summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-12-07 10:03:23 +0100
committersnowleo <schneeleo@gmail.com>2011-12-07 10:03:23 +0100
commit67a3a55f5a396c399697aa42053d378bc5e65d05 (patch)
treedafb71b905b646ceb5f55c3d4747d5e167be5e6b
parente8eb1974b856a9f3867dbd769a3bbe96860eb3c1 (diff)
downloadEssentials-67a3a55f5a396c399697aa42053d378bc5e65d05.tar
Essentials-67a3a55f5a396c399697aa42053d378bc5e65d05.tar.gz
Essentials-67a3a55f5a396c399697aa42053d378bc5e65d05.tar.lz
Essentials-67a3a55f5a396c399697aa42053d378bc5e65d05.tar.xz
Essentials-67a3a55f5a396c399697aa42053d378bc5e65d05.zip
Updated /near and /getpos command, added new argument playername
Test #1214
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java44
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandnear.java80
-rw-r--r--Essentials/src/plugin.yml8
3 files changed, 109 insertions, 23 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java
index b79df021c..c61702e59 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Location;
import org.bukkit.Server;
+import org.bukkit.command.CommandSender;
public class Commandgetpos extends EssentialsCommand
@@ -11,15 +12,44 @@ public class Commandgetpos extends EssentialsCommand
{
super("getpos");
}
-
+
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- final Location coords = user.getLocation();
- user.sendMessage("§7X: " + coords.getBlockX() + " (+East <-> -West)");
- user.sendMessage("§7Y: " + coords.getBlockY() + " (+Up <-> -Down)");
- user.sendMessage("§7Z: " + coords.getBlockZ() + " (+South <-> -North)");
- user.sendMessage("§7Yaw: " + (coords.getYaw() + 180 + 360) % 360 + " (Rotation)");
- user.sendMessage("§7Pitch: " + coords.getPitch() + " (Head angle)");
+ if (args.length > 0 && user.isAuthorized("essentials.getpos.others"))
+ {
+ final User otherUser = getPlayer(server, args, 0);
+ outputPosition(user, otherUser.getLocation(), user.getLocation());
+ }
+ else
+ {
+ outputPosition(user, user.getLocation(), null);
+ }
+ }
+
+ @Override
+ protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
+ {
+ if (args.length < 1)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+ final User user = getPlayer(server, args, 0);
+ outputPosition(sender, user.getLocation(), null);
+ }
+
+ //TODO: Translate
+ private void outputPosition(final CommandSender sender, final Location coords, final Location distance)
+ {
+ sender.sendMessage("§7World: " + coords.getWorld().getName());
+ sender.sendMessage("§7X: " + coords.getBlockX() + " (+East <-> -West)");
+ sender.sendMessage("§7Y: " + coords.getBlockY() + " (+Up <-> -Down)");
+ sender.sendMessage("§7Z: " + coords.getBlockZ() + " (+South <-> -North)");
+ sender.sendMessage("§7Yaw: " + (coords.getYaw() + 180 + 360) % 360 + " (Rotation)");
+ sender.sendMessage("§7Pitch: " + coords.getPitch() + " (Head angle)");
+ if (distance != null && coords.getWorld().equals(distance.getWorld()))
+ {
+ sender.sendMessage("§7Distance: " + coords.distance(distance));
+ }
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java
index 2730256ef..18fb798af 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java
@@ -1,11 +1,11 @@
package com.earth2me.essentials.commands;
-
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
+import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -15,41 +15,97 @@ 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 = 100;
+ User otherUser = null;
+
if (args.length > 0)
{
try
{
- radius = Long.parseLong(args[0]);
+ otherUser = getPlayer(server, args, 0);
+ }
+ 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)
{
}
}
- user.sendMessage(_("nearbyPlayers", getLocal(server, user, radius)));
+ if (otherUser == null || user.isAuthorized("essentials.near.others"))
+ {
+ user.sendMessage(_("nearbyPlayers", getLocal(server, otherUser == null ? user : otherUser, radius)));
+ }
+ else
+ {
+ user.sendMessage(_("noAccessCommand"));
+ }
}
-
- private String getLocal(final Server server, final User user, long radius)
+
+ @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
+ {
+ throw new NotEnoughArgumentsException();
+ }
+ long radius = 100;
+ if (args.length > 1)
+ {
+ try
+ {
+ radius = Long.parseLong(args[1]);
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ }
+ 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 World world = loc.getWorld();
final StringBuilder output = new StringBuilder();
- radius *= radius;
-
+ final long radiusSquared = radius * radius;
+
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User player = ess.getUser(onlinePlayer);
if (!player.equals(user) && !player.isHidden())
{
final Location playerLoc = player.getLocation();
- if (playerLoc.getWorld() != world) { continue; }
+ if (playerLoc.getWorld() != world)
+ {
+ continue;
+ }
- final long delta = (long)playerLoc.distanceSquared(loc);
- if (delta < radius)
+ final long delta = (long)playerLoc.distanceSquared(loc);
+ if (delta < radiusSquared)
{
if (output.length() > 0)
{
diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml
index 64e5fb2cb..5fa22dd8f 100644
--- a/Essentials/src/plugin.yml
+++ b/Essentials/src/plugin.yml
@@ -115,8 +115,8 @@ commands:
usage: /<command> [player]
aliases: [gm,creative,creativemode,egamemode,ecreative,ecreativemode,egm]
getpos:
- description: Get your current coordinates.
- usage: /<command>
+ description: Get your current coordinates or those of a player.
+ usage: /<command> [player]
aliases: [coords,egetpos,whereami,ewhereami]
gc:
description: Reports garbage collection info; useful to developers.
@@ -219,8 +219,8 @@ commands:
usage: /<command> <player> [datediff]
aliases: [emute]
near:
- description: Lists the players near by.
- usage: /<command> [radius]
+ description: Lists the players near by or around a player
+ usage: /<command> [playername] [radius]
aliases: [nearby,enear,enearby]
nick:
description: Change your nickname or that of another player.