changed /f home enemy distance check to use simpler box shaped detection area instead of diamond shaped

This commit is contained in:
Brettflan 2011-06-08 20:33:12 -05:00
parent 85fd5eb04d
commit 19b1ceabdd

View File

@ -43,27 +43,29 @@ public class FCommandHome extends FBaseCommand {
if (Conf.homesTeleportAllowedEnemyDistance > 0 && ! faction.isSafeZone() && ! me.isInOwnTerritory()) { if (Conf.homesTeleportAllowedEnemyDistance > 0 && ! faction.isSafeZone() && ! me.isInOwnTerritory()) {
Location loc = player.getLocation(); Location loc = player.getLocation();
World w = loc.getWorld(); World w = loc.getWorld();
int x = loc.getBlockX(); double x = loc.getX();
int y = loc.getBlockY(); double y = loc.getY();
int z = loc.getBlockZ(); double z = loc.getZ();
for (Player p : player.getServer().getOnlinePlayers()) for (Player p : player.getServer().getOnlinePlayers())
{ {
if (p == null || !p.isOnline() || p.isDead() || p == player || p.getWorld() != w) if (p == null || !p.isOnline() || p.isDead() || p == player || p.getWorld() != w)
continue; continue;
FPlayer fp = FPlayer.get(p); FPlayer fp = FPlayer.get(p);
if (me.getRelation(fp) != Relation.ENEMY) if (me.getRelation(fp) != Relation.ENEMY)
continue; continue;
Location l = p.getLocation(); Location l = p.getLocation();
int dx = Math.abs(x - l.getBlockX()); double dx = Math.abs(x - l.getX());
int dy = Math.abs(y - l.getBlockY()); double dy = Math.abs(y - l.getY());
int dz = Math.abs(z - l.getBlockZ()); double dz = Math.abs(z - l.getZ());
int delta = dx + dy + dz; double max = Conf.homesTeleportAllowedEnemyDistance;
if (delta > Conf.homesTeleportAllowedEnemyDistance)
// box-shaped distance check
if (dx > max || dy > max || dz > max)
continue; continue;
me.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you."); me.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
return; return;
} }