Fixed memory leak with IceSpike (#713)

This commit is contained in:
Sobki 2017-01-30 17:18:20 +10:00 committed by Christopher Martin
parent 4743fdc829
commit f10abf5020

View file

@ -1,12 +1,9 @@
package com.projectkorra.projectkorra.waterbending.ice; package com.projectkorra.projectkorra.waterbending.ice;
import com.projectkorra.projectkorra.GeneralMethods; import java.util.ArrayList;
import com.projectkorra.projectkorra.ability.AirAbility; import java.util.HashMap;
import com.projectkorra.projectkorra.ability.IceAbility; import java.util.Map;
import com.projectkorra.projectkorra.ability.WaterAbility; import java.util.Random;
import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.util.TempPotionEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,14 +16,17 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import com.projectkorra.projectkorra.GeneralMethods;
import java.util.HashMap; import com.projectkorra.projectkorra.ability.AirAbility;
import java.util.Map; import com.projectkorra.projectkorra.ability.IceAbility;
import java.util.Random; import com.projectkorra.projectkorra.ability.WaterAbility;
import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.util.TempPotionEffect;
public class IceSpikePillar extends IceAbility { public class IceSpikePillar extends IceAbility {
/**The list of blocks IceSpike uses*/ /** The list of blocks IceSpike uses */
private Map<Block, TempBlock> ice_blocks = new HashMap<Block, TempBlock>(); private Map<Block, TempBlock> ice_blocks = new HashMap<Block, TempBlock>();
private int height; private int height;
@ -138,6 +138,7 @@ public class IceSpikePillar extends IceAbility {
/** /**
* Reverts the block if it's part of IceSpike * Reverts the block if it's part of IceSpike
*
* @param block The Block * @param block The Block
* @return If the block was removed or not * @return If the block was removed or not
*/ */
@ -152,8 +153,10 @@ public class IceSpikePillar extends IceAbility {
return false; return false;
} }
/**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.*/ * 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() { private boolean canInstantiate() {
if (!isIcebendable(source_block.getType())) { if (!isIcebendable(source_block.getType())) {
return false; return false;
@ -195,7 +198,8 @@ public class IceSpikePillar extends IceAbility {
/** /**
* Makes the pillar rise by 1 block. * Makes the pillar rise by 1 block.
* *
* @return If the block was placed successfully.*/ * @return If the block was placed successfully.
*/
private boolean risePillar() { private boolean risePillar() {
progress++; progress++;
Block affectedBlock = location.clone().add(direction).getBlock(); Block affectedBlock = location.clone().add(direction).getBlock();
@ -212,7 +216,7 @@ public class IceSpikePillar extends IceAbility {
} }
} }
TempBlock b = new TempBlock(affectedBlock, Material.ICE, (byte)0); TempBlock b = new TempBlock(affectedBlock, Material.ICE, (byte) 0);
ice_blocks.put(affectedBlock, b); ice_blocks.put(affectedBlock, b);
if (!inField || new Random().nextInt((int) ((height + 1) * 1.5)) == 0) { if (!inField || new Random().nextInt((int) ((height + 1) * 1.5)) == 0) {
@ -240,9 +244,11 @@ public class IceSpikePillar extends IceAbility {
AirAbility.breakBreathbendingHold(entity); AirAbility.breakBreathbendingHold(entity);
} }
/**The reverse of risePillar(). Makes the pillar sink /**
* The reverse of risePillar(). Makes the pillar sink
* *
* @return If the move should continue progressing.*/ * @return If the move should continue progressing.
*/
public boolean sinkPillar() { public boolean sinkPillar() {
Vector direction = this.direction.clone().multiply(-1); Vector direction = this.direction.clone().multiply(-1);
if (ice_blocks.containsKey(location.getBlock())) { if (ice_blocks.containsKey(location.getBlock())) {
@ -250,7 +256,7 @@ public class IceSpikePillar extends IceAbility {
ice_blocks.remove(location.getBlock()); ice_blocks.remove(location.getBlock());
location.add(direction); location.add(direction);
if (source_block == location.getBlock()) { if (source_block.equals(location.getBlock())) {
return false; return false;
} }
} }