From 093f368545a16ab3e0dd2c41a5e9fd3242a26848 Mon Sep 17 00:00:00 2001 From: bm01 Date: Wed, 29 Feb 2012 03:26:19 +0100 Subject: [PATCH] Replaced m.getDistance() --- .../gmail/nossr50/datatypes/PlayerProfile.java | 2 +- src/main/java/com/gmail/nossr50/m.java | 18 ++++++++++++------ .../java/com/gmail/nossr50/skills/Skills.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 3bcf75b43..aa974f544 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -929,7 +929,7 @@ public class PlayerProfile if(x.isOnline() && !x.getName().equals(thisplayer.getName()) && Party.getInstance().isPartyLeader(x.getName(), this.getParty())) { //leaderName = x.getName(); - if(m.getDistance(thisplayer.getLocation(), x.getLocation()) < 25) + if(m.isNear(thisplayer.getLocation(), x.getLocation(), 25)) { PlayerProfile PartyLeader = Users.getProfile(x); if(PartyLeader.getSkillLevel(skillType) >= this.getSkillLevel(skillType)) diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 1b768b92f..30753c4e3 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -189,13 +189,19 @@ public class m return 1; } - - public static double getDistance(Location loca, Location locb) - { - return Math.sqrt(Math.pow(loca.getX() - locb.getX(), 2) + Math.pow(loca.getY() - locb.getY(), 2) - + Math.pow(loca.getZ() - locb.getZ(), 2)); + + public static boolean isNear(Location first, Location second, int maxDistance) { + double relX = first.getX() - second.getX(); + double relY = first.getY() - second.getY(); + double relZ = first.getZ() - second.getZ(); + double dist = relX * relX + relY * relY + relZ * relZ; + + if (dist < maxDistance * maxDistance) + return true; + + return false; } - + public static boolean abilityBlockCheck(Block block) { switch(block.getType()){ diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index 4278dea5d..34817d585 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -274,7 +274,7 @@ public class Skills player.sendMessage(ability.getAbilityOn()); for(Player y : player.getWorld().getPlayers()) { - if(y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) + if(y != player && m.isNear(player.getLocation(), y.getLocation(), 10)) y.sendMessage(ability.getAbilityPlayer(player)); } PP.setSkillDATS(ability, System.currentTimeMillis()+(ticks*1000));