Add AbilityVelocityAffectEntityEvent (#1094)

Created a cancellable event that will fire whenever a bending move would
alter the velocity of an entity.

## Additions
* Adds 1.
    > The AbilityVelocityAffectEntityEvent
    > Adds a new method to GeneralMethods -> setEntityVelocity()
    > Updates existing setVelocity() calls to use the new method in general methods.
    > checks to see if anything in the event should be modified or if it should be cancelled.

## Fixes
* Fixes 2
    > The lack of a way to detect when a bending move pushed a player.
This commit is contained in:
dniym 2020-10-17 20:27:44 -04:00 committed by GitHub
parent 57869047a4
commit 0b35fb9fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 187 additions and 101 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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