From d14d9aec50c92113be5ce0e84186442bede762c6 Mon Sep 17 00:00:00 2001 From: Nathan Braun Date: Thu, 20 Aug 2015 12:32:22 -0700 Subject: [PATCH 1/6] Improve getInstances efficiency --- .../projectkorra/ability/api/CoreAbility.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java index aeba9bad..904be045 100644 --- a/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java @@ -29,6 +29,7 @@ public abstract class CoreAbility implements Ability { private static ConcurrentHashMap instances = new ConcurrentHashMap<>(); //protected static AbilityMap instances = new AbilityMap<>(); private static ConcurrentHashMap> abilityMap = new ConcurrentHashMap<>(); + private static ConcurrentHashMap, ConcurrentHashMap> classAbilityMap = new ConcurrentHashMap<>(); private static int ID = Integer.MIN_VALUE; private final StockAbility stockAbility = getStockAbility(); @@ -49,15 +50,12 @@ public abstract class CoreAbility implements Ability { return true; } /* - List abilities = getAbilitiesFromPlayer(player); - for (CoreAbility coreAbility : abilities) { - if (ability.isInstance(coreAbility)) { - if (coreAbility.getPlayer().getUniqueId().equals(player.getUniqueId())) { - return true; - } - } - } - */ + * List abilities = getAbilitiesFromPlayer(player); for + * (CoreAbility coreAbility : abilities) { if + * (ability.isInstance(coreAbility)) { if + * (coreAbility.getPlayer().getUniqueId().equals(player.getUniqueId())) + * { return true; } } } + */ return false; } @@ -94,7 +92,7 @@ public abstract class CoreAbility implements Ability { } return null; } - + /** * Gets the ability instance by its id. * @@ -108,8 +106,8 @@ public abstract class CoreAbility implements Ability { /** * An access method to get an the instances of a {@link StockAbility}. * IMPORTANT: If this is used in a for each loop use - * {@link #getAbility(int)} to get the ability. Incorrect usage may - * cause over looping and is capable of hanging the thead. + * {@link #getAbility(int)} to get the ability. Incorrect usage may cause + * over looping and is capable of hanging the thead. * * @param ability The instances map to get * @return a map of instances from the specified {@link StockAbility} @@ -128,21 +126,16 @@ public abstract class CoreAbility implements Ability { /** * An access method to get an the instances of a {@link CoreAbility} by its * class. IMPORTANT: If this is used in a for each loop use - * {@link #getAbility(int)} to get the ability. Incorrect usage may - * cause over looping and is capable of hanging the thead. + * {@link #getAbility(int)} to get the ability. Incorrect usage may cause + * over looping and is capable of hanging the thead. * * @param ability The instances map to get * @return a map of instances from the specified class * @see #getInstances(StockAbility) */ public final static ConcurrentHashMap getInstances(Class ability) { - ConcurrentHashMap instanceMap = new ConcurrentHashMap<>(); - for (Integer id : instances.keySet()) { - if (ability.isInstance(instances.get(id))) { - instanceMap.put(id, instances.get(id)); - } - } - return instanceMap; + ConcurrentHashMap instanceMap = classAbilityMap.get(ability.getClass()); + return instanceMap != null ? instanceMap : new ConcurrentHashMap(); } //TODO: Update bending managers to use bellow method @@ -298,7 +291,14 @@ public abstract class CoreAbility implements Ability { this.id = ID; this.uniqueId = player.getUniqueId(); this.player = player; + Class classKey = ability.getClass(); + + if (!classAbilityMap.containsKey(classKey)) { + classAbilityMap.put(classKey, new ConcurrentHashMap()); + } + classAbilityMap.get(classKey).put(id, ability); instances.put(id, ability); + if (stockAbility != null) { if (abilityMap.containsKey(stockAbility)) { abilityMap.get(stockAbility).add(id); @@ -306,6 +306,7 @@ public abstract class CoreAbility implements Ability { abilityMap.put(stockAbility, new ArrayList(Arrays.asList(id))); } } + if (ID == Integer.MAX_VALUE) ID = Integer.MIN_VALUE; ID++; @@ -329,6 +330,11 @@ public abstract class CoreAbility implements Ability { if (instances.containsKey(id)) { instances.remove(id); } + + if (classAbilityMap.containsKey(this.getClass())) { + classAbilityMap.get(this.getClass()).remove(id); + } + if (stockAbility != null) { if (abilityMap.containsKey(stockAbility)) { abilityMap.get(stockAbility).remove(id); From fbbbe3346acd7f869276d61108b47ca390049a37 Mon Sep 17 00:00:00 2001 From: Nathan Braun Date: Thu, 20 Aug 2015 12:59:02 -0700 Subject: [PATCH 2/6] Cleanup CoreAbility File --- .../projectkorra/ability/api/CoreAbility.java | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java index 904be045..5c833bf4 100644 --- a/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java @@ -21,17 +21,15 @@ public abstract class CoreAbility implements Ability { /** * ConcurrentHashMap that stores all Ability instances under UUID key. To - * access this hashmap use either {@link #getInstance()} from the ability + * access this HashMap use either {@link #getInstance()} from the ability * instance or {@link #getInstance(StockAbility)} from the outside. */ - //private static ConcurrentHashMap> instances = new ConcurrentHashMap<>(); - //private static ConcurrentHashMap> instances = new ConcurrentHashMap<>(); - private static ConcurrentHashMap instances = new ConcurrentHashMap<>(); - //protected static AbilityMap instances = new AbilityMap<>(); - private static ConcurrentHashMap> abilityMap = new ConcurrentHashMap<>(); - private static ConcurrentHashMap, ConcurrentHashMap> classAbilityMap = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap> abilityMap = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap, ConcurrentHashMap> classAbilityMap = new ConcurrentHashMap<>(); private static int ID = Integer.MIN_VALUE; + private final StockAbility stockAbility = getStockAbility(); private Player player; private UUID uniqueId; @@ -46,17 +44,7 @@ public abstract class CoreAbility implements Ability { */ public static final boolean containsPlayer(Player player, Class ability) { CoreAbility coreAbility = getAbilityFromPlayer(player, ability); - if (coreAbility != null) { - return true; - } - /* - * List abilities = getAbilitiesFromPlayer(player); for - * (CoreAbility coreAbility : abilities) { if - * (ability.isInstance(coreAbility)) { if - * (coreAbility.getPlayer().getUniqueId().equals(player.getUniqueId())) - * { return true; } } } - */ - return false; + return coreAbility != null ? true : false; } /** @@ -158,9 +146,10 @@ public abstract class CoreAbility implements Ability { * @see #progressAll(StockAbility) */ public static void progressAll(Class ability) { - for (Integer id : instances.keySet()) { - if (ability.isInstance(instances.get(id))) { - instances.get(id).progress(); + ConcurrentHashMap classAbilities = classAbilityMap.get(ability); + if (classAbilities != null) { + for (Integer id : classAbilities.keySet()) { + classAbilities.get(id).progress(); } } } @@ -222,10 +211,7 @@ public abstract class CoreAbility implements Ability { * @return true if ability is a stock ability */ public boolean isStockAbility() { - if (getStockAbility() == null) { - return false; - } - return true; + return getStockAbility() != null ? true : false; } /** From 6bf6dd48689e49fd72d24a3cf7ae68e618f6d339 Mon Sep 17 00:00:00 2001 From: Nathan Braun Date: Thu, 20 Aug 2015 14:21:17 -0700 Subject: [PATCH 3/6] Remove FireBlast Fire Correctly --- src/com/projectkorra/projectkorra/firebending/FireBlast.java | 4 +++- .../projectkorra/projectkorra/waterbending/WaterMethods.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlast.java b/src/com/projectkorra/projectkorra/firebending/FireBlast.java index f95d69a5..c881da38 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlast.java @@ -223,7 +223,9 @@ public class FireBlast extends CoreAbility { private void ignite(Location location) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { if (FireStream.isIgnitable(player, block) && !safe.contains(block)) { - new Plantbending(block); + if (WaterMethods.isPlantbendable(block)) { + new Plantbending(block); + } block.setType(Material.FIRE); if (dissipate) { FireStream.ignitedblocks.put(block, player); diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterMethods.java b/src/com/projectkorra/projectkorra/waterbending/WaterMethods.java index 408ccc83..a28f7d94 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterMethods.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterMethods.java @@ -307,6 +307,10 @@ public class WaterMethods { return true; return false; } + + public static boolean isPlantbendable(Block block) { + return WaterMethods.isPlantbendable(block, false); + } public static void playFocusWaterEffect(Block block) { block.getWorld().playEffect(block.getLocation(), Effect.SMOKE, 4, 20); From 636add6e4bd0359d25b16e68a5e944789278f6e0 Mon Sep 17 00:00:00 2001 From: Nathan Braun Date: Thu, 20 Aug 2015 14:25:46 -0700 Subject: [PATCH 4/6] Format EarthSmash File --- .../projectkorra/earthbending/EarthSmash.java | 504 +++++++++--------- 1 file changed, 246 insertions(+), 258 deletions(-) diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index 05775742..3d8782ed 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -43,7 +43,7 @@ public class EarthSmash { public static long MAIN_COOLDOWN = ProjectKorra.plugin.getConfig().getLong("Abilities.Earth.EarthSmash.Cooldown"); public static long FLYING_REMOVE_TIMER = ProjectKorra.plugin.getConfig().getLong("Abilities.Earth.EarthSmash.FlightTimer"); public static long REMOVE_TIMER = ProjectKorra.plugin.getConfig().getLong("Abilities.Earth.EarthSmash.RemoveTimer"); - + private static int REQUIRED_BENDABLE_BLOCKS = 11; private static int MAX_BLOCKS_TO_PASS_THROUGH = 3; private static double GRAB_DETECTION_RADIUS = 2.5; @@ -51,7 +51,7 @@ public class EarthSmash { private static long SHOOTING_ANIMATION_COOLDOWN = 25; private static long FLYING_ANIMATION_COOLDOWN = 0; private static long LIFT_ANIMATION_COOLDOWN = 30; - + private Player player; private BendingPlayer bplayer; private Block origin; @@ -64,16 +64,16 @@ public class EarthSmash { private ArrayList affectedEntities = new ArrayList(); private ArrayList currentBlocks = new ArrayList(); private ArrayList affectedBlocks = new ArrayList(); - + public EarthSmash(Player player, ClickType type) { - if(!GeneralMethods.hasPermission(player, "EarthSmash")) + if (!GeneralMethods.hasPermission(player, "EarthSmash")) return; - + this.player = player; bplayer = GeneralMethods.getBendingPlayer(player.getName()); this.time = System.currentTimeMillis(); - - if(type == ClickType.SHIFT_DOWN || type == ClickType.SHIFT_UP && !player.isSneaking()) { + + if (type == ClickType.SHIFT_DOWN || type == ClickType.SHIFT_UP && !player.isSneaking()) { grabRange = GRAB_RANGE; chargeTime = CHARGE_TIME; cooldown = MAIN_COOLDOWN; @@ -83,7 +83,7 @@ public class EarthSmash { flySpeed = FLYING_PLAYER_SPEED; flightRemove = FLYING_REMOVE_TIMER; shootRange = TRAVEL_RANGE; - if(AvatarState.isAvatarState(player)) { + if (AvatarState.isAvatarState(player)) { grabRange = AvatarState.getValue(grabRange); chargeTime = AvatarState.getValue(chargeTime); cooldown = 0; @@ -94,15 +94,15 @@ public class EarthSmash { flightRemove = Integer.MAX_VALUE; shootRange = AvatarState.getValue(shootRange); } - + EarthSmash flySmash = flyingInSmashCheck(player); - if(flySmash != null) { + if (flySmash != null) { flySmash.state = State.FLYING; flySmash.player = player; flySmash.flightStart = System.currentTimeMillis(); return; } - + EarthSmash grabbedSmash = aimingAtSmashCheck(player, State.LIFTED); if (grabbedSmash == null) { if (bplayer.isOnCooldown("EarthSmash")) { @@ -110,106 +110,94 @@ public class EarthSmash { } grabbedSmash = aimingAtSmashCheck(player, State.SHOT); } - if(grabbedSmash != null) { + if (grabbedSmash != null) { grabbedSmash.state = State.GRABBED; grabbedSmash.grabbedRange = grabbedSmash.loc.distance(player.getEyeLocation()); grabbedSmash.player = player; return; } - } - else if(type == ClickType.LEFT_CLICK && player.isSneaking()) { - for(EarthSmash smash : instances) { - if(smash.state == State.GRABBED && smash.player == player) { + } else if (type == ClickType.LEFT_CLICK && player.isSneaking()) { + for (EarthSmash smash : instances) { + if (smash.state == State.GRABBED && smash.player == player) { smash.state = State.SHOT; - smash.destination = player.getEyeLocation().clone().add - (player.getEyeLocation().getDirection().normalize().multiply(smash.shootRange)); + smash.destination = player.getEyeLocation().clone().add(player.getEyeLocation().getDirection().normalize().multiply(smash.shootRange)); smash.loc.getWorld().playEffect(smash.loc, Effect.GHAST_SHOOT, 0, 10); } } return; - } - else if(type == ClickType.RIGHT_CLICK && player.isSneaking()) { + } else if (type == ClickType.RIGHT_CLICK && player.isSneaking()) { EarthSmash grabbedSmash = aimingAtSmashCheck(player, State.GRABBED); - if(grabbedSmash != null) { + if (grabbedSmash != null) { player.teleport(grabbedSmash.loc.clone().add(0, 2, 0)); grabbedSmash.state = State.FLYING; grabbedSmash.player = player; grabbedSmash.flightStart = System.currentTimeMillis(); } return; - } - else { + } else { return; } instances.add(this); } - + public void progress() { progressCounter++; - if(state == State.LIFTED && REMOVE_TIMER > 0 && System.currentTimeMillis() - time > REMOVE_TIMER) { + if (state == State.LIFTED && REMOVE_TIMER > 0 && System.currentTimeMillis() - time > REMOVE_TIMER) { remove(); return; } - if(state == State.START || state == State.FLYING || state == State.GRABBED) { - if(player.isDead() || !player.isOnline()) { + if (state == State.START || state == State.FLYING || state == State.GRABBED) { + if (player.isDead() || !player.isOnline()) { remove(); return; } - } - else if(state == State.START) { + } else if (state == State.START) { String ability = GeneralMethods.getBoundAbility(player); - if(ability == null || !ability.equalsIgnoreCase("EarthSmash") || bplayer.isOnCooldown("EarthSmash")) { + if (ability == null || !ability.equalsIgnoreCase("EarthSmash") || bplayer.isOnCooldown("EarthSmash")) { + remove(); + return; + } + } else if (state == State.START || state == State.FLYING || state == State.GRABBED) { + if (!GeneralMethods.canBend(player.getName(), "EarthSmash")) { remove(); return; } } - else if(state == State.START || state == State.FLYING || state == State.GRABBED) { - if(!GeneralMethods.canBend(player.getName(), "EarthSmash")) { - remove(); - return; - } - } - - if(state == State.START && progressCounter > 1) { - if(!player.isSneaking()) { - if(System.currentTimeMillis() - time > chargeTime) { + + if (state == State.START && progressCounter > 1) { + if (!player.isSneaking()) { + if (System.currentTimeMillis() - time > chargeTime) { origin = EarthMethods.getEarthSourceBlock(player, grabRange); - if(origin == null){ + if (origin == null) { remove(); return; } bplayer.addCooldown("EarthSmash", cooldown); loc = origin.getLocation(); state = State.LIFTING; - } - else { + } else { remove(); return; } - } - else if(System.currentTimeMillis() - time > chargeTime) { - Location tempLoc = player.getEyeLocation().add(player.getEyeLocation() - .getDirection().normalize().multiply(1.2)); + } else if (System.currentTimeMillis() - time > chargeTime) { + Location tempLoc = player.getEyeLocation().add(player.getEyeLocation().getDirection().normalize().multiply(1.2)); tempLoc.add(0, 0.3, 0); - ParticleEffect.SMOKE.display(tempLoc, 0.3F, 0.1F, 0.3F, 0, 4); + ParticleEffect.SMOKE.display(tempLoc, 0.3F, 0.1F, 0.3F, 0, 4); } - } - else if(state == State.LIFTING) { - if(System.currentTimeMillis() - delay >= LIFT_ANIMATION_COOLDOWN) { + } else if (state == State.LIFTING) { + if (System.currentTimeMillis() - delay >= LIFT_ANIMATION_COOLDOWN) { delay = System.currentTimeMillis(); animateLift(); } - } - else if(state == State.GRABBED) { - if(player.isSneaking()) { + } else if (state == State.GRABBED) { + if (player.isSneaking()) { revert(); Location oldLoc = loc.clone(); - loc = player.getEyeLocation().add( - player.getEyeLocation().getDirection().normalize().multiply(grabbedRange)); - + loc = player.getEyeLocation().add(player.getEyeLocation().getDirection().normalize().multiply(grabbedRange)); + //Check to make sure the new location is available to move to - for(Block block : getBlocks()) - if(block.getType() != Material.AIR && !EarthMethods.isTransparentToEarthbending(player, block)) { + for (Block block : getBlocks()) + if (block.getType() != Material.AIR && !EarthMethods.isTransparentToEarthbending(player, block)) { loc = oldLoc; break; } @@ -217,33 +205,30 @@ public class EarthSmash { AirMethods.removeAirSpouts(loc, 2, player); draw(); return; - } - else { + } else { state = State.LIFTED; return; } - } - else if(state == State.SHOT) { - if(System.currentTimeMillis() - delay >= SHOOTING_ANIMATION_COOLDOWN) { + } else if (state == State.SHOT) { + if (System.currentTimeMillis() - delay >= SHOOTING_ANIMATION_COOLDOWN) { delay = System.currentTimeMillis(); - if(GeneralMethods.isRegionProtectedFromBuild(player, "EarthSmash", loc)) { + if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthSmash", loc)) { remove(); return; } revert(); loc.add(GeneralMethods.getDirection(loc, destination).normalize().multiply(1)); - if(loc.distanceSquared(destination) < 4) { + if (loc.distanceSquared(destination) < 4) { remove(); return; } // If an earthsmash runs into too many blocks we should remove it int badBlocksFound = 0; - for(Block block : getBlocks()) - if(block.getType() != Material.AIR && - (!EarthMethods.isTransparentToEarthbending(player, block) || block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)) + for (Block block : getBlocks()) + if (block.getType() != Material.AIR && (!EarthMethods.isTransparentToEarthbending(player, block) || block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)) badBlocksFound++; - - if(badBlocksFound > MAX_BLOCKS_TO_PASS_THROUGH) { + + if (badBlocksFound > MAX_BLOCKS_TO_PASS_THROUGH) { remove(); return; } @@ -254,155 +239,151 @@ public class EarthSmash { smashToSmashCollisionDetection(); } return; - } - else if(state == State.FLYING) { - if(!player.isSneaking()){ + } else if (state == State.FLYING) { + if (!player.isSneaking()) { remove(); return; - } - else if(System.currentTimeMillis() - delay >= FLYING_ANIMATION_COOLDOWN) - { + } else if (System.currentTimeMillis() - delay >= FLYING_ANIMATION_COOLDOWN) { delay = System.currentTimeMillis(); - if(GeneralMethods.isRegionProtectedFromBuild(player, "EarthSmash", loc)) { + if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthSmash", loc)) { remove(); return; } revert(); - destination = player.getEyeLocation().clone().add - (player.getEyeLocation().getDirection().normalize().multiply(shootRange)); + destination = player.getEyeLocation().clone().add(player.getEyeLocation().getDirection().normalize().multiply(shootRange)); Vector direction = GeneralMethods.getDirection(loc, destination).normalize(); - - List entities = GeneralMethods.getEntitiesAroundPoint(loc.clone().add(0,2,0), FLIGHT_DETECTION_RADIUS); - if(entities.size() == 0){ + + List entities = GeneralMethods.getEntitiesAroundPoint(loc.clone().add(0, 2, 0), FLIGHT_DETECTION_RADIUS); + if (entities.size() == 0) { remove(); return; } - for(Entity entity : entities) + for (Entity entity : entities) entity.setVelocity(direction.clone().multiply(flySpeed)); - + //These values tend to work well when dealing with a person aiming upward or downward. - if(direction.getY() < -0.35) - loc = player.getLocation().clone().add(0,-3.2,0); - else if(direction.getY() > 0.35) - loc = player.getLocation().clone().add(0,-1.7,0); + if (direction.getY() < -0.35) + loc = player.getLocation().clone().add(0, -3.2, 0); + else if (direction.getY() > 0.35) + loc = player.getLocation().clone().add(0, -1.7, 0); else - loc = player.getLocation().clone().add(0,-2.2,0); + loc = player.getLocation().clone().add(0, -2.2, 0); draw(); } - if(System.currentTimeMillis() - flightStart > flightRemove){ + if (System.currentTimeMillis() - flightStart > flightRemove) { remove(); return; } } } - + @SuppressWarnings("deprecation") - public void animateLift() - { + public void animateLift() { /** - * Begins animating the EarthSmash from the ground. The lift animation consists - * of 3 steps, and each one has to design the shape in the ground that removes the - * earthbendable material. We also need to make sure that there is a clear path for - * the EarthSmash to rise, and that there is enough earthbendable material for it to be created. + * Begins animating the EarthSmash from the ground. The lift animation + * consists of 3 steps, and each one has to design the shape in the + * ground that removes the earthbendable material. We also need to make + * sure that there is a clear path for the EarthSmash to rise, and that + * there is enough earthbendable material for it to be created. */ - if(animCounter < 4) { + if (animCounter < 4) { revert(); - loc.add(0,1,0); + loc.add(0, 1, 0); //Remove the blocks underneath the rising smash - if(animCounter == 0) { + if (animCounter == 0) { //Check all of the blocks and make sure that they can be removed AND make sure there is enough dirt int totalBendableBlocks = 0; - for(int x = -1; x <= 1; x++) - for(int y = -2; y <= -1; y++) - for(int z = -1; z <= 1; z++) { - Block block = loc.clone().add(x,y,z).getBlock(); - if(GeneralMethods.isRegionProtectedFromBuild(player, "EarthSmash", block.getLocation())) { + for (int x = -1; x <= 1; x++) + for (int y = -2; y <= -1; y++) + for (int z = -1; z <= 1; z++) { + Block block = loc.clone().add(x, y, z).getBlock(); + if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthSmash", block.getLocation())) { remove(); return; } - if(isEarthbendableMaterial(block.getType())) + if (isEarthbendableMaterial(block.getType())) totalBendableBlocks++; } - if(totalBendableBlocks < REQUIRED_BENDABLE_BLOCKS) { + if (totalBendableBlocks < REQUIRED_BENDABLE_BLOCKS) { remove(); return; } //Make sure there is a clear path upward otherwise remove - for(int y = 0; y <= 3; y++) { - Block tempBlock = loc.clone().add(0,y,0).getBlock(); - if(!EarthMethods.isTransparentToEarthbending(player, tempBlock) && tempBlock.getType() != Material.AIR) { + for (int y = 0; y <= 3; y++) { + Block tempBlock = loc.clone().add(0, y, 0).getBlock(); + if (!EarthMethods.isTransparentToEarthbending(player, tempBlock) && tempBlock.getType() != Material.AIR) { remove(); return; } } //Design what this EarthSmash looks like by using BlockRepresenters - Location tempLoc = loc.clone().add(0,-2,0); - for(int x = -1; x <= 1; x++) - for(int y = -1; y <= 1; y++) - for(int z = -1; z <= 1; z++) - if((Math.abs(x) + Math.abs(y) + Math.abs(z)) % 2 == 0) { - Block block = tempLoc.clone().add(x,y,z).getBlock(); + Location tempLoc = loc.clone().add(0, -2, 0); + for (int x = -1; x <= 1; x++) + for (int y = -1; y <= 1; y++) + for (int z = -1; z <= 1; z++) + if ((Math.abs(x) + Math.abs(y) + Math.abs(z)) % 2 == 0) { + Block block = tempLoc.clone().add(x, y, z).getBlock(); currentBlocks.add(new BlockRepresenter(x, y, z, selectMaterialForRepresenter(block.getType()), block.getData())); } - + //Remove the design of the second level of removed dirt - for(int x = -1; x <= 1; x++) - for(int z = -1; z <= 1; z++) { - if((Math.abs(x) + Math.abs(z)) % 2 == 1) { - Block block = loc.clone().add(x,-2,z).getBlock(); - if(isEarthbendableMaterial(block.getType())) + for (int x = -1; x <= 1; x++) + for (int z = -1; z <= 1; z++) { + if ((Math.abs(x) + Math.abs(z)) % 2 == 1) { + Block block = loc.clone().add(x, -2, z).getBlock(); + if (isEarthbendableMaterial(block.getType())) EarthMethods.addTempAirBlock(block); - } - + } + //Remove the first level of dirt - Block block = loc.clone().add(x,-1,z).getBlock(); - if(isEarthbendableMaterial(block.getType())) - EarthMethods.addTempAirBlock(block); - + Block block = loc.clone().add(x, -1, z).getBlock(); + if (isEarthbendableMaterial(block.getType())) + EarthMethods.addTempAirBlock(block); + } /* - * We needed to calculate all of the blocks based on the location being 1 above the initial - * bending block, however we want to animate it starting from the original bending block. + * We needed to calculate all of the blocks based on the + * location being 1 above the initial bending block, however we + * want to animate it starting from the original bending block. * We must readjust the location back to what it originally was. */ - loc.add(0,-1,0); + loc.add(0, -1, 0); } //Move any entities that are above the rock List entities = GeneralMethods.getEntitiesAroundPoint(loc, 2.5); - for(Entity entity : entities) { + for (Entity entity : entities) { org.bukkit.util.Vector velocity = entity.getVelocity(); - entity.setVelocity(velocity.add(new Vector(0,0.36,0))); + entity.setVelocity(velocity.add(new Vector(0, 0.36, 0))); } loc.getWorld().playEffect(loc, Effect.GHAST_SHOOT, 0, 7); draw(); - } - else { + } else { state = State.LIFTED; } animCounter++; } - + public void draw() { /** * Redraws the blocks for this instance of EarthSmash. */ - if(currentBlocks.size() == 0) { + if (currentBlocks.size() == 0) { remove(); return; } - for(BlockRepresenter blockRep : currentBlocks) { - Block block = loc.clone().add(blockRep.getX(),blockRep.getY(),blockRep.getZ()).getBlock(); - if(player != null && EarthMethods.isTransparentToEarthbending(player,block)) { + for (BlockRepresenter blockRep : currentBlocks) { + Block block = loc.clone().add(blockRep.getX(), blockRep.getY(), blockRep.getZ()).getBlock(); + if (player != null && EarthMethods.isTransparentToEarthbending(player, block)) { affectedBlocks.add(new TempBlock(block, blockRep.getType(), blockRep.getData())); EarthMethods.tempNoEarthbending.add(block); } } - } - + } + public void revert() { checkRemainingBlocks(); - for(int i = 0; i < affectedBlocks.size(); i++) { + for (int i = 0; i < affectedBlocks.size(); i++) { TempBlock tblock = affectedBlocks.get(i); EarthMethods.tempNoEarthbending.remove(tblock.getBlock()); tblock.revertBlock(); @@ -410,162 +391,166 @@ public class EarthSmash { i--; } } - + public void checkRemainingBlocks() { /** * Checks to see which of the blocks are still attached to the - * EarthSmash, remember that blocks can be broken or used in other abilities - * so we need to double check and remove any that are not still attached. + * EarthSmash, remember that blocks can be broken or used in other + * abilities so we need to double check and remove any that are not + * still attached. * * Also when we remove the blocks from instances, movedearth, or tempair - * we should do it on a delay because tempair takes a couple seconds before - * the block shows up in that map. + * we should do it on a delay because tempair takes a couple seconds + * before the block shows up in that map. */ - for(int i = 0; i < currentBlocks.size(); i++) { + for (int i = 0; i < currentBlocks.size(); i++) { BlockRepresenter brep = currentBlocks.get(i); final Block block = loc.clone().add(brep.getX(), brep.getY(), brep.getZ()).getBlock(); // Check for grass because sometimes the dirt turns into grass. - if(block.getType() != brep.getType() - && (block.getType() != Material.GRASS) - && (block.getType() != Material.COBBLESTONE)) { + if (block.getType() != brep.getType() && (block.getType() != Material.GRASS) && (block.getType() != Material.COBBLESTONE)) { currentBlocks.remove(i); i--; } } } - + public void remove() { state = State.REMOVED; revert(); instances.remove(this); } - + public List getBlocks() { /** - * Gets the blocks surrounding the EarthSmash's loc. - * This method ignores the blocks that should be Air, and only returns the ones that are dirt. + * Gets the blocks surrounding the EarthSmash's loc. This method ignores + * the blocks that should be Air, and only returns the ones that are + * dirt. */ List blocks = new ArrayList(); - for(int x = -1; x <= 1; x++) - for(int y = -1; y <= 1; y++) - for(int z = -1; z <= 1; z++) - if((Math.abs(x) + Math.abs(y) + Math.abs(z)) % 2 == 0) //Give it the cool shape - if(loc != null) - blocks.add(loc.getWorld().getBlockAt(loc.clone().add(x,y,z))); + for (int x = -1; x <= 1; x++) + for (int y = -1; y <= 1; y++) + for (int z = -1; z <= 1; z++) + if ((Math.abs(x) + Math.abs(y) + Math.abs(z)) % 2 == 0) //Give it the cool shape + if (loc != null) + blocks.add(loc.getWorld().getBlockAt(loc.clone().add(x, y, z))); return blocks; } - + public List getBlocksIncludingInner() { /** - * Gets the blocks surrounding the EarthSmash's loc. - * This method returns all the blocks surrounding the loc, including dirt and air. + * Gets the blocks surrounding the EarthSmash's loc. This method returns + * all the blocks surrounding the loc, including dirt and air. */ List blocks = new ArrayList(); - for(int x = -1; x <= 1; x++) - for(int y = -1; y <= 1; y++) - for(int z = -1; z <= 1; z++) - if(loc != null) - blocks.add(loc.getWorld().getBlockAt(loc.clone().add(x,y,z))); + for (int x = -1; x <= 1; x++) + for (int y = -1; y <= 1; y++) + for (int z = -1; z <= 1; z++) + if (loc != null) + blocks.add(loc.getWorld().getBlockAt(loc.clone().add(x, y, z))); return blocks; } - + public static Material selectMaterial(Material mat) { /** - * Switches the Sand Material and Gravel to SandStone and stone respectively, - * since gravel and sand cannot be bent due to gravity. + * Switches the Sand Material and Gravel to SandStone and stone + * respectively, since gravel and sand cannot be bent due to gravity. */ - if(mat == Material.SAND) return Material.SANDSTONE; - else if(mat == Material.GRAVEL) return Material.STONE; - else return mat; + if (mat == Material.SAND) + return Material.SANDSTONE; + else if (mat == Material.GRAVEL) + return Material.STONE; + else + return mat; } - + public Material selectMaterialForRepresenter(Material mat) { Material tempMat = selectMaterial(mat); Random rand = new Random(); - if(!isEarthbendableMaterial(tempMat)) { - if(currentBlocks.size() < 1) + if (!isEarthbendableMaterial(tempMat)) { + if (currentBlocks.size() < 1) return Material.DIRT; - else + else return currentBlocks.get(rand.nextInt(currentBlocks.size())).getType(); } return tempMat; } - + private EarthSmash aimingAtSmashCheck(Player player, State reqState) { /** - * Determines if a player is trying to grab an EarthSmash. - * A player is trying to grab an EarthSmash if they are staring at it and holding shift. + * Determines if a player is trying to grab an EarthSmash. A player is + * trying to grab an EarthSmash if they are staring at it and holding + * shift. */ - if(!ALLOW_GRAB) + if (!ALLOW_GRAB) return null; @SuppressWarnings("deprecation") List blocks = player.getLineOfSight(EarthMethods.getTransparentEarthbending(), (int) Math.round(grabRange)); - for(EarthSmash smash : instances) { - if(reqState == null || smash.state == reqState) - for(Block block : blocks) - if(block.getLocation().getWorld() == smash.loc.getWorld() && - block.getLocation().distanceSquared(smash.loc) <= Math.pow(GRAB_DETECTION_RADIUS, 2)) + for (EarthSmash smash : instances) { + if (reqState == null || smash.state == reqState) + for (Block block : blocks) + if (block.getLocation().getWorld() == smash.loc.getWorld() && block.getLocation().distanceSquared(smash.loc) <= Math.pow(GRAB_DETECTION_RADIUS, 2)) return smash; } - return null; + return null; } - + public void shootingCollisionDetection() { /** - * This method handles any collision between an EarthSmash and the surrounding entities, - * the method only applies to earthsmashes that have already been shot. + * This method handles any collision between an EarthSmash and the + * surrounding entities, the method only applies to earthsmashes that + * have already been shot. */ List entities = GeneralMethods.getEntitiesAroundPoint(loc, FLIGHT_DETECTION_RADIUS); - for(Entity entity : entities) - if(entity instanceof LivingEntity - && entity != player - && !affectedEntities.contains(entity)) { + for (Entity entity : entities) + if (entity instanceof LivingEntity && entity != player && !affectedEntities.contains(entity)) { affectedEntities.add(entity); double damage = currentBlocks.size() / 13 * this.damage; GeneralMethods.damageEntity(player, entity, damage); Vector travelVec = GeneralMethods.getDirection(loc, entity.getLocation()); entity.setVelocity(travelVec.setY(knockup).normalize().multiply(knockback)); } - } + } + public void smashToSmashCollisionDetection() { /** - * EarthSmash to EarthSmash collision can only happen when one of the Smashes have - * been shot by a player. If we find out that one of them have collided then we want to return - * since a smash can only remove 1 at a time. + * EarthSmash to EarthSmash collision can only happen when one of the + * Smashes have been shot by a player. If we find out that one of them + * have collided then we want to return since a smash can only remove 1 + * at a time. */ - for(int i = 0; i < instances.size(); i++) { + for (int i = 0; i < instances.size(); i++) { EarthSmash smash = instances.get(i); - if(smash.loc != null) { - if(smash != this && smash.loc.getWorld() == loc.getWorld() &&smash.loc.distanceSquared(loc) < Math.pow(FLIGHT_DETECTION_RADIUS, 2)) { + if (smash.loc != null) { + if (smash != this && smash.loc.getWorld() == loc.getWorld() && smash.loc.distanceSquared(loc) < Math.pow(FLIGHT_DETECTION_RADIUS, 2)) { smash.remove(); remove(); - i-=2; + i -= 2; return; } } } } - + private static EarthSmash flyingInSmashCheck(Player player) { /** - * Determines whether or not a player is trying to fly ontop of an EarthSmash. - * A player is considered "flying" if they are standing ontop of the earthsmash and holding shift. + * Determines whether or not a player is trying to fly ontop of an + * EarthSmash. A player is considered "flying" if they are standing + * ontop of the earthsmash and holding shift. */ - if(!ALLOW_FLIGHT) + if (!ALLOW_FLIGHT) return null; - - for(EarthSmash smash : instances) { + + for (EarthSmash smash : instances) { //Check to see if the player is standing on top of the smash. - if(smash.state == State.LIFTED) { - if(smash.loc.getWorld().equals(player.getWorld()) - && smash.loc.clone().add(0,2,0).distanceSquared(player.getLocation()) <= Math.pow(FLIGHT_DETECTION_RADIUS, 2)) { + if (smash.state == State.LIFTED) { + if (smash.loc.getWorld().equals(player.getWorld()) && smash.loc.clone().add(0, 2, 0).distanceSquared(player.getLocation()) <= Math.pow(FLIGHT_DETECTION_RADIUS, 2)) { return smash; } } } return null; } - + public static boolean isEarthbendableMaterial(Material mat) { for (String s : ProjectKorra.plugin.getConfig().getStringList("Properties.Earth.EarthbendableBlocks")) { if (mat == Material.getMaterial(s)) @@ -573,30 +558,32 @@ public class EarthSmash { } return false; } - + public static void progressAll() { - for(int i = 0; i < instances.size(); i++) + for (int i = 0; i < instances.size(); i++) instances.get(i).progress(); } - + public static void removeAll() { - for(int i = 0; i < instances.size(); i++) { + for (int i = 0; i < instances.size(); i++) { instances.get(i).remove(); i--; } } - + public class BlockRepresenter { /** - * A BlockRepresenter is used to keep track of each of - * the individual types of blocks that are attached to an EarthSmash. - * Without the representer then an EarthSmash can only be made up of 1 material - * at a time. For example, an ESmash that is entirely dirt, coalore, or sandstone. - * Using the representer will allow all the materials to be mixed together. + * A BlockRepresenter is used to keep track of each of the individual + * types of blocks that are attached to an EarthSmash. Without the + * representer then an EarthSmash can only be made up of 1 material at a + * time. For example, an ESmash that is entirely dirt, coalore, or + * sandstone. Using the representer will allow all the materials to be + * mixed together. */ private int x, y, z; private Material type; private byte data; + public BlockRepresenter(int x, int y, int z, Material type, byte data) { this.x = x; this.y = y; @@ -604,77 +591,78 @@ public class EarthSmash { this.type = type; this.data = data; } + public int getX() { return x; } - + public int getY() { return y; } - + public int getZ() { return z; } - + public Material getType() { return type; } - + public byte getData() { return data; } - + public void setX(int x) { this.x = x; } - + public void setY(int y) { this.y = y; } - + public void setZ(int z) { this.z = z; } - + public void setType(Material type) { this.type = type; } - + public void setData(byte data) { this.data = data; } - + public String toString() { - return x + ", " + y + ", " + z + ", " + type.toString(); + return x + ", " + y + ", " + z + ", " + type.toString(); } } - + public class Pair { - private F first; //first member of pair - private S second; //second member of pair + private F first; //first member of pair + private S second; //second member of pair - public Pair(F first, S second) { - this.first = first; - this.second = second; - } + public Pair(F first, S second) { + this.first = first; + this.second = second; + } - public void setFirst(F first) { - this.first = first; - } + public void setFirst(F first) { + this.first = first; + } - public void setSecond(S second) { - this.second = second; - } + public void setSecond(S second) { + this.second = second; + } - public F getFirst() { - return first; - } + public F getFirst() { + return first; + } - public S getSecond() { - return second; - } + public S getSecond() { + return second; + } } - + public Player getPlayer() { return player; } @@ -689,7 +677,7 @@ public class EarthSmash { public void setCooldown(long cooldown) { this.cooldown = cooldown; - if(player != null) + if (player != null) bplayer.addCooldown("EarthSmash", cooldown); } From 7680a468d348e6544a2eef94b95ca321383fb633 Mon Sep 17 00:00:00 2001 From: Nathan Braun Date: Thu, 20 Aug 2015 14:30:14 -0700 Subject: [PATCH 5/6] Fix EarthSmash not working in AvatarState --- src/com/projectkorra/projectkorra/earthbending/EarthSmash.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index 3d8782ed..85b3410d 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -85,7 +85,7 @@ public class EarthSmash { shootRange = TRAVEL_RANGE; if (AvatarState.isAvatarState(player)) { grabRange = AvatarState.getValue(grabRange); - chargeTime = AvatarState.getValue(chargeTime); + chargeTime = 0; cooldown = 0; damage = AvatarState.getValue(damage); knockback = AvatarState.getValue(knockback); From 2e5312fb1fb2b1996796833c4a2c724670c32751 Mon Sep 17 00:00:00 2001 From: Nathan Braun Date: Thu, 20 Aug 2015 16:22:02 -0700 Subject: [PATCH 6/6] Improve ComboManager Efficiency --- .../ability/combo/ComboManager.java | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/com/projectkorra/projectkorra/ability/combo/ComboManager.java b/src/com/projectkorra/projectkorra/ability/combo/ComboManager.java index 15cf3e3b..65548597 100644 --- a/src/com/projectkorra/projectkorra/ability/combo/ComboManager.java +++ b/src/com/projectkorra/projectkorra/ability/combo/ComboManager.java @@ -35,7 +35,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("FireKick", fireKick, FireCombo.class)); descriptions.put("FireKick", "A short ranged arc of fire launches from the player's feet dealing moderate damage to enemies."); instructions.put("FireKick", "FireBlast > FireBlast > (Hold Shift) > FireBlast."); - + ArrayList fireSpin = new ArrayList(); fireSpin.add(new AbilityInformation("FireBlast", ClickType.LEFT_CLICK)); fireSpin.add(new AbilityInformation("FireBlast", ClickType.LEFT_CLICK)); @@ -45,7 +45,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("FireSpin", fireSpin, FireCombo.class)); descriptions.put("FireSpin", "A circular array of fire that causes damage and massive knockback to nearby enemies."); instructions.put("FireSpin", "FireBlast > FireBlast > FireShield > (Tap Shift)."); - + ArrayList jetBlast = new ArrayList(); jetBlast.add(new AbilityInformation("FireJet", ClickType.SHIFT_DOWN)); jetBlast.add(new AbilityInformation("FireJet", ClickType.SHIFT_UP)); @@ -57,7 +57,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("JetBlast", jetBlast, FireCombo.class)); descriptions.put("JetBlast", "Create an explosive blast that propels your FireJet at higher speeds."); instructions.put("JetBlast", "FireJet (Tap Shift) > FireJet (Tap Shift) > FireShield (Tap Shift) > FireJet."); - + ArrayList jetBlaze = new ArrayList(); jetBlaze.add(new AbilityInformation("FireJet", ClickType.SHIFT_DOWN)); jetBlaze.add(new AbilityInformation("FireJet", ClickType.SHIFT_UP)); @@ -69,7 +69,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("JetBlaze", jetBlaze, FireCombo.class)); descriptions.put("JetBlaze", "Damages and burns all enemies in the proximity of your FireJet."); instructions.put("JetBlaze", "FireJet (Tap Shift) > FireJet (Tap Shift) > Blaze (Tap Shift) > FireJet."); - + ArrayList fireWheel = new ArrayList(); fireWheel.add(new AbilityInformation("FireShield", ClickType.SHIFT_DOWN)); fireWheel.add(new AbilityInformation("FireShield", ClickType.RIGHT_CLICK)); @@ -78,7 +78,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("FireWheel", fireWheel, FireCombo.class)); descriptions.put("FireWheel", "A high-speed wheel of fire that travels along the ground for long distances dealing high damage."); instructions.put("FireWheel", "FireShield (Hold Shift) > Right Click a block in front of you twice > Switch to Blaze > Release Shift."); - + ArrayList twister = new ArrayList(); twister.add(new AbilityInformation("AirShield", ClickType.SHIFT_DOWN)); twister.add(new AbilityInformation("AirShield", ClickType.SHIFT_UP)); @@ -87,7 +87,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("Twister", twister, AirCombo.class)); descriptions.put("Twister", "Create a cyclone of air that travels along the ground grabbing nearby entities."); instructions.put("Twister", "AirShield (Tap Shift) > Tornado (Hold Shift) > AirBlast (Left Click)"); - + ArrayList airStream = new ArrayList(); airStream.add(new AbilityInformation("AirShield", ClickType.SHIFT_DOWN)); airStream.add(new AbilityInformation("AirSuction", ClickType.LEFT_CLICK)); @@ -95,7 +95,7 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("AirStream", airStream, AirCombo.class)); descriptions.put("AirStream", "Control a large stream of air that grabs onto enemies allowing you to direct them temporarily."); instructions.put("AirStream", "AirShield (Hold Shift) > AirSuction (Left Click) > AirBlast (Left Click)"); - + /* * ArrayList airSlice = new * ArrayList(); airSlice.add(new @@ -115,19 +115,24 @@ public class ComboManager { comboAbilityList.add(new ComboAbility("AirSweep", airSweep, AirCombo.class)); descriptions.put("AirSweep", "Sweep the air in front of you hitting multiple enemies, causing moderate damage and a large knockback. The radius and direction of AirSweep is controlled by moving your mouse in a sweeping motion. For example, if you want to AirSweep upward, then move your mouse upward right after you left click AirBurst"); instructions.put("AirSweep", "AirSwipe (Left Click) > AirSwipe (Left Click) > AirBurst (Hold Shift) > AirBurst (Left Click)"); - + ArrayList iceWave = new ArrayList(); iceWave.add(new AbilityInformation("WaterSpout", ClickType.SHIFT_UP)); iceWave.add(new AbilityInformation("PhaseChange", ClickType.LEFT_CLICK)); comboAbilityList.add(new ComboAbility("IceWave", iceWave, WaterCombo.class)); descriptions.put("IceWave", "PhaseChange your WaterWave into an IceWave that freezes and damages enemies."); - instructions.put("IceWave", "Create a WaterSpout Wave > PhaseChange (Left Click)"); - - /*ArrayList icePillar = new ArrayList(); - icePillar.add(new AbilityInformation("IceSpike", ClickType.LEFT_CLICK)); - icePillar.add(new AbilityInformation("IceSpike", ClickType.LEFT_CLICK)); - icePillar.add(new AbilityInformation("WaterSpout", ClickType.LEFT_CLICK)); - comboAbilityList.add(new ComboAbility("IcePillar", icePillar, WaterCombo.class));*/ + instructions.put("IceWave", "Create a WaterSpout Wave > PhaseChange (Left Click)"); + + /* + * ArrayList icePillar = new + * ArrayList(); icePillar.add(new + * AbilityInformation("IceSpike", ClickType.LEFT_CLICK)); + * icePillar.add(new AbilityInformation("IceSpike", + * ClickType.LEFT_CLICK)); icePillar.add(new + * AbilityInformation("WaterSpout", ClickType.LEFT_CLICK)); + * comboAbilityList.add(new ComboAbility("IcePillar", icePillar, + * WaterCombo.class)); + */ ArrayList iceBullet = new ArrayList(); iceBullet.add(new AbilityInformation("WaterBubble", ClickType.SHIFT_DOWN)); @@ -136,8 +141,8 @@ public class ComboManager { iceBullet.add(new AbilityInformation("IceBlast", ClickType.LEFT_CLICK)); comboAbilityList.add(new ComboAbility("IceBullet", iceBullet, WaterCombo.class)); descriptions.put("IceBullet", "Using a large cavern of ice, you can punch ice shards at your opponent causing moderate damage. To rapid fire, you must alternate between Left clicking and right clicking with IceBlast."); - instructions.put("IceBullet", "WaterBubble (Tap Shift) > IceBlast (Hold Shift) > IceBlast (Left Click) > Wait for ice to Form > Then alternate between Left and Right click with IceBlast"); - + instructions.put("IceBullet", "WaterBubble (Tap Shift) > IceBlast (Hold Shift) > IceBlast (Left Click) > Wait for ice to Form > Then alternate between Left and Right click with IceBlast"); + ArrayList iceBulletLeft = new ArrayList(); iceBulletLeft.add(new AbilityInformation("IceBlast", ClickType.LEFT_CLICK)); comboAbilityList.add(new ComboAbility("IceBulletLeftClick", iceBulletLeft, WaterCombo.class)); @@ -219,18 +224,18 @@ public class ComboManager { Enumeration keys = recentlyUsedAbilities.keys(); while (keys.hasMoreElements()) { String name = keys.nextElement(); - ArrayList combos = recentlyUsedAbilities.get(name); + ArrayList usedAbilities = recentlyUsedAbilities.get(name); + ArrayList stillValidAbilities = new ArrayList(); recentlyUsedAbilities.remove(name); - for (int i = 0; i < combos.size(); i++) { - AbilityInformation info = combos.get(i); - if (System.currentTimeMillis() - info.getTime() > CLEANUP_DELAY) { - combos.remove(i); - i--; + + for (AbilityInformation info : usedAbilities) { + if (System.currentTimeMillis() - info.getTime() <= CLEANUP_DELAY) { + stillValidAbilities.add(info); } } - if (combos.size() > 0) - recentlyUsedAbilities.put(name, combos); + if (stillValidAbilities.size() > 0) + recentlyUsedAbilities.put(name, stillValidAbilities); } } @@ -248,11 +253,12 @@ public class ComboManager { tempList.add(0, list.get(list.size() - 1 - i)); return tempList; } - + public static ArrayList getCombosForElement(Element element) { ArrayList list = new ArrayList(); for (ComboAbility comboab : comboAbilityList) { - if (GeneralMethods.getComboElement(comboab.getName()) == element && descriptions.containsKey(comboab.getName())) list.add(comboab.getName()); + if (GeneralMethods.getComboElement(comboab.getName()) == element && descriptions.containsKey(comboab.getName())) + list.add(comboab.getName()); } Collections.sort(list); return list; @@ -263,7 +269,7 @@ public class ComboManager { public void run() { cleanupOldCombos(); } - }.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY); + }.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY / 1000 * 20); } public static class AbilityInformation {