Better distance checking.

This commit is contained in:
KHobbits 2011-12-01 15:15:45 +00:00
parent 00d44873ca
commit b0377498f7
9 changed files with 32 additions and 39 deletions

View File

@ -16,7 +16,6 @@ public class Commandnear extends EssentialsCommand
super("near"); super("near");
} }
//Todo Translate
@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
{ {
@ -34,26 +33,23 @@ public class Commandnear extends EssentialsCommand
user.sendMessage(_("nearbyPlayers", getLocal(server, user, radius))); user.sendMessage(_("nearbyPlayers", getLocal(server, user, radius)));
} }
private String getLocal(final Server server, final User user, final long radius) private String getLocal(final Server server, final User user, long radius)
{ {
final Location loc = user.getLocation(); final Location loc = user.getLocation();
final World world = loc.getWorld(); final World world = loc.getWorld();
final int x = loc.getBlockX();
final int y = loc.getBlockY();
final int z = loc.getBlockZ();
final StringBuilder output = new StringBuilder(); final StringBuilder output = new StringBuilder();
radius *= radius;
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
final User player = ess.getUser(onlinePlayer); final User player = ess.getUser(onlinePlayer);
if (!player.equals(user) && !player.isHidden()) if (!player.equals(user) && !player.isHidden())
{ {
final Location l = player.getLocation(); final Location playerLoc = player.getLocation();
final int dx = x - l.getBlockX(); if (playerLoc.getWorld() != world) { continue; }
final int dy = y - l.getBlockY();
final int dz = z - l.getBlockZ(); final double delta = playerLoc.distanceSquared(loc);
final long delta = dx * dx + dy * dy + dz * dz; if (delta > radius)
if (delta > radius || world != l.getWorld())
{ {
if (output.length() > 0) if (output.length() > 0)
{ {

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cYou do not have the \u00a7fessentials.mail.send\u00a7c per
noMotd=\u00a7cThere is no message of the day. noMotd=\u00a7cThere is no message of the day.
noNewMail=\u00a77You have no new mail. noNewMail=\u00a77You have no new mail.
noPendingRequest=You do not have a pending request. noPendingRequest=You do not have a pending request.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cYou do not have permission to place a block near that sign. noPlacePermission=\u00a7cYou do not have permission to place a block near that sign.
noPowerTools=You have no power tools assigned. noPowerTools=You have no power tools assigned.
noRules=\u00a7cThere are no rules specified yet. noRules=\u00a7cThere are no rules specified yet.

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cDu har ikke \u00a7fessentials.mail.send\u00a7c tilladelsen
noMotd=\u00a7cDer er ikke nogen besked for dagen. noMotd=\u00a7cDer er ikke nogen besked for dagen.
noNewMail=\u00a77Du har ingen ny post. noNewMail=\u00a77Du har ingen ny post.
noPendingRequest=Du har ikke en ventende anmodning. noPendingRequest=Du har ikke en ventende anmodning.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cYou do not have permission to place a block near that sign. noPlacePermission=\u00a7cYou do not have permission to place a block near that sign.
noPowerTools= You have no power tools assigned. noPowerTools= You have no power tools assigned.
noRules=\u00a7cDer er ingen regler fastsat endnu. noRules=\u00a7cDer er ingen regler fastsat endnu.

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cDu hast die Rechte \u00a7fessentials.mail.send\u00a7c nich
noMotd=\u00a7cEs existiert keine Willkommensnachricht. noMotd=\u00a7cEs existiert keine Willkommensnachricht.
noNewMail=\u00a77Du hast keine Nachrichten. noNewMail=\u00a77Du hast keine Nachrichten.
noPendingRequest=Du hast keine Teleportierungsanfragen. noPendingRequest=Du hast keine Teleportierungsanfragen.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cDu hast keine Rechte, einen Block in der N\u00e4he des Schildes zu platzieren. noPlacePermission=\u00a7cDu hast keine Rechte, einen Block in der N\u00e4he des Schildes zu platzieren.
noPowerTools=Du hast keine Powertools zugewiesen. noPowerTools=Du hast keine Powertools zugewiesen.
noRules=\u00a7cEs wurden keine Regeln definiert. noRules=\u00a7cEs wurden keine Regeln definiert.

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cYou do not have the \u00a7fessentials.mail.send\u00a7c per
noMotd=\u00a7cThere is no message of the day. noMotd=\u00a7cThere is no message of the day.
noNewMail=\u00a77You have no new mail. noNewMail=\u00a77You have no new mail.
noPendingRequest=You do not have a pending request. noPendingRequest=You do not have a pending request.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cYou do not have permission to place a block near that sign. noPlacePermission=\u00a7cYou do not have permission to place a block near that sign.
noPowerTools=You have no power tools assigned. noPowerTools=You have no power tools assigned.
noRules=\u00a7cThere are no rules specified yet. noRules=\u00a7cThere are no rules specified yet.

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cNo tienes el permiso de \u00a7fessentials.mail.send\u00a7c
noMotd=\u00a7cNo hay ningun mensaje del dia. noMotd=\u00a7cNo hay ningun mensaje del dia.
noNewMail=\u00a77No tienes ningun correo nuevo. noNewMail=\u00a77No tienes ningun correo nuevo.
noPendingRequest=No tienes ninguna peticion pendiente. noPendingRequest=No tienes ninguna peticion pendiente.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cNo tienes permiso para situar ese bloque en ese lugar. noPlacePermission=\u00a7cNo tienes permiso para situar ese bloque en ese lugar.
noPowerTools=You have no power tools assigned. noPowerTools=You have no power tools assigned.
noRules=\u00a7cNo hay reglas especificadas todavia. noRules=\u00a7cNo hay reglas especificadas todavia.

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cVous n''avez pas la permission \u00a7fessentials.mail.send
noMotd=\u00a7cIl n''y a pas de message su jour. noMotd=\u00a7cIl n''y a pas de message su jour.
noNewMail=\u00a77Vous n''avez pas de courrier. noNewMail=\u00a77Vous n''avez pas de courrier.
noPendingRequest=Vous n''avez pas de requ\u00eate non lue. noPendingRequest=Vous n''avez pas de requ\u00eate non lue.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cVous n''avez pas la permission de placer un bloc pr\u00c3\u00a8 de cette pancarte. noPlacePermission=\u00a7cVous n''avez pas la permission de placer un bloc pr\u00c3\u00a8 de cette pancarte.
noPowerTools=Vous n''avez pas d''outil automatique associ\u00e9. noPowerTools=Vous n''avez pas d''outil automatique associ\u00e9.
noRules=\u00a7cIl n''y a pas encore de r\u00c3\u00a8gles d\u00e9finies. noRules=\u00a7cIl n''y a pas encore de r\u00c3\u00a8gles d\u00e9finies.

View File

@ -221,7 +221,7 @@ noMailSendPerm=\u00a7cJe hebt de \u00a7fessentials.mail.send\u00a7c toestemming
noMotd=\u00a7cEr is geen bericht van de dag. noMotd=\u00a7cEr is geen bericht van de dag.
noNewMail=\u00a77Je hebt geen nieuwe berichten. noNewMail=\u00a77Je hebt geen nieuwe berichten.
noPendingRequest=Je hebt geen aanvragen. noPendingRequest=Je hebt geen aanvragen.
noPermToSpawnMob=\u00a7cYou don't have permission to spawn this mob. noPermToSpawnMob=\u00a7cYou don''t have permission to spawn this mob.
noPlacePermission=\u00a7cJe hebt geen toestemming om een blok naast die sign te plaatsen. noPlacePermission=\u00a7cJe hebt geen toestemming om een blok naast die sign te plaatsen.
noPowerTools=You have no power tools assigned. noPowerTools=You have no power tools assigned.
noRules=\u00a7cEr zijn nog geen regels gegeven. noRules=\u00a7cEr zijn nog geen regels gegeven.

View File

@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
//TODO: Translate the local/spy tags
public abstract class EssentialsChatPlayer extends PlayerListener public abstract class EssentialsChatPlayer extends PlayerListener
{ {
protected transient IEssentials ess; protected transient IEssentials ess;
@ -112,34 +112,31 @@ public abstract class EssentialsChatPlayer extends PlayerListener
logger.info(_("localFormat", sender.getName(), event.getMessage())); logger.info(_("localFormat", sender.getName(), event.getMessage()));
final Location loc = sender.getLocation(); final Location loc = sender.getLocation();
final World world = loc.getWorld(); final World world = loc.getWorld();
final int x = loc.getBlockX();
final int y = loc.getBlockY(); for (Player onlinePlayer : server.getOnlinePlayers())
final int z = loc.getBlockZ();
for (Player p : server.getOnlinePlayers())
{ {
String type = "[L]"; String type = "[L]";
final User u = ess.getUser(p); final User user = ess.getUser(onlinePlayer);
//TODO: remove reference to op //TODO: remove reference to op
if (u.isIgnoredPlayer(sender.getName()) && !sender.isOp()) if (user.isIgnoredPlayer(sender.getName()) && !sender.isOp())
{ {
continue; continue;
} }
if (!u.equals(sender)) if (!user.equals(sender))
{ {
final Location l = u.getLocation(); final Location playerLoc = user.getLocation();
final int dx = x - l.getBlockX(); if (playerLoc.getWorld() != world) { continue; }
final int dy = y - l.getBlockY(); final double delta = playerLoc.distanceSquared(loc);
final int dz = z - l.getBlockZ();
final long delta = dx * dx + dy * dy + dz * dz; if (delta > radius)
if (delta > radius || world != l.getWorld())
{ {
if (!u.isAuthorized("essentials.chat.spy")) if (user.isAuthorized("essentials.chat.spy"))
{ {
continue; type = type.concat("[Spy]");
} }
else else
{ {
type = type.concat("[Spy]"); continue;
} }
} }
} }
@ -147,9 +144,9 @@ public abstract class EssentialsChatPlayer extends PlayerListener
String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage()); String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage());
for (IEssentialsChatListener listener : listeners.values()) for (IEssentialsChatListener listener : listeners.values())
{ {
message = listener.modifyMessage(event, p, message); message = listener.modifyMessage(event, onlinePlayer, message);
} }
u.sendMessage(message); user.sendMessage(message);
} }
} }
} }