summaryrefslogtreecommitdiffstats
path: root/EssentialsChat/src/com
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
commite7ea30c5177140000d3deb2aaafaca5e73f958a6 (patch)
tree19a61ce1f5cca0fd1aafd02862de40d718302ec9 /EssentialsChat/src/com
parent34a2e03df74f6cf007b42c917f6f5e9400a8ec92 (diff)
downloadEssentials-e7ea30c5177140000d3deb2aaafaca5e73f958a6.tar
Essentials-e7ea30c5177140000d3deb2aaafaca5e73f958a6.tar.gz
Essentials-e7ea30c5177140000d3deb2aaafaca5e73f958a6.tar.lz
Essentials-e7ea30c5177140000d3deb2aaafaca5e73f958a6.tar.xz
Essentials-e7ea30c5177140000d3deb2aaafaca5e73f958a6.zip
Better distance checking.
Diffstat (limited to 'EssentialsChat/src/com')
-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);
}
}
}