diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index 6073360a..b82cc9d0 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -112,6 +112,7 @@ import com.projectkorra.projectkorra.airbending.AirSwipe; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.earthbending.EarthBlast; import com.projectkorra.projectkorra.earthbending.passive.EarthPassive; +import com.projectkorra.projectkorra.event.AbilityVelocityAffectEntityEvent; import com.projectkorra.projectkorra.event.BendingPlayerCreationEvent; import com.projectkorra.projectkorra.event.BendingReloadEvent; import com.projectkorra.projectkorra.event.PlayerBindChangeEvent; @@ -2314,39 +2315,6 @@ public class GeneralMethods { DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = '" + (permaRemoved ? "true" : "false") + "' WHERE uuid = '" + uuid + "'"); } - public static void setVelocity(final Entity entity, final Vector velocity) { - if (entity instanceof TNTPrimed) { - if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingAffectFallingSand.TNT")) { - velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.TNTStrengthMultiplier")); - } - } else if (entity instanceof FallingBlock) { - if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingAffectFallingSand.Normal")) { - velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.NormalStrengthMultiplier")); - } - } - - // Attempt to stop velocity from going over the packet cap. - if (velocity.getX() > 4) { - velocity.setX(4); - } else if (velocity.getX() < -4) { - velocity.setX(-4); - } - - if (velocity.getY() > 4) { - velocity.setY(4); - } else if (velocity.getY() < -4) { - velocity.setY(-4); - } - - if (velocity.getZ() > 4) { - velocity.setZ(4); - } else if (velocity.getZ() < -4) { - velocity.setZ(-4); - } - - entity.setVelocity(velocity); - } - public static FallingBlock spawnFallingBlock(final Location loc, final Material type) { return spawnFallingBlock(loc, type, type.createBlockData()); } @@ -2532,4 +2500,51 @@ public class GeneralMethods { return false; } } + + @Deprecated + public static void setVelocity(Entity entity, Vector vector) { + setVelocity(null,entity,vector); + } + + public static void setVelocity(Ability ability, Entity entity, Vector vector) { + final AbilityVelocityAffectEntityEvent event = new AbilityVelocityAffectEntityEvent(ability, entity, vector); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + + Vector velocity = event.getVelocity(); + if(velocity == null || Double.isNaN(velocity.length())) + return; + + if (entity instanceof TNTPrimed) { + if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingAffectFallingSand.TNT")) { + velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.TNTStrengthMultiplier")); + } + } else if (entity instanceof FallingBlock) { + if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingAffectFallingSand.Normal")) { + velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.NormalStrengthMultiplier")); + } + } + + // Attempt to stop velocity from going over the packet cap. + if (velocity.getX() > 4) { + velocity.setX(4); + } else if (velocity.getX() < -4) { + velocity.setX(-4); + } + + if (velocity.getY() > 4) { + velocity.setY(4); + } else if (velocity.getY() < -4) { + velocity.setY(-4); + } + + if (velocity.getZ() > 4) { + velocity.setZ(4); + } else if (velocity.getZ() < -4) { + velocity.setZ(-4); + } + + event.getAffected().setVelocity(velocity); + } } diff --git a/src/com/projectkorra/projectkorra/ability/EarthAbility.java b/src/com/projectkorra/projectkorra/ability/EarthAbility.java index 200bc1c2..d5c81ee5 100644 --- a/src/com/projectkorra/projectkorra/ability/EarthAbility.java +++ b/src/com/projectkorra/projectkorra/ability/EarthAbility.java @@ -170,13 +170,14 @@ public abstract class EarthAbility extends ElementalAbility { final LivingEntity lentity = (LivingEntity) entity; if (lentity.getEyeLocation().getBlockX() == affectedblock.getX() && lentity.getEyeLocation().getBlockZ() == affectedblock.getZ()) { if (!(entity instanceof FallingBlock)) { - entity.setVelocity(norm.clone().multiply(.75)); + GeneralMethods.setVelocity(this, entity, norm.clone().multiply(.75)); + } } } else { if (entity.getLocation().getBlockX() == affectedblock.getX() && entity.getLocation().getBlockZ() == affectedblock.getZ()) { if (!(entity instanceof FallingBlock)) { - entity.setVelocity(norm.clone().multiply(.75)); + GeneralMethods.setVelocity(this, entity, norm.clone().multiply(.75)); } } } diff --git a/src/com/projectkorra/projectkorra/airbending/AirBlast.java b/src/com/projectkorra/projectkorra/airbending/AirBlast.java index 7ff93428..554b57ab 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBlast.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBlast.java @@ -280,8 +280,7 @@ public class AirBlast extends AirAbility { if (Math.abs(entity.getVelocity().dot(push)) > knockback && entity.getVelocity().angle(push) > Math.PI / 3) { push.normalize().add(entity.getVelocity()).multiply(knockback); } - - GeneralMethods.setVelocity(entity, push); + GeneralMethods.setVelocity(this, entity, push); if (this.source != null) { new HorizontalVelocityTracker(entity, this.player, 200l, this.source); diff --git a/src/com/projectkorra/projectkorra/airbending/AirScooter.java b/src/com/projectkorra/projectkorra/airbending/AirScooter.java index d4059ab2..22a8728b 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirScooter.java +++ b/src/com/projectkorra/projectkorra/airbending/AirScooter.java @@ -201,9 +201,9 @@ public class AirScooter extends AirAbility { this.player.setSprinting(false); this.player.removePotionEffect(PotionEffectType.SPEED); if (this.useslime) { - this.slime.setVelocity(velocity); + GeneralMethods.setVelocity(this, this.slime, velocity); } else { - this.player.setVelocity(velocity); + GeneralMethods.setVelocity(this, this.player, velocity); } if (this.random.nextInt(4) == 0) { diff --git a/src/com/projectkorra/projectkorra/airbending/AirShield.java b/src/com/projectkorra/projectkorra/airbending/AirShield.java index 97ec55db..19d90ae3 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirShield.java +++ b/src/com/projectkorra/projectkorra/airbending/AirShield.java @@ -162,7 +162,7 @@ public class AirShield extends AirAbility { } velocity.multiply(0.5); - GeneralMethods.setVelocity(entity, velocity); + GeneralMethods.setVelocity(this, entity, velocity); entity.setFallDistance(0); } } diff --git a/src/com/projectkorra/projectkorra/airbending/AirSuction.java b/src/com/projectkorra/projectkorra/airbending/AirSuction.java index 802b68a0..2fe3bd48 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSuction.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSuction.java @@ -231,8 +231,8 @@ public class AirSuction extends AirAbility { if (Math.abs(entity.getVelocity().dot(push)) > knockback) { push.normalize().add(entity.getVelocity()).multiply(knockback); } - - GeneralMethods.setVelocity(entity, push.normalize().multiply(knockback)); + GeneralMethods.setVelocity(this, entity, push.normalize().multiply(knockback)); + new HorizontalVelocityTracker(entity, this.player, 200l, this); entity.setFallDistance(0); diff --git a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java index 759bee6a..0800dd53 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java @@ -243,9 +243,7 @@ public class AirSwipe extends AirAbility { } } if (entities.size() < MAX_AFFECTABLE_ENTITIES) { - - GeneralMethods.setVelocity(entity, fDirection.multiply(AirSwipe.this.pushFactor)); - + GeneralMethods.setVelocity(AirSwipe.this, entity, fDirection.multiply(AirSwipe.this.pushFactor)); } if (!AirSwipe.this.affectedEntities.contains(entity)) { if (AirSwipe.this.damage != 0) { @@ -255,9 +253,7 @@ public class AirSwipe extends AirAbility { } breakBreathbendingHold(entity); } else if (entity.getEntityId() != AirSwipe.this.player.getEntityId() && !(entity instanceof LivingEntity)) { - - GeneralMethods.setVelocity(entity, fDirection.multiply(AirSwipe.this.pushFactor)); - + GeneralMethods.setVelocity(AirSwipe.this, entity, fDirection.multiply(AirSwipe.this.pushFactor)); } } }.runTaskLater(ProjectKorra.plugin, i / MAX_AFFECTABLE_ENTITIES); diff --git a/src/com/projectkorra/projectkorra/airbending/Tornado.java b/src/com/projectkorra/projectkorra/airbending/Tornado.java index fc41a7a5..ad540e95 100644 --- a/src/com/projectkorra/projectkorra/airbending/Tornado.java +++ b/src/com/projectkorra/projectkorra/airbending/Tornado.java @@ -169,7 +169,7 @@ public class Tornado extends AirAbility { velocity.setZ(vz); velocity.setY(vy); velocity.multiply(timefactor); - GeneralMethods.setVelocity(entity, velocity); + GeneralMethods.setVelocity(this, entity, velocity); entity.setFallDistance(0); breakBreathbendingHold(entity); diff --git a/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java b/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java index 02678172..3cb54ab5 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java @@ -165,7 +165,7 @@ public class AirStream extends AirAbility implements ComboAbility { continue; } final Vector force = GeneralMethods.getDirection(entity.getLocation(), this.currentLoc); - entity.setVelocity(force.clone().normalize().multiply(this.speed)); + GeneralMethods.setVelocity(this, entity, force.clone().normalize().multiply(this.speed)); entity.setFallDistance(0F); } } diff --git a/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java b/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java index 0dd9f398..6e99c085 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java @@ -198,7 +198,7 @@ public class AirSweep extends AirAbility implements ComboAbility { if (!entity.equals(this.player) && !(entity instanceof Player && Commands.invincible.contains(((Player) entity).getName()))) { if (this.knockback != 0) { final Vector force = fstream.getLocation().getDirection(); - GeneralMethods.setVelocity(entity, force.clone().multiply(this.knockback)); + GeneralMethods.setVelocity(this, entity, force.clone().multiply(this.knockback)); new HorizontalVelocityTracker(entity, this.player, 200l, this); entity.setFallDistance(0); } diff --git a/src/com/projectkorra/projectkorra/airbending/combo/Twister.java b/src/com/projectkorra/projectkorra/airbending/combo/Twister.java index 9c18fe6f..b85d4278 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/Twister.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/Twister.java @@ -146,7 +146,7 @@ public class Twister extends AirAbility implements ComboAbility { continue; } final Vector forceDir = GeneralMethods.getDirection(entity.getLocation(), this.currentLoc.clone().add(0, height, 0)); - entity.setVelocity(forceDir.clone().normalize().multiply(0.3)); + GeneralMethods.setVelocity(this, entity, forceDir.clone().normalize().multiply(0.3)); } } diff --git a/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java b/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java index ac696629..5f656db6 100644 --- a/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java +++ b/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java @@ -227,14 +227,14 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { if (!GeneralMethods.isRegionProtectedFromBuild(this.player, e.getLocation())) { final LivingEntity le = (LivingEntity) e; DamageHandler.damageEntity(le, this.speed / 2, this); - le.setVelocity(this.player.getVelocity().clone().multiply(2 / 3)); + GeneralMethods.setVelocity(this, le, this.player.getVelocity().clone().multiply(2 / 3)); } } } } this.particles(); - this.player.setVelocity(this.player.getEyeLocation().getDirection().clone().multiply(this.multiplier)); + GeneralMethods.setVelocity(this, this.player, this.player.getEyeLocation().getDirection().clone().multiply(this.multiplier)); } else if (this.mode == FlightMode.GLIDE) { this.player.setAllowFlight(false); this.player.setFlying(false); diff --git a/src/com/projectkorra/projectkorra/chiblocking/HighJump.java b/src/com/projectkorra/projectkorra/chiblocking/HighJump.java index d4992cf1..6f5d5cd2 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/HighJump.java +++ b/src/com/projectkorra/projectkorra/chiblocking/HighJump.java @@ -35,7 +35,7 @@ public class HighJump extends ChiAbility { } final Vector vec = p.getVelocity(); vec.setY(this.height); - p.setVelocity(vec); + GeneralMethods.setVelocity(this, p, vec); this.bPlayer.addCooldown(this); return; } diff --git a/src/com/projectkorra/projectkorra/earthbending/Catapult.java b/src/com/projectkorra/projectkorra/earthbending/Catapult.java index 78bfe6bd..38e3da8e 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Catapult.java +++ b/src/com/projectkorra/projectkorra/earthbending/Catapult.java @@ -73,7 +73,7 @@ public class Catapult extends EarthAbility { if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { continue; } - entity.setVelocity(apply); + GeneralMethods.setVelocity(this, entity, apply); } } this.moveEarth(this.origin.clone().subtract(direction), direction, 3, false); @@ -135,7 +135,7 @@ public class Catapult extends EarthAbility { final Location tar = this.origin.clone().add(direction.clone().normalize().multiply(this.stage + 0.5)); this.target = tar; final Vector apply = this.target.clone().toVector().subtract(this.origin.clone().toVector()); - this.player.setVelocity(apply); + GeneralMethods.setVelocity(this, this.player, apply); this.moveEarth(apply, direction); this.remove(); } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java index 6157139e..748eaf9a 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java @@ -276,7 +276,7 @@ public class EarthBlast extends EarthAbility { final Location location = this.player.getEyeLocation(); final Vector vector = location.getDirection(); - entity.setVelocity(vector.normalize().multiply(this.pushFactor)); + GeneralMethods.setVelocity(this, entity, vector.normalize().multiply(this.pushFactor)); double damage = this.damage; if (isMetal(this.sourceBlock) && this.bPlayer.canMetalbend()) { diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java b/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java index 6a861982..cd7c27f4 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java @@ -320,7 +320,7 @@ public class EarthGrab extends EarthAbility { continue; } final Block b = entity.getLocation().getBlock().getRelative(BlockFace.DOWN); - entity.setVelocity(GeneralMethods.getDirection(entity.getLocation(), this.player.getLocation()).normalize().multiply(this.dragSpeed)); + GeneralMethods.setVelocity(this, entity, GeneralMethods.getDirection(entity.getLocation(), this.player.getLocation()).normalize().multiply(this.dragSpeed)); ParticleEffect.BLOCK_CRACK.display(entity.getLocation(), 2, 0, 0, 0, b.getBlockData()); playEarthbendingSound(entity.getLocation()); } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index e71a0d9e..e4ea0196 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -293,7 +293,7 @@ public class EarthSmash extends EarthAbility { if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { continue; } - entity.setVelocity(direction.clone().multiply(this.flightSpeed)); + GeneralMethods.setVelocity(this, entity, direction.clone().multiply(this.flightSpeed)); } // These values tend to work well when dealing with a person aiming upward or downward. @@ -398,7 +398,7 @@ public class EarthSmash extends EarthAbility { final List entities = GeneralMethods.getEntitiesAroundPoint(this.location, 2.5); for (final Entity entity : entities) { final org.bukkit.util.Vector velocity = entity.getVelocity(); - entity.setVelocity(velocity.add(new Vector(0, 0.36, 0))); + GeneralMethods.setVelocity(this, entity, velocity.add(new Vector(0, 0.36, 0))); } this.location.getWorld().playEffect(this.location, Effect.GHAST_SHOOT, 0, 7); this.draw(); @@ -573,7 +573,7 @@ public class EarthSmash extends EarthAbility { final double damage = this.currentBlocks.size() / 13.0 * this.damage; DamageHandler.damageEntity(entity, damage, this); final Vector travelVec = GeneralMethods.getDirection(this.location, entity.getLocation()); - entity.setVelocity(travelVec.setY(this.knockup).normalize().multiply(this.knockback)); + GeneralMethods.setVelocity(this, entity, travelVec.setY(this.knockup).normalize().multiply(this.knockback)); } } } diff --git a/src/com/projectkorra/projectkorra/earthbending/Ripple.java b/src/com/projectkorra/projectkorra/earthbending/Ripple.java index 25fc4bb2..74c33920 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Ripple.java +++ b/src/com/projectkorra/projectkorra/earthbending/Ripple.java @@ -285,7 +285,7 @@ public class Ripple extends EarthAbility { final Vector vector = this.direction.clone(); vector.setY(.5); final double knock = this.bPlayer.isAvatarState() ? AvatarState.getValue(this.knockback) : this.knockback; - entity.setVelocity(vector.clone().normalize().multiply(knock)); + GeneralMethods.setVelocity(this, entity, vector.clone().normalize().multiply(knock)); AirAbility.breakBreathbendingHold(entity); } diff --git a/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java b/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java index 611c63f4..406fdbad 100644 --- a/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java +++ b/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java @@ -100,8 +100,7 @@ public class EarthPillars extends EarthAbility implements ComboAbility { if (lent instanceof Player && !((Player) lent).isOnline()) { continue; } - - lent.setVelocity(new Vector(0, this.knockup, 0)); + GeneralMethods.setVelocity(this, lent, new Vector(0, this.knockup, 0)); } if (this.damaging) { DamageHandler.damageEntity(lent, this.damage, this); diff --git a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java index 8d969430..81ada408 100644 --- a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java +++ b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java @@ -236,7 +236,7 @@ public class LavaSurge extends LavaAbility { x = (this.random.nextBoolean()) ? -x : x; z = (this.random.nextBoolean()) ? -z : z; - fbs.setVelocity(this.direction.clone().add(new Vector(x, 0.2, z)).multiply(1.2)); + GeneralMethods.setVelocity(this, fbs, this.direction.clone().add(new Vector(x, 0.2, z)).multiply(1.2)); fbs.setDropItem(false); for (final Block b : this.fracture) { @@ -244,7 +244,7 @@ public class LavaSurge extends LavaAbility { final FallingBlock fb = GeneralMethods.spawnFallingBlock(b.getLocation().add(new Vector(0, 1, 0)), Material.MAGMA_BLOCK, Material.MAGMA_BLOCK.createBlockData()); ALL_FALLING_BLOCKS.add(fb); this.fallingBlocks.add(fb); - fb.setVelocity(this.direction.clone().add(new Vector(this.random.nextDouble() / 10, 0.1, this.random.nextDouble() / 10)).multiply(1.2)); + GeneralMethods.setVelocity(this, fb, this.direction.clone().add(new Vector(this.random.nextDouble() / 10, 0.1, this.random.nextDouble() / 10)).multiply(1.2)); fb.setDropItem(false); } } @@ -258,7 +258,7 @@ public class LavaSurge extends LavaAbility { if (e.getEntityId() != this.player.getEntityId()) { DamageHandler.damageEntity(e, this.impactDamage, this); e.setFireTicks(100); - GeneralMethods.setVelocity(e, this.direction.clone()); + GeneralMethods.setVelocity(this, e, this.direction.clone()); } } } diff --git a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java index 082aef15..dc01e60b 100644 --- a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java +++ b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java @@ -207,7 +207,7 @@ public class LavaSurgeWave extends LavaAbility { if (knockback) { final Vector dir = direction.clone(); dir.setY(dir.getY() * this.verticalPush); - entity.setVelocity(entity.getVelocity().clone().add(dir.clone().multiply(this.horizontalPush))); + GeneralMethods.setVelocity(this, entity, entity.getVelocity().clone().add(dir.clone().multiply(this.horizontalPush))); entity.setFallDistance(0); if (entity.getFireTicks() > 0) { diff --git a/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java b/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java index 3dde48e6..a06443fc 100644 --- a/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java +++ b/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java @@ -156,7 +156,7 @@ public class MetalClips extends MetalAbility { vector = GeneralMethods.getDirection(this.player.getLocation(), GeneralMethods.getTargetedLocation(this.player, this.range)); } - item.setVelocity(vector.normalize().add(new Vector(0, 0.1, 0).multiply(1.2))); + GeneralMethods.setVelocity(this, item, vector.normalize().add(new Vector(0, 0.1, 0).multiply(1.2))); this.trackedIngots.add(item); this.player.getInventory().removeItem(is); } @@ -228,7 +228,7 @@ public class MetalClips extends MetalAbility { dz = target.getZ() - location.getZ(); final Vector vector = new Vector(dx, dy, dz); vector.normalize(); - this.targetEntity.setVelocity(vector.multiply(this.metalClipsCount / 2D)); + GeneralMethods.setVelocity(this, this.targetEntity, vector.multiply(this.metalClipsCount / 2D)); this.remove(); } @@ -342,7 +342,7 @@ public class MetalClips extends MetalAbility { final Item iron = (Item) entity; if (Arrays.asList(METAL_ITEMS).contains(iron.getItemStack().getType())) { - iron.setVelocity(vector.normalize().multiply(this.magnetSpeed).add(new Vector(0, 0.2, 0))); + GeneralMethods.setVelocity(this, iron, vector.normalize().multiply(this.magnetSpeed).add(new Vector(0, 0.2, 0))); } } } @@ -367,7 +367,7 @@ public class MetalClips extends MetalAbility { final Vector vector = GeneralMethods.getDirection(this.targetEntity.getLocation(), this.player.getLocation()); if (distance > 0.5) { - this.targetEntity.setVelocity(vector.normalize().multiply(0.2)); + GeneralMethods.setVelocity(this, this.targetEntity, vector.normalize().multiply(0.2)); } } @@ -384,7 +384,7 @@ public class MetalClips extends MetalAbility { final Vector vector = GeneralMethods.getDirection(this.targetEntity.getLocation(), GeneralMethods.getTargetedLocation(this.player, 10)); if (distance > 1.2) { - this.targetEntity.setVelocity(vector.normalize().multiply(0.2)); + GeneralMethods.setVelocity(this, this.targetEntity, vector.normalize().multiply(0.2)); } } @@ -401,9 +401,9 @@ public class MetalClips extends MetalAbility { final Vector vector = GeneralMethods.getDirection(oldLocation, GeneralMethods.getTargetedLocation(this.player, 10)); if (distance > 1.2) { - this.targetEntity.setVelocity(vector.normalize().multiply(.5)); + GeneralMethods.setVelocity(this, this.targetEntity, vector.normalize().multiply(.5)); } else { - this.targetEntity.setVelocity(new Vector(0, 0, 0)); + GeneralMethods.setVelocity(this, this.targetEntity, new Vector(0, 0, 0)); } this.targetEntity.setFallDistance(0); diff --git a/src/com/projectkorra/projectkorra/event/AbilityVelocityAffectEntityEvent.java b/src/com/projectkorra/projectkorra/event/AbilityVelocityAffectEntityEvent.java new file mode 100644 index 00000000..e2cf2efd --- /dev/null +++ b/src/com/projectkorra/projectkorra/event/AbilityVelocityAffectEntityEvent.java @@ -0,0 +1,75 @@ +package com.projectkorra.projectkorra.event; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.util.Vector; + +import com.projectkorra.projectkorra.ability.Ability; + +/** + * Cancellable event called when an ability would push or alter the velocity of + * an entity. + * + * the entity can be changed, vector can be modified, and the ability that + * caused the change can be accessed. + * + * @author dNiym + * + */ + +public class AbilityVelocityAffectEntityEvent extends Event implements Cancellable { + + Entity affected; + Vector velocity; + Ability ability; + boolean cancelled = false; + + private static final HandlerList handlers = new HandlerList(); + + public AbilityVelocityAffectEntityEvent(Ability ability, Entity entity, Vector vector) { + this.affected = entity; + this.ability = ability; + this.velocity = vector; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public Entity getAffected() { + return affected; + } + + public void setAffected(Entity affected) { + this.affected = affected; + } + + public Vector getVelocity() { + return velocity; + } + + public void setVelocity(Vector velocity) { + this.velocity = velocity; + } + + public Ability getAbility() { + return ability; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlast.java b/src/com/projectkorra/projectkorra/firebending/FireBlast.java index c3ea453b..c5807e6d 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlast.java @@ -199,9 +199,9 @@ public class FireBlast extends FireAbility { private void affect(final Entity entity) { if (entity.getUniqueId() != this.player.getUniqueId() && !GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) && !((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { if (this.bPlayer.isAvatarState()) { - GeneralMethods.setVelocity(entity, this.direction.clone().multiply(AvatarState.getValue(this.knockback))); + GeneralMethods.setVelocity(this, entity, this.direction.clone().multiply(AvatarState.getValue(this.knockback))); } else { - GeneralMethods.setVelocity(entity, this.direction.clone().multiply(this.knockback)); + GeneralMethods.setVelocity(this, entity, this.direction.clone().multiply(this.knockback)); } if (entity instanceof LivingEntity) { entity.setFireTicks((int) (this.fireTicks * 20)); diff --git a/src/com/projectkorra/projectkorra/firebending/FireJet.java b/src/com/projectkorra/projectkorra/firebending/FireJet.java index 8c382942..ded60a23 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireJet.java +++ b/src/com/projectkorra/projectkorra/firebending/FireJet.java @@ -10,6 +10,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.airbending.AirSpout; @@ -57,7 +58,7 @@ public class FireJet extends FireAbility { final Block block = player.getLocation().getBlock(); if (isIgnitable(block) || ElementalAbility.isAir(block.getType()) || block.getType() == Material.STONE_SLAB || block.getType() == Material.ACACIA_SLAB || block.getType() == Material.BIRCH_SLAB || block.getType() == Material.DARK_OAK_SLAB || block.getType() == Material.JUNGLE_SLAB || block.getType() == Material.OAK_SLAB || block.getType() == Material.SPRUCE_SLAB || isIlluminationTorch(block) || this.bPlayer.isAvatarState()) { - player.setVelocity(player.getEyeLocation().getDirection().clone().normalize().multiply(this.speed)); + GeneralMethods.setVelocity(this, player, player.getEyeLocation().getDirection().clone().normalize().multiply(this.speed)); if (!canFireGrief()) { if (ElementalAbility.isAir(block.getType())) { createTempFire(block.getLocation()); @@ -102,7 +103,7 @@ public class FireJet extends FireAbility { } final Vector velocity = this.player.getEyeLocation().getDirection().clone().normalize().multiply(this.speed * timefactor); - this.player.setVelocity(velocity); + GeneralMethods.setVelocity(this, this.player, velocity); this.player.setFallDistance(0); } } diff --git a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java index a45bb920..9782da1b 100644 --- a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java +++ b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java @@ -121,7 +121,7 @@ public class WallOfFire extends FireAbility { } private void affect(final Entity entity) { - GeneralMethods.setVelocity(entity, new Vector(0, 0, 0)); + GeneralMethods.setVelocity(this, entity, new Vector(0, 0, 0)); if (entity instanceof LivingEntity) { final Block block = ((LivingEntity) entity).getEyeLocation().getBlock(); if (TempBlock.isTempBlock(block) && isIce(block)) { diff --git a/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java b/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java index de0a9917..787ab5d0 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java @@ -136,7 +136,7 @@ public class FireComboStream extends BukkitRunnable { fireSpin.getAffectedEntities().add(entity); final double newKnockback = this.bPlayer.isAvatarState() ? this.knockback + 0.5 : this.knockback; DamageHandler.damageEntity(entity, this.damage, coreAbility); - entity.setVelocity(direction.normalize().multiply(newKnockback)); + GeneralMethods.setVelocity(coreAbility, entity, direction.normalize().multiply(newKnockback)); } } else if (coreAbility.getName().equalsIgnoreCase("JetBlaze")) { final JetBlaze jetBlaze = CoreAbility.getAbility(this.player, JetBlaze.class); diff --git a/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java b/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java index 6ddbac66..883154b8 100644 --- a/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java +++ b/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java @@ -207,7 +207,7 @@ public class OctopusForm extends WaterAbility { } final double knock = this.bPlayer.isAvatarState() ? AvatarState.getValue(this.knockback) : this.knockback; - entity.setVelocity(GeneralMethods.getDirection(this.player.getLocation(), location).normalize().multiply(knock)); + GeneralMethods.setVelocity(this, entity, GeneralMethods.getDirection(this.player.getLocation(), location).normalize().multiply(knock)); if (entity instanceof LivingEntity) { DamageHandler.damageEntity(entity, this.damage, this); diff --git a/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java b/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java index 08f181a0..fdf5f571 100644 --- a/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java @@ -377,7 +377,7 @@ public class SurgeWave extends WaterAbility { } final Vector dir = direction.clone(); dir.setY(dir.getY() * this.knockup); - GeneralMethods.setVelocity(entity, entity.getVelocity().clone().add(dir.clone().multiply(this.getNightFactor(this.knockback)))); + GeneralMethods.setVelocity(this, entity, entity.getVelocity().clone().add(dir.clone().multiply(this.getNightFactor(this.knockback)))); entity.setFallDistance(0); if (entity.getFireTicks() > 0) { diff --git a/src/com/projectkorra/projectkorra/waterbending/Torrent.java b/src/com/projectkorra/projectkorra/waterbending/Torrent.java index c93e3e83..c9d14e4f 100644 --- a/src/com/projectkorra/projectkorra/waterbending/Torrent.java +++ b/src/com/projectkorra/projectkorra/waterbending/Torrent.java @@ -591,7 +591,7 @@ public class Torrent extends WaterAbility { velocity.setZ(vec.getY()); } - GeneralMethods.setVelocity(entity, velocity); + GeneralMethods.setVelocity(this, entity, velocity); entity.setFallDistance(0); if (entity instanceof LivingEntity) { final double damageDealt = this.getNightFactor(this.deflectDamage); @@ -611,7 +611,7 @@ public class Torrent extends WaterAbility { direction.setY(this.knockup); } if (!this.freeze) { - entity.setVelocity(direction.multiply(this.knockback)); + GeneralMethods.setVelocity(this, entity, direction.multiply(this.knockback)); } if (entity instanceof LivingEntity && !this.hurtEntities.contains(entity)) { double damageDealt = this.getNightFactor(this.damage); diff --git a/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java b/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java index 664f7a50..e1c55e09 100644 --- a/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java @@ -180,7 +180,7 @@ public class TorrentWave extends WaterAbility { final Vector direction = GeneralMethods.getDirection(this.origin, entity.getLocation()); direction.setY(0); direction.normalize(); - entity.setVelocity(entity.getVelocity().clone().add(direction.multiply(this.knockback))); + GeneralMethods.setVelocity(this, entity, entity.getVelocity().clone().add(direction.multiply(this.knockback))); } @Override diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java index 2b067176..8117ebbd 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java @@ -283,7 +283,7 @@ public class WaterManipulation extends WaterAbility { } final Location location = this.player.getEyeLocation(); final Vector vector = location.getDirection(); - entity.setVelocity(vector.normalize().multiply(this.knockback)); + GeneralMethods.setVelocity(this, entity, vector.normalize().multiply(this.knockback)); if (this.bPlayer.isAvatarState()) { this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.WaterManipulation.Damage"); diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java index e997ce09..49befa99 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java @@ -299,8 +299,7 @@ public class WaterSpoutWave extends WaterAbility { if (this.bPlayer.isAvatarState()) { currentSpeed = this.getNightFactor(this.speed); } - - this.player.setVelocity(this.player.getEyeLocation().getDirection().normalize().multiply(currentSpeed)); + GeneralMethods.setVelocity(this, this.player, this.player.getEyeLocation().getDirection().normalize().multiply(currentSpeed)); for (final Block block : GeneralMethods.getBlocksAroundPoint(this.player.getLocation().add(0, -1, 0), this.waveRadius)) { if (ElementalAbility.isAir(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { if (this.iceWave) { diff --git a/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java b/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java index fc203eec..dcf503f2 100644 --- a/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java +++ b/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java @@ -153,7 +153,7 @@ public class Bloodbending extends BloodAbility { vector = GeneralMethods.getDirection(location, GeneralMethods.getTargetedLocation(this.player, location.distance(target))); } vector.normalize(); - entity.setVelocity(vector.multiply(this.knockback)); + GeneralMethods.setVelocity(this, entity, vector.multiply(this.knockback)); new HorizontalVelocityTracker(entity, this.player, 200, this); } this.remove(); @@ -220,7 +220,7 @@ public class Bloodbending extends BloodAbility { continue; } if (entity instanceof LivingEntity) { - entity.setVelocity(this.vector); + GeneralMethods.setVelocity(this, entity, this.vector); new TempPotionEffect((LivingEntity) entity, effect); entity.setFallDistance(0); if (entity instanceof Creature) { @@ -281,7 +281,7 @@ public class Bloodbending extends BloodAbility { this.vector = new Vector(0, 0, 0); } - this.target.setVelocity(this.vector); + GeneralMethods.setVelocity(this, this.target, this.vector); new TempPotionEffect((LivingEntity) this.target, effect); this.target.setFallDistance(0); diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java index 55a497fc..13e11548 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java @@ -246,7 +246,7 @@ public class IceSpikePillar extends IceAbility { } private void affect(final LivingEntity entity) { - entity.setVelocity(this.thrownForce); + GeneralMethods.setVelocity(this, entity, this.thrownForce); DamageHandler.damageEntity(entity, this.damage, this); this.damaged.add(entity); diff --git a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java index 850ce95e..202a8022 100644 --- a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java +++ b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java @@ -114,7 +114,7 @@ public class WaterArmsWhip extends WaterAbility { waw.grabbed = false; if (waw.grabbedEntity != null) { GRABBED_ENTITIES.remove(waw.grabbedEntity); - waw.grabbedEntity.setVelocity(waw.grabbedEntity.getVelocity().multiply(2.5)); + GeneralMethods.setVelocity(this, waw.grabbedEntity, waw.grabbedEntity.getVelocity().multiply(2.5)); } return; } @@ -300,7 +300,7 @@ public class WaterArmsWhip extends WaterAbility { continue; } final Vector vector = endOfArm.toVector().subtract(entity.getLocation().toVector()); - entity.setVelocity(vector.multiply(this.pullMultiplier)); + GeneralMethods.setVelocity(this, entity, vector.multiply(this.pullMultiplier)); } break; case PUNCH: @@ -310,7 +310,7 @@ public class WaterArmsWhip extends WaterAbility { } final Vector vector = entity.getLocation().toVector().subtract(endOfArm.toVector()); - entity.setVelocity(vector.multiply(0.15)); + GeneralMethods.setVelocity(this, entity, vector.multiply(0.15)); if (entity instanceof LivingEntity) { if (entity.getEntityId() != this.player.getEntityId()) { this.hasDamaged = true; @@ -373,9 +373,9 @@ public class WaterArmsWhip extends WaterAbility { final Vector vector = new Vector(dx, dy, dz); if (distance > 0.5) { - this.grabbedEntity.setVelocity(vector.normalize().multiply(.65)); + GeneralMethods.setVelocity(this, this.grabbedEntity, vector.normalize().multiply(.65)); } else { - this.grabbedEntity.setVelocity(new Vector(0, 0, 0)); + GeneralMethods.setVelocity(this, this.grabbedEntity, new Vector(0, 0, 0)); } this.grabbedEntity.setFallDistance(0); @@ -392,7 +392,7 @@ public class WaterArmsWhip extends WaterAbility { } final Vector vector = this.player.getLocation().toVector().subtract(location.toVector()); - this.player.setVelocity(vector.multiply(-0.25)); + GeneralMethods.setVelocity(this, this.player, vector.multiply(-0.25)); this.player.setFallDistance(0); } } diff --git a/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java b/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java index 71a1f1fa..95ad6240 100644 --- a/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java +++ b/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java @@ -3,6 +3,7 @@ package com.projectkorra.projectkorra.waterbending.passive; import org.bukkit.Location; import org.bukkit.entity.Player; +import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.PassiveAbility; import com.projectkorra.projectkorra.ability.WaterAbility; @@ -57,7 +58,7 @@ public class FastSwim extends WaterAbility implements PassiveAbility { if (this.bPlayer.getBoundAbility() == null || (this.bPlayer.getBoundAbility() != null && !this.bPlayer.getBoundAbility().isSneakAbility())) { if (this.player.isSneaking()) { if (isWater(this.player.getLocation().getBlock()) && !this.bPlayer.isOnCooldown(this)) { - this.player.setVelocity(this.player.getEyeLocation().getDirection().clone().normalize().multiply(this.swimSpeed)); + GeneralMethods.setVelocity(this, this.player, this.player.getEyeLocation().getDirection().clone().normalize().multiply(this.swimSpeed)); } } else { this.bPlayer.addCooldown(this);