From 89de7a3a366a61689bd3b97179889d74f5f21b1f Mon Sep 17 00:00:00 2001 From: Simp Date: Wed, 2 Jan 2019 21:34:00 -0500 Subject: [PATCH] Fixes --- .../projectkorra/GeneralMethods.java | 2 +- .../projectkorra/projectkorra/PKListener.java | 4 +- .../ability/ElementalAbility.java | 2 +- .../projectkorra/airbending/AirSuction.java | 331 ++++++++---------- .../airbending/util/AirbendingManager.java | 2 - .../projectkorra/earthbending/EarthBlast.java | 3 +- .../projectkorra/earthbending/EarthSmash.java | 2 +- .../projectkorra/firebending/HeatControl.java | 9 +- .../waterbending/ice/IceSpikeBlast.java | 4 +- 9 files changed, 163 insertions(+), 196 deletions(-) diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index ec0f784a..39516d14 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -1145,7 +1145,7 @@ public class GeneralMethods { } public static Location getTargetedLocation(final Player player, final double range, final Material... nonOpaque2) { - return getTargetedLocation(player, range, true, nonOpaque2); + return getTargetedLocation(player, range, false, nonOpaque2); } public static Location getTargetedLocation(final Player player, final int range) { diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index cbd89abc..7a262270 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -1357,7 +1357,7 @@ public class PKListener implements Listener { } else if (abil.equalsIgnoreCase("AirBurst")) { new AirBurst(player, false); } else if (abil.equalsIgnoreCase("AirSuction")) { - AirSuction.setOrigin(player); + new AirSuction(player); } else if (abil.equalsIgnoreCase("AirSwipe")) { new AirSwipe(player, true); } else if (abil.equalsIgnoreCase("AirShield")) { @@ -1561,7 +1561,7 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("AirBlast")) { new AirBlast(player); } else if (abil.equalsIgnoreCase("AirSuction")) { - new AirSuction(player); + AirSuction.shoot(player); } else if (abil.equalsIgnoreCase("AirBurst")) { AirBurst.coneBurst(player); } else if (abil.equalsIgnoreCase("AirScooter")) { diff --git a/src/com/projectkorra/projectkorra/ability/ElementalAbility.java b/src/com/projectkorra/projectkorra/ability/ElementalAbility.java index 47c3cc0b..841347fb 100644 --- a/src/com/projectkorra/projectkorra/ability/ElementalAbility.java +++ b/src/com/projectkorra/projectkorra/ability/ElementalAbility.java @@ -229,7 +229,7 @@ public abstract class ElementalAbility extends CoreAbility { } public static boolean isWater(final Material material) { - return material == Material.WATER || material == Material.SEAGRASS || material == Material.TALL_SEAGRASS || material == Material.KELP_PLANT || material == Material.KELP; + return material == Material.WATER || material == Material.SEAGRASS || material == Material.TALL_SEAGRASS || material == Material.KELP_PLANT || material == Material.KELP || material == Material.BUBBLE_COLUMN; } } diff --git a/src/com/projectkorra/projectkorra/airbending/AirSuction.java b/src/com/projectkorra/projectkorra/airbending/AirSuction.java index b5707469..1122db74 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSuction.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSuction.java @@ -1,14 +1,10 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.AirAbility; -import com.projectkorra.projectkorra.ability.util.Collision; -import com.projectkorra.projectkorra.attribute.Attribute; -import com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; -import com.projectkorra.projectkorra.waterbending.WaterSpout; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -20,17 +16,21 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.AirAbility; +import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; +import com.projectkorra.projectkorra.waterbending.WaterSpout; public class AirSuction extends AirAbility { - private static final int MAX_TICKS = 10000; - private static final Map ORIGINS = new ConcurrentHashMap<>(); private final List affectedDoors = new ArrayList<>(); - - private boolean hasOtherOrigin; - private int ticks; + + private boolean progressing; private int particleCount; @Attribute(Attribute.COOLDOWN) private long cooldown; @@ -57,9 +57,20 @@ public class AirSuction extends AirAbility { } else if (hasAbility(player, AirSpout.class) || hasAbility(player, WaterSpout.class)) { return; } + + if (hasAbility(player, AirSuction.class)) { + AirSuction suc = getAbility(player, AirSuction.class); + if (!suc.isProgressing()) { + Location loc = getTargetLocation(); + + if (!GeneralMethods.isRegionProtectedFromBuild(player, this.getName(), loc)) { + suc.setOrigin(loc); + } + } + return; + } - this.hasOtherOrigin = false; - this.ticks = 0; + this.progressing = false; this.particleCount = getConfig().getInt("Abilities.Air.AirSuction.Particles"); this.speed = getConfig().getDouble("Abilities.Air.AirSuction.Speed"); this.range = getConfig().getDouble("Abilities.Air.AirSuction.Range"); @@ -67,81 +78,21 @@ public class AirSuction extends AirAbility { this.pushFactor = getConfig().getDouble("Abilities.Air.AirSuction.Push"); this.cooldown = getConfig().getLong("Abilities.Air.AirSuction.Cooldown"); this.random = new Random(); - - if (ORIGINS.containsKey(player)) { - this.origin = ORIGINS.get(player); - this.hasOtherOrigin = true; - ORIGINS.remove(player); - } else { - this.origin = player.getEyeLocation(); + this.origin = getTargetLocation(); + + if (GeneralMethods.isRegionProtectedFromBuild(player, this.getName(), origin)) { + return; } - - this.location = GeneralMethods.getTargetedLocation(player, this.range, getTransparentMaterials()); - this.direction = GeneralMethods.getDirection(this.location, this.origin).normalize(); - final Entity entity = GeneralMethods.getTargetedEntity(player, this.range); - - if (entity != null) { - this.direction = GeneralMethods.getDirection(entity.getLocation(), this.origin).normalize(); - this.location = this.getLocation(this.origin, this.direction.clone().multiply(-1)); - } - - this.bPlayer.addCooldown(this); + + this.location = null; + if (this.bPlayer.isAvatarState()) { this.pushFactor = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirSuction.Push"); } + this.start(); } - private static void playOriginEffect(final Player player) { - if (!ORIGINS.containsKey(player)) { - return; - } - - final Location origin = ORIGINS.get(player); - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer == null || player.isDead() || !player.isOnline()) { - return; - } else if (!origin.getWorld().equals(player.getWorld())) { - ORIGINS.remove(player); - return; - } else if (!bPlayer.canBendIgnoreCooldowns(getAbility("AirSuction"))) { - ORIGINS.remove(player); - return; - } else if (origin.distanceSquared(player.getEyeLocation()) > getSelectRange() * getSelectRange()) { - ORIGINS.remove(player); - return; - } - - playAirbendingParticles(origin, getSelectParticles()); - } - - public static void progressOrigins() { - for (final Player player : ORIGINS.keySet()) { - playOriginEffect(player); - } - } - - public static void setOrigin(final Player player) { - final Material[] ignore = new Material[getTransparentMaterials().length + AirBlast.DOORS.length + AirBlast.TDOORS.length]; - for (int i = 0; i < ignore.length; i++) { - if (i < getTransparentMaterials().length) { - ignore[i] = getTransparentMaterials()[i]; - } else if (i < getTransparentMaterials().length + AirBlast.DOORS.length){ - ignore[i] = AirBlast.DOORS[i - getTransparentMaterials().length]; - } else { - ignore[i] = AirBlast.TDOORS[i - getTransparentMaterials().length - AirBlast.DOORS.length]; - } - } - final Location location = GeneralMethods.getTargetedLocation(player, getSelectRange(), false, ignore); - if (location.getBlock().isLiquid() || GeneralMethods.isSolid(location.getBlock())) { - return; - } else if (GeneralMethods.isRegionProtectedFromBuild(player, "AirSuction", location)) { - return; - } else { - ORIGINS.put(player, location); - } - } - private void advanceLocation() { playAirbendingParticles(this.location, this.particleCount, 0.275F, 0.275F, 0.275F); if (this.random.nextInt(4) == 0) { @@ -209,91 +160,131 @@ public class AirSuction extends AirAbility { this.affectedDoors.add(block); } - private Location getLocation(final Location origin, final Vector direction) { - Location location = origin.clone(); - for (double i = 1; i <= this.range; i++) { - location = origin.clone().add(direction.clone().multiply(i)); - if ((!this.isTransparent(location.getBlock()) && !(Arrays.asList(AirBlast.DOORS).contains(location.getBlock().getType()) && Arrays.asList(AirBlast.TDOORS).contains(location.getBlock().getType()))) || GeneralMethods.isRegionProtectedFromBuild(this, location)) { - return origin.clone().add(direction.clone().multiply(i - 1)); + private Location getTargetLocation() { + final Material[] ignore = new Material[getTransparentMaterials().length + AirBlast.DOORS.length + AirBlast.TDOORS.length]; + + for (int i = 0; i < ignore.length; i++) { + if (i < getTransparentMaterials().length) { + ignore[i] = getTransparentMaterials()[i]; + } else if (i < getTransparentMaterials().length + AirBlast.DOORS.length){ + ignore[i] = AirBlast.DOORS[i - getTransparentMaterials().length]; + } else { + ignore[i] = AirBlast.TDOORS[i - getTransparentMaterials().length - AirBlast.DOORS.length]; } } - return location; + + return GeneralMethods.getTargetedLocation(player, getSelectRange(), ignore); } @Override public void progress() { if (this.player.isDead() || !this.player.isOnline()) { - this.remove(); - return; - } else if (GeneralMethods.isRegionProtectedFromBuild(this.player, "AirSuction", this.location)) { - this.remove(); + this.remove(); return; } - this.ticks++; - if (this.ticks > MAX_TICKS) { - this.remove(); - return; - } else if ((this.location.distanceSquared(this.origin) > this.range * this.range) || (this.location.distanceSquared(this.origin) <= 1)) { - this.remove(); - return; - } - - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.radius)) { - if (entity.getEntityId() != this.player.getEntityId() || this.hasOtherOrigin) { - if (entity instanceof Player) { - if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || Commands.invincible.contains(((Player) entity).getName())){ - continue; - } - } - final Vector velocity = entity.getVelocity(); - final double max = this.speed; - double factor = this.pushFactor; - - final Vector push = this.direction.clone(); - if (Math.abs(push.getY()) > max && entity.getEntityId() != this.player.getEntityId()) { - if (push.getY() < 0) { - push.setY(-max); - } else { - push.setY(max); - } - } - if (this.location.getWorld().equals(this.origin.getWorld())) { - factor *= 1 - this.location.distance(this.origin) / (2 * this.range); - } - - final double comp = velocity.dot(push.clone().normalize()); - if (comp > factor) { - velocity.multiply(.5); - velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize()))); - } else if (comp + factor * .5 > factor) { - velocity.add(push.clone().multiply(factor - comp)); - } else { - velocity.add(push.clone().multiply(factor * .5)); - } - - if (entity instanceof Player) { - if (Commands.invincible.contains(((Player) entity).getName())) { - continue; - } - } - - GeneralMethods.setVelocity(entity, velocity); - new HorizontalVelocityTracker(entity, this.player, 200l, this); - entity.setFallDistance(0); - if (entity.getEntityId() != this.player.getEntityId() && entity instanceof Player) { - flightHandler.createInstance((Player) entity, this.player, 5000L, this.getName()); - } - - if (entity.getFireTicks() > 0) { - entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); - } - entity.setFireTicks(0); - breakBreathbendingHold(entity); + if (this.progressing) { + if (GeneralMethods.isRegionProtectedFromBuild(this.player, "AirSuction", this.location)) { + this.remove(); + return; + } else if (this.location.distanceSquared(this.origin) > this.range * this.range || this.location.distanceSquared(this.origin) <= 1) { + this.remove(); + return; } + + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.radius)) { + if (entity.getEntityId() != this.player.getEntityId()) { + if (entity instanceof Player) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || Commands.invincible.contains(((Player) entity).getName())){ + continue; + } + } + final Vector velocity = entity.getVelocity(); + final double max = this.speed; + final Vector push = this.direction.clone(); + double factor = this.pushFactor; + + if (Math.abs(push.getY()) > max && entity.getEntityId() != this.player.getEntityId()) { + if (push.getY() < 0) { + push.setY(-max); + } else { + push.setY(max); + } + } + + if (this.location.getWorld().equals(this.origin.getWorld())) { + factor *= 1 - this.location.distance(this.origin) / (2 * this.range); + } + + final double comp = velocity.dot(push.clone().normalize()); + if (comp > factor) { + velocity.multiply(.5); + velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize()))); + } else if (comp + factor * .5 > factor) { + velocity.add(push.clone().multiply(factor - comp)); + } else { + velocity.add(push.clone().multiply(factor * .5)); + } + + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { + continue; + } + } + + GeneralMethods.setVelocity(entity, velocity); + new HorizontalVelocityTracker(entity, this.player, 200l, this); + entity.setFallDistance(0); + if (entity.getEntityId() != this.player.getEntityId() && entity instanceof Player) { + flightHandler.createInstance((Player) entity, this.player, 5000L, this.getName()); + } + + if (entity.getFireTicks() > 0) { + entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); + } + entity.setFireTicks(0); + breakBreathbendingHold(entity); + } + } + + this.advanceLocation(); + } else { + playAirbendingParticles(origin, 5, 0.5, 0.5, 0.5); } + } + + public void shoot() { + Location target; + Entity entity = GeneralMethods.getTargetedEntity(player, this.range); - this.advanceLocation(); + if (entity != null) { + target = entity.getLocation(); + } else { + target = getTargetLocation(); + } + + this.location = target.clone(); + this.direction = GeneralMethods.getDirection(this.location, this.origin).normalize(); + this.progressing = true; + this.bPlayer.addCooldown(this); + } + + public static void shoot(Player player) { + AirSuction suc = null; + + if (CoreAbility.hasAbility(player, AirSuction.class)) { + suc = CoreAbility.getAbility(player, AirSuction.class); + if (suc.isProgressing()) { + return; + } + } else { + suc = new AirSuction(player); + suc.setOrigin(player.getEyeLocation().clone()); + } + + if (suc.getOrigin() != null) { + suc.shoot(); + } } /** @@ -344,6 +335,10 @@ public class AirSuction extends AirAbility { public double getCollisionRadius() { return this.getRadius(); } + + public boolean isProgressing() { + return progressing; + } public Location getOrigin() { return this.origin; @@ -361,22 +356,6 @@ public class AirSuction extends AirAbility { this.direction = direction; } - public boolean isHasOtherOrigin() { - return this.hasOtherOrigin; - } - - public void setHasOtherOrigin(final boolean hasOtherOrigin) { - this.hasOtherOrigin = hasOtherOrigin; - } - - public int getTicks() { - return this.ticks; - } - - public void setTicks(final int ticks) { - this.ticks = ticks; - } - public int getParticleCount() { return this.particleCount; } @@ -425,10 +404,6 @@ public class AirSuction extends AirAbility { this.cooldown = cooldown; } - public static Map getOrigins() { - return ORIGINS; - } - public static int getSelectParticles() { return getConfig().getInt("Abilities.Air.AirSuction.SelectParticles"); } diff --git a/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java b/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java index 28b23bf9..d7649e55 100644 --- a/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java +++ b/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java @@ -2,7 +2,6 @@ package com.projectkorra.projectkorra.airbending.util; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.airbending.AirBlast; -import com.projectkorra.projectkorra.airbending.AirSuction; public class AirbendingManager implements Runnable { @@ -15,7 +14,6 @@ public class AirbendingManager implements Runnable { @Override public void run() { AirBlast.progressOrigins(); - AirSuction.progressOrigins(); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java index 3aa8ef7d..89c9975d 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java @@ -145,7 +145,7 @@ public class EarthBlast extends EarthAbility { } if (target == null) { - location = GeneralMethods.getTargetedLocation(this.player, this.range, trans); + location = GeneralMethods.getTargetedLocation(this.player, this.range, true, trans); } else { location = ((LivingEntity) target).getEyeLocation(); } @@ -455,7 +455,6 @@ public class EarthBlast extends EarthAbility { if (mloc.distanceSquared(location) <= blast.range * blast.range && GeneralMethods.getDistanceFromLine(vector, location, blast.location) < blast.deflectRange && mloc.distanceSquared(location.clone().add(vector)) < mloc.distanceSquared(location.clone().add(vector.clone().multiply(-1)))) { blast.redirect(player, blast.getTargetLocation()); } - } } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index d726e088..4ae6864b 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -535,7 +535,7 @@ public class EarthSmash extends EarthAbility { return null; } - final List blocks = GeneralMethods.getBlocksAroundPoint(GeneralMethods.getTargetedLocation(player, this.grabRange, false, getTransparentMaterials()), 1); + final List blocks = GeneralMethods.getBlocksAroundPoint(GeneralMethods.getTargetedLocation(player, this.grabRange, getTransparentMaterials()), 1); for (final EarthSmash smash : getAbilities(EarthSmash.class)) { if (reqState == null || smash.state == reqState) { for (final Block block : blocks) { diff --git a/src/com/projectkorra/projectkorra/firebending/HeatControl.java b/src/com/projectkorra/projectkorra/firebending/HeatControl.java index 56ce81f1..2c76d160 100644 --- a/src/com/projectkorra/projectkorra/firebending/HeatControl.java +++ b/src/com/projectkorra/projectkorra/firebending/HeatControl.java @@ -28,7 +28,6 @@ import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.earthbending.lava.LavaFlow; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ReflectionHandler.PackageType; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.SurgeWave; import com.projectkorra.projectkorra.waterbending.Torrent; @@ -221,7 +220,7 @@ public class HeatControl extends FireAbility { final Location targetLocation = GeneralMethods.getTargetedLocation(this.player, this.solidifyRange); this.resetLocation(targetLocation); - final List area = GeneralMethods.getCircle(this.solidifyLocation, this.solidifyRadius, 3, true, true, 0); + final List area = GeneralMethods.getCircle(this.solidifyLocation, this.solidifyRadius, 3, false, true, 0); this.solidify(area); } @@ -363,11 +362,7 @@ public class HeatControl extends FireAbility { final Block b = lava.get(this.randy.nextInt(lava.size())); - Material tempRevertMaterial = Material.STONE; - - if (Integer.parseInt(PackageType.getServerVersion().split("_")[1]) > 9) { - tempRevertMaterial = Material.valueOf("MAGMA"); - } + Material tempRevertMaterial = Material.MAGMA_BLOCK; final TempBlock tempBlock; if (TempBlock.isTempBlock(b)) { diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java index 01c96883..10b50d9d 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java @@ -255,7 +255,7 @@ public class IceSpikeBlast extends IceAbility { final LivingEntity target = (LivingEntity) GeneralMethods.getTargetedEntity(this.player, this.range); if (target == null) { - this.destination = GeneralMethods.getTargetedLocation(this.player, this.range, getTransparentMaterials()); + this.destination = GeneralMethods.getTargetedLocation(this.player, this.range, true, getTransparentMaterials()); } else { this.destination = target.getEyeLocation(); } @@ -376,7 +376,7 @@ public class IceSpikeBlast extends IceAbility { Location loc; final Entity target = GeneralMethods.getTargetedEntity(player, iceSpike.range); if (target == null) { - loc = GeneralMethods.getTargetedLocation(player, iceSpike.range); + loc = GeneralMethods.getTargetedLocation(player, iceSpike.range, true); } else { loc = ((LivingEntity) target).getEyeLocation(); }