TF-ProjectKorra/src/com/projectkorra/projectkorra/airbending/AirSuction.java
Christopher Martin c12e0daebb
1.8.9 (#1038)
For Spigot 1.14.4+

## General Gameplay
### Additions
- Added default Suffocate cooldown: 6.5 seconds
- Added kinetic damage tracker to AirSweep
- Added self and others push strength options for AirSuction
- Added config option for multiple blocks to be changed per EarthTunnel run, allowing for much faster earth tunnels
- Added config to ignore ores completely for EarthTunnel (good for mining)
- Added AllowSnow config option for IceBlast
- Added AvatarStateCooldown config options for IceBlast and IceBullet
- Added config option for ice trapping abilities to not place blocks in players head or feet
### Fixes
- Fixed preset command not allowing page numbers higher than 1
- Fixed Catapult and MetalClips not respecting /b invincible
- Fixed Charged FireBlast radius and cooldown
- Fixed Suffocate being usable through walls
- Fixed FireBlast ignoring particle radius options
- Fixed FireBurst fragmenting (not looking like a single burst)
- Fixed AirSweep knockback to be more consistent (lessened friction)
- Fixed AirBlast knockback using wrong push options
- Fixed EarthSmash using nonexistent AvatarState options
- Fixed error when switching worlds with PhaseChange active
- Fixed server crash when hitting falling blocks with high-velocity abilities
- Fixed server crash when using EarthGrab over the void
- Fixed EarthTunnel not using configurable revert time
- Fixed EarthPillars persisting when no entities were around
### Changes
- Improved pathing for EarthBlast; works more consistently and can be used from ceilings
- Improved aiming for EarthBlast and IceBlast
- Changed AirSwipe and AirSweep to originate from the player’s main hand
- Changed AirBlast knockback calculations; made the push options affect knockback more directly
- Changed EarthTunnel to use tempblocks properly
- Moved core combo instructions to config
### Removals
- Removed being able to use Lightning while using FireJet
- Removed jukeboxes being tempblocks
- Removed bending.command.import permission from plugin.yml

## API
### Additions
- Added GeneralMethods#getMainHandLocation(Player)
- Added GeneralMethods#getClosestEntity(Location, double)
- Added GeneralMethods#getClosestLivingEntity(Location, double)
- Added "large" abilities collision with each other
- Added specific timings for hot spots in the code that should help server owners diagnose lag from PK
  + player move event
  + physics event
  + bending manager
- Created local folder repo and update pom for local jar files, this is necessary to use the maven shade plugin.
- Added check for concrete powder in move earth
- Added PlaceholderAPI support (hopefully more to come)
  + %projectkorra_slot<1-9>% ability on slot <1-9>
  + %projectkorra_element% element of the player
  + %projectkorra_elementcolor% color of the player’s element
  + %projectkorra_elements% elements the player has
- Added "bending" WorldGuard flag. 
  + Used for allowing or denying bending in worldguard regions. Will fall back to the old method of the build flag if the custom flag fails to register or isn't set
### Fixes
- Fixed calls to CoreAbility#isEnabled() causing NullPointerExceptions when a CoreAbility is not enabled
### Changes
- Changed CoreAbility#getAbility(..) Javadocs to state when it returns null
- Formatted codebase
- Changed GeneralMethods#getEntitiesAroundPoint() use spigot method for entities around point, should be more optimized
- Optimizations to water and air spout to not continually set flying
- Optimized revertchecker to not use block.getChunk; this will load the chunk on the server and instead use hashmap of coords
- Optimized revertchecker to use paperlib to allow servers running paperspigot to load the chunk for a revert block async
- Optimized tempblock revert to load chunk async before updating stateOptimize move event to ignore head movements without directional movement
- Optimized physics event to check for air prior to checking for tempblocks
- Optimized tempblock set/revert to not apply physics for blocks that don't emit light
- Optimize isWater to check for actual water blocks first
- Optimize PhaseChange list check, hot spot due to being called in physics event
### Removals
- Removed BindChangeEvent; never called or used
- Removed HorizontalVelocityTracker that has lasted over 30 seconds, also don't create a tracker for non-living entities
2019-12-09 23:03:28 -08:00

417 lines
12 KiB
Java

package com.projectkorra.projectkorra.airbending;
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;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.TrapDoor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
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 final List<Block> affectedDoors = new ArrayList<>();
private boolean progressing;
private int particleCount;
@Attribute(Attribute.COOLDOWN)
private long cooldown;
@Attribute(Attribute.SPEED)
private double speed;
@Attribute(Attribute.RANGE)
private double range;
@Attribute(Attribute.RADIUS)
private double radius;
@Attribute(Attribute.KNOCKBACK)
private double pushFactor;
@Attribute(Attribute.KNOCKBACK + "Others")
private double pushFactorForOthers;
private Random random;
private Location location;
private Location origin;
private Vector direction;
private boolean canAffectSelf;
public AirSuction(final Player player) {
super(player);
if (this.bPlayer.isOnCooldown(this)) {
return;
} else if (player.getEyeLocation().getBlock().isLiquid()) {
return;
} else if (hasAbility(player, AirSpout.class) || hasAbility(player, WaterSpout.class)) {
return;
}
if (hasAbility(player, AirSuction.class)) {
final AirSuction suc = getAbility(player, AirSuction.class);
if (!suc.isProgressing()) {
final Location loc = this.getTargetLocation();
if (!GeneralMethods.isRegionProtectedFromBuild(player, this.getName(), loc)) {
suc.setOrigin(loc);
}
}
return;
}
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");
this.radius = getConfig().getDouble("Abilities.Air.AirSuction.Radius");
this.pushFactor = getConfig().getDouble("Abilities.Air.AirSuction.Push.Self");
this.pushFactorForOthers = getConfig().getDouble("Abilities.Air.AirSuction.Push.Others");
this.cooldown = getConfig().getLong("Abilities.Air.AirSuction.Cooldown");
this.random = new Random();
this.origin = this.getTargetLocation();
this.canAffectSelf = true;
if (GeneralMethods.isRegionProtectedFromBuild(player, this.getName(), this.origin)) {
return;
}
this.location = null;
if (this.bPlayer.isAvatarState()) {
this.pushFactor = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirSuction.Push");
}
this.start();
}
private void advanceLocation() {
playAirbendingParticles(this.location, this.particleCount, 0.275F, 0.275F, 0.275F);
if (this.random.nextInt(4) == 0) {
playAirbendingSound(this.location);
}
final double speedFactor = this.speed * (ProjectKorra.time_step / 1000.);
this.location = this.location.add(this.direction.clone().multiply(speedFactor));
if ((Arrays.asList(AirBlast.DOORS).contains(this.location.getBlock().getType()) || Arrays.asList(AirBlast.TDOORS).contains(this.location.getBlock().getType())) && !this.affectedDoors.contains(this.location.getBlock())) {
this.handleDoorMechanics(this.location.getBlock());
}
}
private void handleDoorMechanics(final Block block) {
boolean tDoor = false;
boolean open = false;
if (Arrays.asList(AirBlast.DOORS).contains(block.getType())) {
final Door door = (Door) block.getBlockData();
final BlockFace face = door.getFacing();
final Vector toPlayer = GeneralMethods.getDirection(block.getLocation(), this.player.getLocation().getBlock().getLocation());
final double[] dims = { toPlayer.getX(), toPlayer.getY(), toPlayer.getZ() };
for (int i = 0; i < 3; i++) {
if (i == 1) {
continue;
}
final BlockFace bf = GeneralMethods.getBlockFaceFromValue(i, dims[i]);
if (bf == face) {
if (!door.isOpen()) {
return;
}
} else if (bf.getOppositeFace() == face) {
if (door.isOpen()) {
return;
}
}
}
door.setOpen(!door.isOpen());
block.setBlockData(door);
open = door.isOpen();
} else {
tDoor = true;
final TrapDoor trap = (TrapDoor) block.getBlockData();
if (this.origin.getY() < block.getY()) {
if (trap.isOpen()) {
return;
}
} else {
if (!trap.isOpen()) {
return;
}
}
trap.setOpen(!trap.isOpen());
block.setBlockData(trap);
open = trap.isOpen();
}
final String sound = "block_wooden_" + (tDoor ? "trap" : "") + "door_" + (!open ? "open" : "close");
block.getWorld().playSound(block.getLocation(), sound, 0.5f, 0);
this.affectedDoors.add(block);
}
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 GeneralMethods.getTargetedLocation(this.player, getSelectRange(), ignore);
}
@Override
public void progress() {
if (this.player.isDead() || !this.player.isOnline()) {
this.remove();
return;
}
if (this.progressing) {
if (GeneralMethods.isRegionProtectedFromBuild(this.player, "AirSuction", this.location)) {
this.remove();
return;
} else if (!this.location.getWorld().equals(this.origin.getWorld()) || 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 (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) {
continue;
}
if ((entity.getEntityId() == this.player.getEntityId()) && !this.canAffectSelf) {
continue;
}
double knockback = this.pushFactor;
if (entity.getEntityId() != player.getEntityId()) {
knockback = this.pushFactorForOthers;
}
final double max = this.speed;
final Vector push = this.direction.clone();
if (Math.abs(push.getY()) > max) {
if (push.getY() < 0) {
push.setY(-max);
} else {
push.setY(max);
}
}
if (this.location.getWorld().equals(this.origin.getWorld())) {
knockback *= 1 - this.location.distance(this.origin) / (2 * this.range);
}
push.normalize().multiply(knockback);
if (Math.abs(entity.getVelocity().dot(push)) > knockback) {
push.normalize().add(entity.getVelocity()).multiply(knockback);
}
GeneralMethods.setVelocity(entity, push.normalize().multiply(knockback));
new HorizontalVelocityTracker(entity, this.player, 200l, this);
entity.setFallDistance(0);
if (entity.getFireTicks() > 0) {
entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0);
}
entity.setFireTicks(0);
breakBreathbendingHold(entity);
}
this.advanceLocation();
} else {
playAirbendingParticles(this.origin, 5, 0.5, 0.5, 0.5);
}
}
public void shoot() {
Location target;
final Entity entity = GeneralMethods.getTargetedEntity(this.player, this.range);
if (entity != null) {
target = entity.getLocation();
} else {
target = this.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(final 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());
suc.setCanEffectSelf(false);
}
if (suc.getOrigin() != null) {
suc.shoot();
}
}
/**
* This method was used for the old collision detection system. Please see
* {@link Collision} for the new system.
*/
@Deprecated
public static boolean removeAirSuctionsAroundPoint(final Location location, final double radius) {
boolean removed = false;
for (final AirSuction airSuction : getAbilities(AirSuction.class)) {
final Location airSuctionlocation = airSuction.location;
if (location.getWorld() == airSuctionlocation.getWorld()) {
if (location.distanceSquared(airSuctionlocation) <= radius * radius) {
airSuction.remove();
}
removed = true;
}
}
return removed;
}
@Override
public String getName() {
return "AirSuction";
}
@Override
public Location getLocation() {
return this.location;
}
@Override
public long getCooldown() {
return this.cooldown;
}
@Override
public boolean isSneakAbility() {
return true;
}
@Override
public boolean isHarmlessAbility() {
return false;
}
@Override
public double getCollisionRadius() {
return this.getRadius();
}
public boolean isProgressing() {
return this.progressing;
}
public Location getOrigin() {
return this.origin;
}
public void setOrigin(final Location origin) {
this.origin = origin;
}
public Vector getDirection() {
return this.direction;
}
public void setDirection(final Vector direction) {
this.direction = direction;
}
public int getParticleCount() {
return this.particleCount;
}
public void setParticleCount(final int particleCount) {
this.particleCount = particleCount;
}
public double getSpeed() {
return this.speed;
}
public void setSpeed(final double speed) {
this.speed = speed;
}
public double getRange() {
return this.range;
}
public void setRange(final double range) {
this.range = range;
}
public double getRadius() {
return this.radius;
}
public void setRadius(final double radius) {
this.radius = radius;
}
public double getPushFactor() {
return this.pushFactor;
}
public void setPushFactor(final double pushFactor) {
this.pushFactor = pushFactor;
}
public void setLocation(final Location location) {
this.location = location;
}
public void setCooldown(final long cooldown) {
this.cooldown = cooldown;
}
public void setCanEffectSelf(final boolean affect) {
this.canAffectSelf = affect;
}
public static int getSelectParticles() {
return getConfig().getInt("Abilities.Air.AirSuction.SelectParticles");
}
public static double getSelectRange() {
return getConfig().getDouble("Abilities.Air.AirSuction.SelectRange");
}
}