TF-ProjectKorra/src/com/projectkorra/projectkorra/ability/WaterAbility.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

384 lines
13 KiB
Java

package com.projectkorra.projectkorra.ability;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Levelled;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.util.Collision;
import com.projectkorra.projectkorra.firebending.HeatControl;
import com.projectkorra.projectkorra.util.BlockSource;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.waterbending.SurgeWall;
import com.projectkorra.projectkorra.waterbending.SurgeWave;
import com.projectkorra.projectkorra.waterbending.Torrent;
import com.projectkorra.projectkorra.waterbending.WaterSpout;
import com.projectkorra.projectkorra.waterbending.ice.PhaseChange;
import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms;
public abstract class WaterAbility extends ElementalAbility {
public WaterAbility(final Player player) {
super(player);
}
public boolean canAutoSource() {
return getConfig().getBoolean("Abilities." + this.getElement() + "." + this.getName() + ".CanAutoSource");
}
public boolean canDynamicSource() {
return getConfig().getBoolean("Abilities." + this.getElement() + "." + this.getName() + ".CanDynamicSource");
}
@Override
public Element getElement() {
return Element.WATER;
}
public Block getIceSourceBlock(final double range) {
return getIceSourceBlock(this.player, range);
}
public Block getPlantSourceBlock(final double range) {
return this.getPlantSourceBlock(range, false);
}
public Block getPlantSourceBlock(final double range, final boolean onlyLeaves) {
return getPlantSourceBlock(this.player, range, onlyLeaves);
}
@Override
public boolean isExplosiveAbility() {
return false;
}
@Override
public boolean isIgniteAbility() {
return false;
}
@Override
public void handleCollision(final Collision collision) {
super.handleCollision(collision);
if (collision.isRemovingFirst()) {
ParticleEffect.BLOCK_CRACK.display(collision.getLocationFirst(), 10, 1, 1, 1, 0.1, collision.getLocationFirst().getBlock().getBlockData());
}
}
public double getNightFactor(final double value) {
return this.player != null ? value * getNightFactor() : 1;
}
public static boolean isBendableWaterTempBlock(final Block block) { // TODO: Will need to be done for earth as well.
return isBendableWaterTempBlock(TempBlock.get(block));
}
public static boolean isBendableWaterTempBlock(final TempBlock tempBlock) {
return PhaseChange.getFrozenBlocksMap().containsKey(tempBlock) || HeatControl.getMeltedBlocks().contains(tempBlock) || SurgeWall.SOURCE_BLOCKS.contains(tempBlock) || Torrent.getFrozenBlocks().containsKey(tempBlock);
}
public boolean isIcebendable(final Block block) {
return this.isIcebendable(block.getType());
}
public boolean isIcebendable(final Material material) {
return this.isIcebendable(this.player, material);
}
public boolean isIcebendable(final Player player, final Material material) {
return isIcebendable(player, material, false);
}
public boolean isPlantbendable(final Block block) {
return this.isPlantbendable(block.getType());
}
public boolean isPlantbendable(final Material material) {
return this.isPlantbendable(this.player, material);
}
public boolean isPlantbendable(final Player player, final Material material) {
return isPlantbendable(player, material, false);
}
public boolean isWaterbendable(final Block block) {
return this.isWaterbendable(this.player, block);
}
public boolean isWaterbendable(final Player player, final Block block) {
return isWaterbendable(player, null, block);
}
public boolean allowBreakPlants() {
return true;
}
public static boolean isWaterbendable(final Material material) {
return isWater(material) || isIce(material) || isPlant(material) || isSnow(material);
}
public static Block getIceSourceBlock(final Player player, final double range) {
final Location location = player.getEyeLocation();
final Vector vector = location.getDirection().clone().normalize();
for (double i = 0; i <= range; i++) {
final Block block = location.clone().add(vector.clone().multiply(i)).getBlock();
if (GeneralMethods.isRegionProtectedFromBuild(player, "IceBlast", location)) {
continue;
}
if (isIcebendable(player, block.getType(), false)) {
if (TempBlock.isTempBlock(block) && !isBendableWaterTempBlock(block)) {
continue;
}
return block;
}
}
return null;
}
public static double getNightFactor() {
return getConfig().getDouble("Properties.Water.NightFactor");
}
public static double getNightFactor(final double value, final World world) {
if (isNight(world)) {
return value * getNightFactor();
}
return value;
}
public static double getNightFactor(final World world) {
return getNightFactor(1, world);
}
public static Block getPlantSourceBlock(final Player player, final double range, final boolean onlyLeaves) {
final Location location = player.getEyeLocation();
final Vector vector = location.getDirection().clone().normalize();
for (double i = 0; i <= range; i++) {
final Block block = location.clone().add(vector.clone().multiply(i)).getBlock();
if (GeneralMethods.isRegionProtectedFromBuild(player, "PlantDisc", location)) {
continue;
} else if (isPlantbendable(player, block.getType(), onlyLeaves)) {
if (TempBlock.isTempBlock(block) && !isBendableWaterTempBlock(block)) {
continue;
}
return block;
}
}
return null;
}
/**
* Finds a valid Water source for a Player. To use dynamic source selection,
* use BlockSource.getWaterSourceBlock() instead of this method. Dynamic
* source selection saves the user's previous source for future use.
* {@link BlockSource#getWaterSourceBlock(Player, double)}
*
* @param player the player that is attempting to Waterbend.
* @param range the maximum block selection range.
* @param plantbending true if the player can bend plants.
* @return a valid Water source block, or null if one could not be found.
*/
public static Block getWaterSourceBlock(final Player player, final double range, final boolean plantbending) {
final Location location = player.getEyeLocation();
final Vector vector = location.getDirection().clone().normalize();
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
final Set<Material> trans = getTransparentMaterialSet();
if (plantbending) {
final Set<Material> remove = new HashSet<>();
for (final Material m : trans) {
if (isPlant(m)) {
remove.add(m);
}
}
trans.removeAll(remove);
}
final Block testBlock = player.getTargetBlock(trans, range > 3 ? 3 : (int) range);
if (bPlayer == null) {
return null;
} else if (isWaterbendable(player, null, testBlock) && (!isPlant(testBlock) || plantbending)) {
return testBlock;
}
for (double i = 0; i <= range; i++) {
final Block block = location.clone().add(vector.clone().multiply(i)).getBlock();
if ((!isTransparent(player, block) && !isIce(block) && !isPlant(block) && !isSnow(block)) || GeneralMethods.isRegionProtectedFromBuild(player, "WaterManipulation", location)) {
continue;
} else if (isWaterbendable(player, null, block) && (!isPlant(block) || plantbending)) {
if (TempBlock.isTempBlock(block) && !isBendableWaterTempBlock(block)) {
continue;
}
return block;
}
}
return null;
}
public static boolean isAdjacentToFrozenBlock(final Block block) {
final BlockFace[] faces = { BlockFace.DOWN, BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH };
boolean adjacent = false;
for (final BlockFace face : faces) {
if (PhaseChange.getFrozenBlocksAsBlock().contains((block.getRelative(face)))) {
adjacent = true;
}
}
return adjacent;
}
public static boolean isIcebendable(final Player player, final Material material, final boolean onlyIce) {
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
return bPlayer == null ? null : isIce(material) && bPlayer.canIcebend() && (!onlyIce || material == Material.ICE);
}
public static boolean isPlantbendable(final Player player, final Material material, final boolean onlyLeaves) {
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (onlyLeaves) {
return bPlayer == null ? null : isPlant(material) && bPlayer.canPlantbend() && isLeaves(material);
} else {
return bPlayer == null ? null : isPlant(material) && bPlayer.canPlantbend();
}
}
public static boolean isLeaves(final Block block) {
return block != null ? isLeaves(block.getType()) : false;
}
public static boolean isLeaves(final Material material) {
return Tag.LEAVES.isTagged(material);
}
public static boolean isSnow(final Block block) {
return block != null ? isSnow(block.getType()) : false;
}
public static boolean isSnow(final Material material) {
return material == Material.SNOW || material == Material.SNOW_BLOCK;
}
public static boolean isWaterbendable(final Player player, final String abilityName, final Block block) {
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null || !isWaterbendable(block.getType()) || GeneralMethods.isRegionProtectedFromBuild(player, abilityName, block.getLocation())) {
return false;
}
if (TempBlock.isTempBlock(block) && !isBendableWaterTempBlock(block)) {
return false;
} else if (isWater(block) && block.getBlockData() instanceof Levelled && ((Levelled) block.getBlockData()).getLevel() == 0) {
return true;
} else if (isIce(block) && !bPlayer.canIcebend()) {
return false;
} else if (isPlant(block) && !bPlayer.canPlantbend()) {
return false;
}
return true;
}
public static void playFocusWaterEffect(final Block block) {
ParticleEffect.SMOKE_NORMAL.display(block.getLocation().add(0.5, 0.5, 0.5), 4);
}
public static void playIcebendingSound(final Location loc) {
if (getConfig().getBoolean("Properties.Water.PlaySound")) {
final float volume = (float) getConfig().getDouble("Properties.Water.IceSound.Volume");
final float pitch = (float) getConfig().getDouble("Properties.Water.IceSound.Pitch");
Sound sound = Sound.ITEM_FLINTANDSTEEL_USE;
try {
sound = Sound.valueOf(getConfig().getString("Properties.Water.IceSound.Sound"));
} catch (final IllegalArgumentException exception) {
ProjectKorra.log.warning("Your current value for 'Properties.Water.IceSound.Sound' is not valid.");
} finally {
loc.getWorld().playSound(loc, sound, volume, pitch);
}
}
}
public static void playPlantbendingSound(final Location loc) {
if (getConfig().getBoolean("Properties.Water.PlaySound")) {
final float volume = (float) getConfig().getDouble("Properties.Water.PlantSound.Volume");
final float pitch = (float) getConfig().getDouble("Properties.Water.PlantSound.Pitch");
Sound sound = Sound.BLOCK_GRASS_STEP;
try {
sound = Sound.valueOf(getConfig().getString("Properties.Water.PlantSound.Sound"));
} catch (final IllegalArgumentException exception) {
ProjectKorra.log.warning("Your current value for 'Properties.Water.PlantSound.Sound' is not valid.");
} finally {
loc.getWorld().playSound(loc, sound, volume, pitch);
}
}
}
public static void playWaterbendingSound(final Location loc) {
if (getConfig().getBoolean("Properties.Water.PlaySound")) {
final float volume = (float) getConfig().getDouble("Properties.Water.WaterSound.Volume");
final float pitch = (float) getConfig().getDouble("Properties.Water.WaterSound.Pitch");
Sound sound = Sound.BLOCK_WATER_AMBIENT;
try {
sound = Sound.valueOf(getConfig().getString("Properties.Water.WaterSound.Sound"));
} catch (final IllegalArgumentException exception) {
ProjectKorra.log.warning("Your current value for 'Properties.Water.WaterSound.Sound' is not valid.");
} finally {
loc.getWorld().playSound(loc, sound, volume, pitch);
}
}
}
/**
* This method was used for the old collision detection system. Please see
* {@link Collision} for the new system.
* <p>
* Removes all water spouts in a location within a certain radius.
*
* @param loc The location to use
* @param radius The radius around the location to remove spouts in
* @param source The player causing the removal
*/
@Deprecated
public static void removeWaterSpouts(final Location loc, final double radius, final Player source) {
WaterSpout.removeSpouts(loc, radius, source);
}
/**
* This method was used for the old collision detection system. Please see
* {@link Collision} for the new system.
* <p>
* Removes all water spouts in a location with a radius of 1.5.
*
* @param loc The location to use
* @param source The player causing the removal
*/
@Deprecated
public static void removeWaterSpouts(final Location loc, final Player source) {
removeWaterSpouts(loc, 1.5, source);
}
public static void stopBending() {
SurgeWall.removeAllCleanup();
SurgeWave.removeAllCleanup();
WaterArms.removeAllCleanup();
}
}