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
This commit is contained in:
Christopher Martin 2016-10-14 21:32:15 -07:00 committed by GitHub
parent 9c00dd8c09
commit 3c41c611b9
26 changed files with 178 additions and 68 deletions

View file

@ -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));

View file

@ -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) {

View file

@ -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;

View file

@ -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;
}

View file

@ -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) {

View file

@ -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<Entity> ents = GeneralMethods.getEntitiesAroundPoint(targetLoc, constantAimRadius);

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -48,7 +48,10 @@ public class EarthTunnel extends EarthAbility {
this.origin = player.getTargetBlock((HashSet<Material>) 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)) {

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -626,7 +626,7 @@ public enum ParticleEffect {
*/
private static boolean isLongDistance(Location location, List<Player> 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;

View file

@ -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();

View file

@ -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<Integer, ItemStack> 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() {

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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();

View file

@ -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();
}

View file

@ -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);
}