From 0b2833d9b6fe9e4d7cd7feeffad32be428016220 Mon Sep 17 00:00:00 2001 From: StrangeOne101 Date: Thu, 19 Jan 2017 11:42:08 +1300 Subject: [PATCH] IceSpike + Water Fixes (#701) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IceSpike + Water Fixes • Fixed IceSpike not using TempBlocks • Fixed IceWave not automatically thawing the ice that freezes people • Fixed EarthPassive (Soft landing) dropping sand blocks when the sand is broken • Made HeatControl a harmless ability if it's the Cook ability * Change isHarmless to use equals() rather than == --- .../projectkorra/projectkorra/PKListener.java | 2 + .../configuration/ConfigManager.java | 2 + .../projectkorra/firebending/HeatControl.java | 2 +- .../waterbending/WaterSpoutWave.java | 22 +++ .../waterbending/ice/IceSpikePillar.java | 143 +++++++++--------- .../util/WaterbendingManager.java | 2 + 6 files changed, 98 insertions(+), 75 deletions(-) diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 4eb09f7b..be10fcee 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -223,6 +223,8 @@ public class PKListener implements Listener { EarthAbility.removeRevertIndex(block); } else if (TempBlock.isTempBlock(block)) { TempBlock.revertBlock(block, Material.AIR); + } else if (EarthPassive.isPassiveSand(block)) { + EarthPassive.revertSand(block); } } diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index 89a723d8..799185cb 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -941,6 +941,8 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterCombo.IceBullet.AnimationSpeed", 1); config.addDefault("Abilities.Water.WaterCombo.IceBullet.ShootTime", 10000); config.addDefault("Abilities.Water.WaterCombo.IceBullet.Cooldown", 10000); + config.addDefault("Abilities.Water.WaterCombo.IceWave.RevertSphere", true); + config.addDefault("Abilities.Water.WaterCombo.IceWave.RevertSphereTime", 30000L); config.addDefault("Abilities.Earth.Passive.Duration", 2500); config.addDefault("Abilities.Earth.Passive.DensityShift.Enabled", true); diff --git a/src/com/projectkorra/projectkorra/firebending/HeatControl.java b/src/com/projectkorra/projectkorra/firebending/HeatControl.java index 2a3df2be..c977515e 100644 --- a/src/com/projectkorra/projectkorra/firebending/HeatControl.java +++ b/src/com/projectkorra/projectkorra/firebending/HeatControl.java @@ -414,7 +414,7 @@ public class HeatControl extends FireAbility { @Override public boolean isHarmlessAbility() { - return false; + return this.heatControlType.equals(HeatControlType.COOK); } @Override diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java index 8f300973..073b3755 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; import java.util.Map; +import java.util.Random; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; @@ -45,9 +46,11 @@ public class WaterSpoutWave extends WaterAbility { private boolean moving; private boolean plant; private boolean collidable; + private boolean revertIceSphere; private int progressCounter; private long time; private long cooldown; + private long revertSphereTime; private double selectRange; private double speed; private double chargeTime; @@ -83,6 +86,8 @@ public class WaterSpoutWave extends WaterAbility { this.chargeTime = getConfig().getLong("Abilities.Water.WaterSpout.Wave.ChargeTime"); this.flightTime = getConfig().getLong("Abilities.Water.WaterSpout.Wave.FlightTime"); this.cooldown = getConfig().getLong("Abilities.Water.WaterSpout.Wave.Cooldown"); + this.revertSphereTime = getConfig().getLong("Abilities.Water.WaterCombo.IceWave.RevertSphereTime"); + this.revertIceSphere = getConfig().getBoolean("Abilities.Water.WaterCombo.IceWave.RevertSphere"); this.affectedBlocks = new ConcurrentHashMap<>(); this.affectedEntities = new ArrayList<>(); this.tasks = new ArrayList<>(); @@ -386,6 +391,9 @@ public class WaterSpoutWave extends WaterAbility { if (!FROZEN_BLOCKS.containsKey(block)) { TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 1); FROZEN_BLOCKS.put(block, tblock); + if (revertIceSphere) { + tblock.setRevertTime(revertSphereTime + (new Random().nextInt(1000) - 500)); + } } } } @@ -432,6 +440,20 @@ public class WaterSpoutWave extends WaterAbility { } return false; } + + public static void progressAllCleanup() { + for (Block block : FROZEN_BLOCKS.keySet()) { + TempBlock tb = FROZEN_BLOCKS.get(block); + if (block.getType() != Material.ICE) { + FROZEN_BLOCKS.remove(block); + continue; + } + if (tb == null || !TempBlock.isTempBlock(block)) { + FROZEN_BLOCKS.remove(block); + continue; + } + } + } public static boolean canThaw(Block block) { return FROZEN_BLOCKS.containsKey(block); diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java index b15e81e6..9a8912e8 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java @@ -4,6 +4,7 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.IceAbility; import com.projectkorra.projectkorra.util.DamageHandler; +import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.util.TempPotionEffect; import org.bukkit.Location; @@ -18,16 +19,16 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; public class IceSpikePillar extends IceAbility { - - private static final Map ALREADY_DONE_BLOCKS = new ConcurrentHashMap<>(); - private static final Map BASE_BLOCKS = new ConcurrentHashMap<>(); - + + /**The list of blocks IceSpike uses*/ + private Map ice_blocks = new HashMap(); + private int height; private int progress; private int slowPower; @@ -41,14 +42,14 @@ public class IceSpikePillar extends IceAbility { private double damage; private double range; private double speed; - private Block block; + private Block source_block; //The block clicked on + private Block base_block; //The block at the bottom of the pillar private Location origin; private Location location; private Vector thrownForce; private Vector direction; - private ConcurrentHashMap affectedBlocks; private ArrayList damaged; - protected boolean inField = false; + protected boolean inField = false; //If it's part of a field or not. public IceSpikePillar(Player player) { super(player); @@ -76,19 +77,17 @@ public class IceSpikePillar extends IceAbility { if (closestEntity != null) { Block tempTestingBlock = closestEntity.getLocation().getBlock().getRelative(BlockFace.DOWN, 1); - this.block = tempTestingBlock; + this.source_block = tempTestingBlock; } else { - this.block = player.getTargetBlock((HashSet) null, (int) range); + this.source_block = player.getTargetBlock((HashSet) null, (int) range); } - origin = block.getLocation(); + origin = source_block.getLocation(); location = origin.clone(); } catch (IllegalStateException e) { return; } - loadAffectedBlocks(); - if (height != 0) { if (canInstantiate()) { start(); @@ -108,11 +107,9 @@ public class IceSpikePillar extends IceAbility { this.damage = damage; this.thrownForce = throwing; this.location = origin.clone(); - this.block = location.getBlock(); + this.source_block = location.getBlock(); - loadAffectedBlocks(); - - if (isIcebendable(block)) { + if (isIcebendable(source_block)) { if (canInstantiate()) { start(); time = System.currentTimeMillis() - interval; @@ -131,46 +128,46 @@ public class IceSpikePillar extends IceAbility { this.cooldown = getConfig().getLong("Abilities.Water.IceSpike.Cooldown"); this.height = getConfig().getInt("Abilities.Water.IceSpike.Height"); this.thrownForce = new Vector(0, getConfig().getDouble("Abilities.Water.IceSpike.Push"), 0); - this.affectedBlocks = new ConcurrentHashMap<>(); this.damaged = new ArrayList<>(); this.interval = (long) (1000. / speed); } - private void loadAffectedBlocks() { - affectedBlocks.clear(); - Block thisBlock; - for (int i = 1; i <= height; i++) { - thisBlock = block.getWorld().getBlockAt(location.clone().add(direction.clone().multiply(i))); - affectedBlocks.put(thisBlock, thisBlock); - } - } - - private boolean blockInAffectedBlocks(Block block) { - return affectedBlocks.containsKey(block); - } - - public static boolean blockInAllAffectedBlocks(Block block) { + /** + * Reverts the block if it's part of IceSpike + * @param block The Block + * @return If the block was removed or not + */ + public static boolean revertBlock(Block block) { for (IceSpikePillar iceSpike : getAbilities(IceSpikePillar.class)) { - if (iceSpike.blockInAffectedBlocks(block)) { + if (iceSpike.ice_blocks.containsKey(block)) { + iceSpike.ice_blocks.get(block).revertBlock(); + iceSpike.ice_blocks.remove(block); return true; } } return false; } - public static void revertBlock(Block block) { - for (IceSpikePillar iceSpike : getAbilities(IceSpikePillar.class)) { - iceSpike.affectedBlocks.remove(block); - } - } - + /**Checks to see if this move can start. Checks things like if there is enough space to form, if the source isn't + * a TempBlock, etc.*/ private boolean canInstantiate() { - if (!isIcebendable(block.getType())) { + if (!isIcebendable(source_block.getType())) { return false; } - for (Block block : affectedBlocks.keySet()) { - if (blockInAllAffectedBlocks(block) || ALREADY_DONE_BLOCKS.containsKey(block) || block.getType() != Material.AIR || (block.getX() == player.getEyeLocation().getBlock().getX() && block.getZ() == player.getEyeLocation().getBlock().getZ())) { + + if (TempBlock.isTempBlock(source_block)) { + return false; + } + + Block b; + for (int i = 1; i <= height; i++) { + b = source_block.getWorld().getBlockAt(location.clone().add(direction.clone().multiply(i))); + if (b.getType() != Material.AIR) { + return false; + } + + if (b.getX() == player.getEyeLocation().getBlock().getX() && b.getZ() == player.getEyeLocation().getBlock().getZ()) { return false; } } @@ -185,9 +182,9 @@ public class IceSpikePillar extends IceAbility { risePillar(); removeTimestamp = System.currentTimeMillis(); } else { + //If it's time to remove if (removeTimestamp != 0 && removeTimestamp + removeTimer <= System.currentTimeMillis()) { - BASE_BLOCKS.put(location.clone().add(direction.clone().multiply(-1 * (height))).getBlock(), (height - 1)); - if (!revertblocks()) { + if (!sinkPillar()) { remove(); return; } @@ -196,6 +193,10 @@ public class IceSpikePillar extends IceAbility { } } + /** + * Makes the pillar rise by 1 block. + * + * @return If the block was placed successfully.*/ private boolean risePillar() { progress++; Block affectedBlock = location.clone().add(direction).getBlock(); @@ -211,16 +212,14 @@ public class IceSpikePillar extends IceAbility { affect(le); } } + + TempBlock b = new TempBlock(affectedBlock, Material.ICE, (byte)0); + ice_blocks.put(affectedBlock, b); - affectedBlock.setType(Material.ICE); if (!inField || new Random().nextInt((int) ((height + 1) * 1.5)) == 0) { - playIcebendingSound(block.getLocation()); - } - loadAffectedBlocks(); - - if (location.distanceSquared(origin) >= height * height) { - return false; + playIcebendingSound(source_block.getLocation()); } + return true; } @@ -241,24 +240,20 @@ public class IceSpikePillar extends IceAbility { } AirAbility.breakBreathbendingHold(entity); } + + /**The reverse of risePillar(). Makes the pillar sink + * + * @return If the move should continue progressing.*/ + public boolean sinkPillar() { + Vector direction = this.direction.clone().multiply(-1); + if (ice_blocks.containsKey(location.getBlock())) { + ice_blocks.get(location.getBlock()).revertBlock(); + ice_blocks.remove(location.getBlock()); + location.add(direction); - public static boolean blockIsBase(Block block) { - return block != null ? BASE_BLOCKS.containsKey(block) : null; - } - - public static void removeBlockBase(Block block) { - if (block != null) { - BASE_BLOCKS.remove(block); - } - } - - public boolean revertblocks() { - Vector direction = new Vector(0, -1, 0); - location.getBlock().setType(Material.AIR); - location.add(direction); - - if (blockIsBase(location.getBlock())) { - return false; + if (source_block == location.getBlock()) { + return false; + } } return true; } @@ -384,11 +379,11 @@ public class IceSpikePillar extends IceAbility { } public Block getBlock() { - return block; + return source_block; } public void setBlock(Block block) { - this.block = block; + this.source_block = block; } public Location getOrigin() { @@ -424,12 +419,12 @@ public class IceSpikePillar extends IceAbility { this.direction = direction; } - public static Map getAlreadyDoneBlocks() { - return ALREADY_DONE_BLOCKS; + public Map getIceBlocks() { + return ice_blocks; } - public static Map getBaseBlocks() { - return BASE_BLOCKS; + public Block getBaseBlock() { + return base_block; } } diff --git a/src/com/projectkorra/projectkorra/waterbending/util/WaterbendingManager.java b/src/com/projectkorra/projectkorra/waterbending/util/WaterbendingManager.java index 1985c96d..8fd375d8 100644 --- a/src/com/projectkorra/projectkorra/waterbending/util/WaterbendingManager.java +++ b/src/com/projectkorra/projectkorra/waterbending/util/WaterbendingManager.java @@ -2,6 +2,7 @@ package com.projectkorra.projectkorra.waterbending.util; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.waterbending.Torrent; +import com.projectkorra.projectkorra.waterbending.WaterSpoutWave; import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms; public class WaterbendingManager implements Runnable { @@ -17,6 +18,7 @@ public class WaterbendingManager implements Runnable { //WaterPassive.handlePassive(); # Fast Swim is now managed in FastSwim.java Torrent.progressAllCleanup(); WaterArms.progressAllCleanup(); + WaterSpoutWave.progressAllCleanup(); } }