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");
}
//Todo Translate
@Override
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)));
}
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 World world = loc.getWorld();
final int x = loc.getBlockX();
final int y = loc.getBlockY();
final int z = loc.getBlockZ();
final World world = loc.getWorld();
final StringBuilder output = new StringBuilder();
radius *= radius;
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User player = ess.getUser(onlinePlayer);
if (!player.equals(user) && !player.isHidden())
{
final Location l = player.getLocation();
final int dx = x - l.getBlockX();
final int dy = y - l.getBlockY();
final int dz = z - l.getBlockZ();
final long delta = dx * dx + dy * dy + dz * dz;
if (delta > radius || world != l.getWorld())
final Location playerLoc = player.getLocation();
if (playerLoc.getWorld() != world) { continue; }
final double delta = playerLoc.distanceSquared(loc);
if (delta > radius)
{
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.
noNewMail=\u00a77You have no new mail.
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.
noPowerTools=You have no power tools assigned.
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.
noNewMail=\u00a77Du har ingen ny post.
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.
noPowerTools= You have no power tools assigned.
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.
noNewMail=\u00a77Du hast keine Nachrichten.
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.
noPowerTools=Du hast keine Powertools zugewiesen.
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.
noNewMail=\u00a77You have no new mail.
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.
noPowerTools=You have no power tools assigned.
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.
noNewMail=\u00a77No tienes ningun correo nuevo.
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.
noPowerTools=You have no power tools assigned.
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.
noNewMail=\u00a77Vous n''avez pas de courrier.
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.
noPowerTools=Vous n''avez pas d''outil automatique associ\u00e9.
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.
noNewMail=\u00a77Je hebt geen nieuwe berichten.
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.
noPowerTools=You have no power tools assigned.
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.PlayerListener;
//TODO: Translate the local/spy tags
public abstract class EssentialsChatPlayer extends PlayerListener
{
protected transient IEssentials ess;
@ -112,34 +112,31 @@ public abstract class EssentialsChatPlayer extends PlayerListener
logger.info(_("localFormat", sender.getName(), event.getMessage()));
final Location loc = sender.getLocation();
final World world = loc.getWorld();
final int x = loc.getBlockX();
final int y = loc.getBlockY();
final int z = loc.getBlockZ();
for (Player p : server.getOnlinePlayers())
for (Player onlinePlayer : server.getOnlinePlayers())
{
String type = "[L]";
final User u = ess.getUser(p);
final User user = ess.getUser(onlinePlayer);
//TODO: remove reference to op
if (u.isIgnoredPlayer(sender.getName()) && !sender.isOp())
if (user.isIgnoredPlayer(sender.getName()) && !sender.isOp())
{
continue;
}
if (!u.equals(sender))
{
final Location l = u.getLocation();
final int dx = x - l.getBlockX();
final int dy = y - l.getBlockY();
final int dz = z - l.getBlockZ();
final long delta = dx * dx + dy * dy + dz * dz;
if (delta > radius || world != l.getWorld())
if (!user.equals(sender))
{
final Location playerLoc = user.getLocation();
if (playerLoc.getWorld() != world) { continue; }
final double delta = playerLoc.distanceSquared(loc);
if (delta > radius)
{
if (!u.isAuthorized("essentials.chat.spy"))
if (user.isAuthorized("essentials.chat.spy"))
{
continue;
type = type.concat("[Spy]");
}
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());
for (IEssentialsChatListener listener : listeners.values())
{
message = listener.modifyMessage(event, p, message);
message = listener.modifyMessage(event, onlinePlayer, message);
}
u.sendMessage(message);
user.sendMessage(message);
}
}
}