From 3c41c611b9ffaf843fdebd24f0cbba690838ce27 Mon Sep 17 00:00:00 2001 From: Christopher Martin Date: Fri, 14 Oct 2016 21:32:15 -0700 Subject: [PATCH] Add Changes to HealingWaters and Fix for Distance bug (#610) * Add Changes to HealingWaters and Fix for Distance bug * Fix conflicts in EarthGrab.java * Fix conflicts in ConfigManager.java * Fix conflicts in EarthGrab.java --- .../projectkorra/GeneralMethods.java | 12 ++- .../projectkorra/projectkorra/PKListener.java | 4 +- .../projectkorra/airbending/AirBlast.java | 10 +- .../projectkorra/airbending/AirCombo.java | 6 +- .../projectkorra/airbending/AirSuction.java | 5 +- .../projectkorra/airbending/Suffocate.java | 5 +- .../projectkorra/airbending/Tornado.java | 2 +- .../projectkorra/earthbending/Catapult.java | 2 +- .../projectkorra/earthbending/EarthSmash.java | 5 +- .../earthbending/EarthTunnel.java | 5 +- .../earthbending/LavaSurgeWave.java | 2 +- .../projectkorra/earthbending/MetalClips.java | 31 ++++-- .../event/HorizontalVelocityChangeEvent.java | 2 +- .../firebending/FireBlastCharged.java | 10 +- .../projectkorra/firebending/FireShield.java | 2 +- .../projectkorra/firebending/Lightning.java | 6 +- .../projectkorra/util/BlockSource.java | 2 +- .../projectkorra/util/ParticleEffect.java | 2 +- .../waterbending/Bloodbending.java | 10 +- .../waterbending/HealingWaters.java | 102 +++++++++++++----- .../waterbending/IceSpikePillar.java | 5 +- .../waterbending/PhaseChangeFreeze.java | 2 +- .../projectkorra/waterbending/WaterArms.java | 2 +- .../waterbending/WaterArmsWhip.java | 6 +- .../projectkorra/waterbending/WaterSpout.java | 4 +- .../waterbending/WaterSpoutWave.java | 2 +- 26 files changed, 178 insertions(+), 68 deletions(-) diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index a40905b2..df8fbdb2 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -1010,7 +1010,8 @@ public class GeneralMethods { && getDistanceFromLine(direction, origin, entity.getLocation()) < 2 && (entity instanceof LivingEntity) && entity.getEntityId() != player.getEntityId() - && entity.getLocation().distanceSquared(origin.clone().add(direction)) < entity.getLocation().distanceSquared(origin.clone().add(direction.clone().multiply(-1)))) { + && entity.getLocation().distanceSquared(origin.clone().add(direction)) < entity.getLocation().distanceSquared(origin.clone().add(direction.clone().multiply(-1))) + && entity.getWorld().equals(origin.getWorld())) { target = entity; longestr = entity.getLocation().distance(origin); } @@ -1048,7 +1049,10 @@ public class GeneralMethods { } Block block = player.getTargetBlock(trans, (int) originselectrange + 1); - double distance = block.getLocation().distance(origin) - 1.5; + double distance = originselectrange; + if(block.getWorld().equals(origin.getWorld())) { + distance = block.getLocation().distance(origin) - 1.5; + } Location location = origin.add(direction.multiply(distance)); return location; @@ -1141,7 +1145,9 @@ public class GeneralMethods { Location loc; - double max = location1.distance(location2); + double max = 0; + if(location1.getWorld().equals(location2.getWorld())) + max = location1.distance(location2); for (double i = 0; i <= max; i++) { loc = location1.clone().add(direction.clone().multiply(i)); diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 66bef11a..43fd6384 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -1057,8 +1057,10 @@ public class PKListener implements Listener { } else if (Bloodbending.isBloodbent(player)) { - double distance1, distance2; + double distance1 = 0; + double distance2 = 0; Location loc = Bloodbending.getBloodbendingLocation(player); + if (event.getPlayer().getWorld().equals(loc.getWorld())) distance1 = event.getFrom().distance(loc); distance2 = event.getTo().distance(loc); if (distance2 > distance1) { diff --git a/src/com/projectkorra/projectkorra/airbending/AirBlast.java b/src/com/projectkorra/projectkorra/airbending/AirBlast.java index 848b6c4f..7ff6deaa 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBlast.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBlast.java @@ -207,8 +207,9 @@ public class AirBlast extends AirAbility { push.setY(max); } } - - factor *= 1 - location.distance(origin) / (2 * range); + if(location.getWorld().equals(origin.getWorld())) { + factor *= 1 - location.distance(origin) / (2 * range); + } if (isUser && GeneralMethods.isSolid(player.getLocation().add(0, -.5, 0).getBlock())) { factor *= .5; @@ -403,7 +404,10 @@ public class AirBlast extends AirAbility { * messed up and reading the distance returns Double.NaN. If we don't remove this instance * then the AirBlast will never be removed. */ - double dist = location.distance(origin); + double dist = 0; + if(location.getWorld().equals(origin.getWorld())) { + dist = location.distance(origin); + } if (Double.isNaN(dist) || dist > range) { remove(); return; diff --git a/src/com/projectkorra/projectkorra/airbending/AirCombo.java b/src/com/projectkorra/projectkorra/airbending/AirCombo.java index 8439a655..e36acac2 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirCombo.java +++ b/src/com/projectkorra/projectkorra/airbending/AirCombo.java @@ -208,7 +208,7 @@ public class AirCombo extends AirAbility implements ComboAbility { } else if (!player.isSneaking()) { remove(); return; - } else if (Math.abs(player.getLocation().distanceSquared(currentLoc)) > range * range) { + } else if (player.getWorld().equals(currentLoc.getWorld()) && Math.abs(player.getLocation().distanceSquared(currentLoc)) > range * range) { remove(); return; } else if (affectedEntities.size() > 0 && System.currentTimeMillis() - time >= airStreamEntityCarryDuration) { @@ -374,12 +374,12 @@ public class AirCombo extends AirAbility implements ComboAbility { if (combo.getPlayer().equals(player)) { continue; } else if (ability.equalsIgnoreCase("Twister") && combo.abilityName.equalsIgnoreCase("Twister")) { - if (combo.currentLoc != null && Math.abs(combo.currentLoc.distance(loc)) <= radius) { + if (combo.currentLoc != null && combo.currentLoc.getWorld().equals(loc.getWorld()) && Math.abs(combo.currentLoc.distance(loc)) <= radius) { combo.remove(); removed = true; } } else if (ability.equalsIgnoreCase("AirStream") && combo.abilityName.equalsIgnoreCase("AirStream")) { - if (combo.currentLoc != null && Math.abs(combo.currentLoc.distance(loc)) <= radius) { + if (combo.currentLoc != null && combo.currentLoc.getWorld().equals(loc.getWorld()) && Math.abs(combo.currentLoc.distance(loc)) <= radius) { combo.remove(); removed = true; } diff --git a/src/com/projectkorra/projectkorra/airbending/AirSuction.java b/src/com/projectkorra/projectkorra/airbending/AirSuction.java index 06689a36..e4c469ad 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSuction.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSuction.java @@ -178,8 +178,9 @@ public class AirSuction extends AirAbility { push.setY(max); } } - - factor *= 1 - location.distance(origin) / (2 * range); + if(location.getWorld().equals(origin.getWorld())) { + factor *= 1 - location.distance(origin) / (2 * range); + } double comp = velocity.dot(push.clone().normalize()); if (comp > factor) { diff --git a/src/com/projectkorra/projectkorra/airbending/Suffocate.java b/src/com/projectkorra/projectkorra/airbending/Suffocate.java index 2c361d9d..3539721b 100644 --- a/src/com/projectkorra/projectkorra/airbending/Suffocate.java +++ b/src/com/projectkorra/projectkorra/airbending/Suffocate.java @@ -170,7 +170,10 @@ public class Suffocate extends AirAbility { } if (requireConstantAim) { - double dist = player.getEyeLocation().distance(targets.get(0).getEyeLocation()); + double dist = 0; + if(player.getWorld().equals(targets.get(0).getWorld())) { + dist = player.getEyeLocation().distance(targets.get(0).getEyeLocation()); + } Location targetLoc = player.getEyeLocation().clone() .add(player.getEyeLocation().getDirection().normalize().multiply(dist)); List ents = GeneralMethods.getEntitiesAroundPoint(targetLoc, constantAimRadius); diff --git a/src/com/projectkorra/projectkorra/airbending/Tornado.java b/src/com/projectkorra/projectkorra/airbending/Tornado.java index 233a44a5..72823cdb 100644 --- a/src/com/projectkorra/projectkorra/airbending/Tornado.java +++ b/src/com/projectkorra/projectkorra/airbending/Tornado.java @@ -102,7 +102,7 @@ public class Tornado extends AirAbility { if (y > origin.getY() && y < origin.getY() + currentHeight) { factor = (y - origin.getY()) / currentHeight; Location testloc = new Location(origin.getWorld(), origin.getX(), y, origin.getZ()); - if (testloc.distance(entity.getLocation()) < currentRadius * factor) { + if (testloc.getWorld().equals(entity.getWorld()) && testloc.distance(entity.getLocation()) < currentRadius * factor) { double x, z, vx, vz, mag; double angle = 100; double vy = 0.7 * npcPushFactor; diff --git a/src/com/projectkorra/projectkorra/earthbending/Catapult.java b/src/com/projectkorra/projectkorra/earthbending/Catapult.java index b6de9ed5..831b0fab 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Catapult.java +++ b/src/com/projectkorra/projectkorra/earthbending/Catapult.java @@ -116,7 +116,7 @@ public class Catapult extends EarthAbility { private boolean moveEarth() { location = location.clone().add(direction); if (catapult) { - if (location.distance(origin) < 0.5) { + if (location.getWorld().equals(origin.getWorld()) && location.distance(origin) < 0.5) { for (Entity entity : GeneralMethods.getEntitiesAroundPoint(origin, 2)) { if (entity instanceof Player) { Player target = (Player) entity; diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index f7a472e8..0d37afb7 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -122,7 +122,10 @@ public class EarthSmash extends EarthAbility { if (grabbedSmash != null) { grabbedSmash.state = State.GRABBED; - grabbedSmash.grabbedDistance = grabbedSmash.location.distance(player.getEyeLocation()); + grabbedSmash.grabbedDistance = 0; + if(grabbedSmash.location.getWorld().equals(player.getWorld())) { + grabbedSmash.grabbedDistance = grabbedSmash.location.distance(player.getEyeLocation()); + } grabbedSmash.player = player; return; } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java b/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java index 2ef26fe9..cdea4f58 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java @@ -48,7 +48,10 @@ public class EarthTunnel extends EarthAbility { this.origin = player.getTargetBlock((HashSet) null, (int) range).getLocation(); this.block = origin.getBlock(); this.direction = location.getDirection().clone().normalize(); - this.depth = Math.max(0, origin.distance(location) - 1); + this.depth = 0; + if(origin.getWorld().equals(location.getWorld())) { + this.depth = Math.max(0, origin.distance(location) - 1); + } this.angle = 0; if (!bPlayer.canBend(this)) { diff --git a/src/com/projectkorra/projectkorra/earthbending/LavaSurgeWave.java b/src/com/projectkorra/projectkorra/earthbending/LavaSurgeWave.java index 5108e349..6197e2a6 100644 --- a/src/com/projectkorra/projectkorra/earthbending/LavaSurgeWave.java +++ b/src/com/projectkorra/projectkorra/earthbending/LavaSurgeWave.java @@ -266,7 +266,7 @@ public class LavaSurgeWave extends LavaAbility { public static boolean isBlockInWave(Block block) { for (LavaSurgeWave lavaWave : getAbilities(LavaSurgeWave.class)) { - if (block.getLocation().distance(lavaWave.location) <= 2 * lavaWave.radius) { + if (block.getWorld().equals(lavaWave.location.getWorld()) && block.getLocation().distance(lavaWave.location) <= 2 * lavaWave.radius) { return true; } } diff --git a/src/com/projectkorra/projectkorra/earthbending/MetalClips.java b/src/com/projectkorra/projectkorra/earthbending/MetalClips.java index ffa895b4..a6ed654d 100644 --- a/src/com/projectkorra/projectkorra/earthbending/MetalClips.java +++ b/src/com/projectkorra/projectkorra/earthbending/MetalClips.java @@ -366,8 +366,14 @@ public class MetalClips extends MetalAbility { if (isControlling && player.isSneaking()) { if (metalClipsCount == 1) { Location oldLocation = targetEntity.getLocation(); - Location loc = GeneralMethods.getTargetedLocation(player, (int) player.getLocation().distance(oldLocation)); - double distance = loc.distance(oldLocation); + Location loc = oldLocation; + if(player.getWorld().equals(oldLocation.getWorld())) { + loc = GeneralMethods.getTargetedLocation(player, (int) player.getLocation().distance(oldLocation)); + } + double distance = 0; + if(loc.getWorld().equals(oldLocation.getWorld())) { + distance = loc.distance(oldLocation); + } Vector vector = GeneralMethods.getDirection(targetEntity.getLocation(), player.getLocation()); if (distance > 0.5) { @@ -377,9 +383,14 @@ public class MetalClips extends MetalAbility { if (metalClipsCount == 2) { Location oldLocation = targetEntity.getLocation(); - Location loc = GeneralMethods.getTargetedLocation(player, (int) player.getLocation().distance(oldLocation)); - double distance = loc.distance(oldLocation); - + Location loc = oldLocation; + if(player.getWorld().equals(oldLocation.getWorld())) { + loc = GeneralMethods.getTargetedLocation(player, (int) player.getLocation().distance(oldLocation)); + } + double distance = 0; + if(loc.getWorld().equals(oldLocation.getWorld())) { + distance = loc.distance(oldLocation); + } Vector vector = GeneralMethods.getDirection(targetEntity.getLocation(), GeneralMethods.getTargetedLocation(player, 10)); if (distance > 1.2) { @@ -389,8 +400,14 @@ public class MetalClips extends MetalAbility { if (metalClipsCount >= 3) { Location oldLocation = targetEntity.getLocation(); - Location loc = GeneralMethods.getTargetedLocation(player, (int) player.getLocation().distance(oldLocation)); - double distance = loc.distance(oldLocation); + Location loc = oldLocation; + if(player.getWorld().equals(oldLocation.getWorld())) { + loc = GeneralMethods.getTargetedLocation(player, (int) player.getLocation().distance(oldLocation)); + } + double distance = 0; + if(loc.getWorld().equals(oldLocation.getWorld())) { + distance = loc.distance(oldLocation); + } Vector vector = GeneralMethods.getDirection(oldLocation, GeneralMethods.getTargetedLocation(player, 10)); if (distance > 1.2) { diff --git a/src/com/projectkorra/projectkorra/event/HorizontalVelocityChangeEvent.java b/src/com/projectkorra/projectkorra/event/HorizontalVelocityChangeEvent.java index 44babf2a..3dbff2a5 100644 --- a/src/com/projectkorra/projectkorra/event/HorizontalVelocityChangeEvent.java +++ b/src/com/projectkorra/projectkorra/event/HorizontalVelocityChangeEvent.java @@ -73,7 +73,7 @@ public class HorizontalVelocityChangeEvent extends Event implements Cancellable } public double getDistanceTraveled() { - if (start.getWorld() != end.getWorld()) { + if (!start.getWorld().equals(end.getWorld())) { return 0; } return start.distance(end); diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java b/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java index a20782f9..6466290b 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java @@ -135,7 +135,10 @@ public class FireBlastCharged extends FireAbility { return; } - double distance = entity.getLocation().distance(explosion.getLocation()); + double distance = 0; + if(entity.getWorld().equals(explosion.getWorld())) { + distance = entity.getLocation().distance(explosion.getLocation()); + } if (distance > damageRadius) { return; } else if (distance < innerRadius) { @@ -177,7 +180,10 @@ public class FireBlastCharged extends FireAbility { for (Entity entity : entities) { if (entity instanceof LivingEntity) { double slope = -(maxDamage * .5) / (damageRadius - innerRadius); - double damage = slope * (entity.getLocation().distance(location) - innerRadius) + maxDamage; + double damage = 0; + if(entity.getWorld().equals(location.getWorld())) { + damage = slope * (entity.getLocation().distance(location) - innerRadius) + maxDamage; + } DamageHandler.damageEntity(entity, damage, this); } } diff --git a/src/com/projectkorra/projectkorra/firebending/FireShield.java b/src/com/projectkorra/projectkorra/firebending/FireShield.java index dba5899d..c92c0df9 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireShield.java +++ b/src/com/projectkorra/projectkorra/firebending/FireShield.java @@ -74,7 +74,7 @@ public class FireShield extends FireAbility { Location tempLoc = playerLoc.clone().add(playerLoc.multiply(fshield.discRadius)); if (!tempLoc.getWorld().equals(loc.getWorld())) { return false; - } else if (tempLoc.distance(loc) <= fshield.discRadius * fshield.discRadius) { + } else if (tempLoc.getWorld().equals(loc.getWorld()) && tempLoc.distance(loc) <= fshield.discRadius * fshield.discRadius) { return true; } } diff --git a/src/com/projectkorra/projectkorra/firebending/Lightning.java b/src/com/projectkorra/projectkorra/firebending/Lightning.java index d738f180..4412ae6d 100644 --- a/src/com/projectkorra/projectkorra/firebending/Lightning.java +++ b/src/com/projectkorra/projectkorra/firebending/Lightning.java @@ -401,7 +401,11 @@ public class Lightning extends LightningAbility { for (int j = 0; j < points.size() - 1; j += 2) { Location loc1 = points.get(j); Location loc2 = points.get(j + 1); - double adjac = loc1.distance(loc2) / 2; + double adjac = 0; + if (loc1.getWorld().equals(loc2.getWorld())) { + adjac = loc1.distance(loc2) / 2; + } + double angle = (Math.random() - 0.5) * maxArcAngle; angle += angle >= 0 ? 10 : -10; diff --git a/src/com/projectkorra/projectkorra/util/BlockSource.java b/src/com/projectkorra/projectkorra/util/BlockSource.java index 5aec9b84..2a2b4619 100644 --- a/src/com/projectkorra/projectkorra/util/BlockSource.java +++ b/src/com/projectkorra/projectkorra/util/BlockSource.java @@ -244,7 +244,7 @@ public class BlockSource { // Check the block in front of the player's eyes, it may have been created by a // WaterBottle. sourceBlock = WaterAbility.getWaterSourceBlock(player, range, allowPlant); - if (sourceBlock == null || sourceBlock.getLocation().distance(player.getEyeLocation()) > 3) { + if (sourceBlock == null || (sourceBlock.getWorld().equals(player.getWorld()) && sourceBlock.getLocation().distance(player.getEyeLocation()) > 3)) { sourceBlock = null; } } diff --git a/src/com/projectkorra/projectkorra/util/ParticleEffect.java b/src/com/projectkorra/projectkorra/util/ParticleEffect.java index b1b89833..1e6a637b 100644 --- a/src/com/projectkorra/projectkorra/util/ParticleEffect.java +++ b/src/com/projectkorra/projectkorra/util/ParticleEffect.java @@ -626,7 +626,7 @@ public enum ParticleEffect { */ private static boolean isLongDistance(Location location, List players) { for (Player player : players) { - if (player.getLocation().distance(location) < 256) { + if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) < 256) { continue; } return true; diff --git a/src/com/projectkorra/projectkorra/waterbending/Bloodbending.java b/src/com/projectkorra/projectkorra/waterbending/Bloodbending.java index 3d9a2474..ddf39f29 100644 --- a/src/com/projectkorra/projectkorra/waterbending/Bloodbending.java +++ b/src/com/projectkorra/projectkorra/waterbending/Bloodbending.java @@ -146,7 +146,10 @@ public class Bloodbending extends BloodAbility { Location location = player.getLocation(); for (Entity entity : TARGETED_ENTITIES.keySet()) { Location target = entity.getLocation().clone(); - Vector vector = GeneralMethods.getDirection(location, GeneralMethods.getTargetedLocation(player, location.distance(target))); + Vector vector = new Vector(0,0,0); + if (location.getWorld().equals(target.getWorld())) { + vector = GeneralMethods.getDirection(location, GeneralMethods.getTargetedLocation(player, location.distance(target))); + } vector.normalize(); entity.setVelocity(vector.multiply(throwFactor)); new HorizontalVelocityTracker(entity, player, 200, this); @@ -252,7 +255,10 @@ public class Bloodbending extends BloodAbility { } Location location = GeneralMethods.getTargetedLocation(player, 6, getTransparentMaterial()); - double distance = location.distance(target.getLocation()); + double distance = 0; + if(location.getWorld().equals(target.getWorld())) { + location.distance(target.getLocation()); + } double dx, dy, dz; dx = location.getX() - target.getLocation().getX(); dy = location.getY() - target.getLocation().getY(); diff --git a/src/com/projectkorra/projectkorra/waterbending/HealingWaters.java b/src/com/projectkorra/projectkorra/waterbending/HealingWaters.java index 5b7d7d4a..403cc2d1 100644 --- a/src/com/projectkorra/projectkorra/waterbending/HealingWaters.java +++ b/src/com/projectkorra/projectkorra/waterbending/HealingWaters.java @@ -1,10 +1,15 @@ package com.projectkorra.projectkorra.waterbending; +import java.util.HashMap; + import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; @@ -41,6 +46,8 @@ public class HealingWaters extends HealingAbility { private boolean healing = false; private boolean healingSelf = false; private boolean charged = false; + private boolean bottle = false; + private boolean hasReached = false; private String hex; public HealingWaters(Player player) { @@ -88,15 +95,20 @@ public class HealingWaters extends HealingAbility { return; } - if (!inWater(player)) { + if (!inWater(player) && !WaterReturn.hasWaterBottle(player) && !charged) { remove(); return; } + if(WaterReturn.hasWaterBottle(player)) { + bottle = true; + } + // If ability is is charged, set charged = true. If not, play charging particles. if (System.currentTimeMillis() >= startTime + chargeTime) { if (!charged) { this.charged = true; + WaterReturn.emptyWaterBottle(player); } } else { GeneralMethods.displayColoredParticle(origin, hex); @@ -126,13 +138,17 @@ public class HealingWaters extends HealingAbility { public void click() { Entity target = GeneralMethods.getTargetedEntity(player, range); if (target != null && target instanceof LivingEntity) { + hasReached = false; this.target = (LivingEntity) target; } } private void heal(Player player) { - Entity target = GeneralMethods.getTargetedEntity(player, range); - if (target != null && this.target != null && target instanceof LivingEntity && this.target.getEntityId() == target.getEntityId()) { + if(!inWater(player) && !bottle){ + remove(); + } + + if (this.target != null && GeneralMethods.getTargetedEntity(player, range).equals(target) && target instanceof LivingEntity && hasReached) { giveHP(this.target); } else { giveHP(player); @@ -211,47 +227,79 @@ public class HealingWaters extends HealingAbility { } public void displayHealingParticlesOther() { - if (target != null) { - - Location centre = target.getLocation().clone().add(0, 1, 0); - double increment = (2 * Math.PI) / 36; - double angle1 = tstage1 * increment; - double angle2 = tstage2 * increment; - double x1 = centre.getX() + (0.75 * Math.cos(angle1)); - double z1 = centre.getZ() + (0.75 * Math.sin(angle1)); - double x2 = centre.getX() + (0.75 * Math.cos(angle2)); - double z2 = centre.getZ() + (0.75 * Math.sin(angle2)); - - GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x1, centre.getY() + (0.75 * Math.cos(angle1)), z1), hex); - GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x2, centre.getY() + (0.75 * -Math.cos(angle2)), z2), hex); - - if (tstage1 >= 36) { - tstage1 = 0; + if (hasReached) { + Location centre = target.getLocation().clone().add(0, 1, 0); + double increment = (2 * Math.PI) / 36; + double angle1 = tstage1 * increment; + double angle2 = tstage2 * increment; + double x1 = centre.getX() + (0.75 * Math.cos(angle1)); + double z1 = centre.getZ() + (0.75 * Math.sin(angle1)); + double x2 = centre.getX() + (0.75 * Math.cos(angle2)); + double z2 = centre.getZ() + (0.75 * Math.sin(angle2)); + + GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x1, centre.getY() + (0.75 * Math.cos(angle1)), z1), hex); + GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x2, centre.getY() + (0.75 * -Math.cos(angle2)), z2), hex); + + if (tstage1 >= 36) { + tstage1 = 0; + } + tstage1++; + + if (tstage2 >= 36) { + tstage2 = 0; + } + tstage2++; } - tstage1++; - - if (tstage2 >= 36) { - tstage2 = 0; - } - tstage2++; double factor = 0.2; Location targetLoc = target.getLocation().clone().add(0, 1, 0); - double distance = origin.distance(targetLoc); + double distance = 0; + if (origin.getWorld().equals(targetLoc.getWorld())) { + distance = origin.distance(targetLoc); + } Vector vec = new Vector( targetLoc.getX() - location.getX(), targetLoc.getY() - location.getY(), targetLoc.getZ() - location.getZ()).normalize(); - if (origin.distance(location) < distance) { + if (origin.getWorld().equals(location.getWorld()) && origin.distance(location) < distance) { location = location.clone().add(vec.clone().multiply(factor)); GeneralMethods.displayColoredParticle(location, hex); + } else if (origin.getWorld().equals(location.getWorld()) && origin.distance(location) >= distance) { + hasReached = true; } } } + + private void fillBottle() { + PlayerInventory inventory = player.getInventory(); + if (inventory.contains(Material.GLASS_BOTTLE)) { + int index = inventory.first(Material.GLASS_BOTTLE); + ItemStack item = inventory.getItem(index); + + if (item.getAmount() == 1) { + inventory.setItem(index, new ItemStack(Material.POTION)); + } else { + item.setAmount(item.getAmount() - 1); + inventory.setItem(index, item); + HashMap leftover = inventory.addItem(new ItemStack(Material.POTION)); + for (int left : leftover.keySet()) { + player.getWorld().dropItemNaturally(player.getLocation(), leftover.get(left)); + } + } + } + } + + @Override + public void remove() { + if(bottle) { + fillBottle(); + } + HealingWaters.super.remove(); + } @Override public boolean isSneakAbility() { diff --git a/src/com/projectkorra/projectkorra/waterbending/IceSpikePillar.java b/src/com/projectkorra/projectkorra/waterbending/IceSpikePillar.java index 91d99c88..155d18ef 100644 --- a/src/com/projectkorra/projectkorra/waterbending/IceSpikePillar.java +++ b/src/com/projectkorra/projectkorra/waterbending/IceSpikePillar.java @@ -65,7 +65,10 @@ public class IceSpikePillar extends IceAbility { if (GeneralMethods.getDistanceFromLine(player.getLocation().getDirection(), player.getLocation(), entity.getLocation()) <= 2 && (entity instanceof LivingEntity) && (entity.getEntityId() != player.getEntityId())) { - double distance = player.getLocation().distance(entity.getLocation()); + double distance = 0; + if(player.getWorld().equals(entity.getWorld())) { + distance = player.getLocation().distance(entity.getLocation()); + } if (distance < lowestDistance) { closestEntity = entity; lowestDistance = distance; diff --git a/src/com/projectkorra/projectkorra/waterbending/PhaseChangeFreeze.java b/src/com/projectkorra/projectkorra/waterbending/PhaseChangeFreeze.java index b23606ab..310314b8 100644 --- a/src/com/projectkorra/projectkorra/waterbending/PhaseChangeFreeze.java +++ b/src/com/projectkorra/projectkorra/waterbending/PhaseChangeFreeze.java @@ -139,7 +139,7 @@ public class PhaseChangeFreeze extends IceAbility { } if (bPlayer.getBoundAbilityName().equalsIgnoreCase("OctopusForm")) { - if (block.getLocation().distance(player.getLocation()) <= REMOVE_RANGE + 2) { + if (block.getWorld().equals(player.getWorld()) && block.getLocation().distance(player.getLocation()) <= REMOVE_RANGE + 2) { return false; } } diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterArms.java b/src/com/projectkorra/projectkorra/waterbending/WaterArms.java index 56f5a015..b63b6d91 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterArms.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterArms.java @@ -361,7 +361,7 @@ public class WaterArms extends WaterAbility { for (Lightning.Arc arc : lightning.getArcs()) { for (Block arm : BLOCK_REVERT_TIMES.keySet()) { for (Location loc : arc.getPoints()) { - if (arm.getLocation().getWorld() == loc.getWorld() && loc.distance(arm.getLocation()) <= 2.5) { + if (arm.getLocation().getWorld().equals(loc.getWorld()) && loc.distance(arm.getLocation()) <= 2.5) { for (Location l1 : getOffsetLocations(4, arm.getLocation(), 1.25)) { FireAbility.playLightningbendingParticle(l1); } diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterArmsWhip.java b/src/com/projectkorra/projectkorra/waterbending/WaterArmsWhip.java index cea5c4fc..56c10b0b 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterArmsWhip.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterArmsWhip.java @@ -348,7 +348,11 @@ public class WaterArmsWhip extends WaterAbility { } Location newLocation = grabbedEntity.getLocation(); - double distance = location.distance(newLocation); + double distance = 0; + if(location.getWorld().equals(newLocation.getWorld())) { + distance = location.distance(newLocation); + } + double dx, dy, dz; dx = location.getX() - newLocation.getX(); dy = location.getY() - newLocation.getY(); diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java b/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java index 4d78d01d..b3318a5f 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java @@ -297,8 +297,8 @@ public class WaterSpout extends WaterAbility { Location base = spout.getBase().getLocation(); double dist = top.getBlockY() - base.getBlockY(); for (double d = 0; d <= dist; d += 0.5) { - Location spoutl = base.clone().add(0, d, 0); - if (loc0.distance(spoutl) <= radius) { + Location spoutLoc = base.clone().add(0, d, 0); + if (loc0.getWorld().equals(spoutLoc.getWorld()) && loc0.distance(spoutLoc) <= radius) { removed = true; spout.remove(); } diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java index f33f4544..af7698c2 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java @@ -285,7 +285,7 @@ public class WaterSpoutWave extends WaterAbility { } for (Block block : FROZEN_BLOCKS.keySet()) { TempBlock tBlock = FROZEN_BLOCKS.get(block); - if (tBlock.getLocation().distance(player.getLocation()) >= thawRadius) { + if (tBlock.getBlock().getWorld().equals(player.getWorld()) && tBlock.getLocation().distance(player.getLocation()) >= thawRadius) { tBlock.revertBlock(); FROZEN_BLOCKS.remove(block); }