Updated /near and /getpos command, added new argument playername

Test #1214
This commit is contained in:
snowleo 2011-12-07 10:03:23 +01:00
parent e8eb1974b8
commit 67a3a55f5a
3 changed files with 109 additions and 23 deletions

View file

@ -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));
}
}
}

View file

@ -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)
{

View file

@ -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.