summaryrefslogtreecommitdiffstats
path: root/EssentialsChat/src/com/earth2me/essentials/chat
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2011-12-01 15:15:45 +0000
committerKHobbits <rob@khobbits.co.uk>2011-12-01 15:15:45 +0000
commitb0377498f72814cb78e1ffd0286ffd4a92333f50 (patch)
tree00180217195c9bbc58fd48deb112f5b10ba26b8f /EssentialsChat/src/com/earth2me/essentials/chat
parent00d44873ca4bb810add4d49aa5e5b6d4545c727a (diff)
downloadEssentials-b0377498f72814cb78e1ffd0286ffd4a92333f50.tar
Essentials-b0377498f72814cb78e1ffd0286ffd4a92333f50.tar.gz
Essentials-b0377498f72814cb78e1ffd0286ffd4a92333f50.tar.lz
Essentials-b0377498f72814cb78e1ffd0286ffd4a92333f50.tar.xz
Essentials-b0377498f72814cb78e1ffd0286ffd4a92333f50.zip
Better distance checking.
Diffstat (limited to 'EssentialsChat/src/com/earth2me/essentials/chat')
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java37
1 files changed, 17 insertions, 20 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java
index 305e13e8a..2d6e1ae4e 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java
@@ -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);
}
}
}