diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 8d40b980..69685911 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -61,7 +61,6 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.ability.AvatarState; -import com.projectkorra.projectkorra.ability.api.CoreAbility; import com.projectkorra.projectkorra.ability.combo.ComboManager; import com.projectkorra.projectkorra.ability.multiability.MultiAbilityManager; import com.projectkorra.projectkorra.airbending.AirBlast; @@ -833,7 +832,7 @@ public class PKListener implements Listener { } if (e.getCause() == DamageCause.ENTITY_ATTACK && GeneralMethods.getBendingPlayer(sourceplayer.getName()).isElementToggled(Element.Chi) == true) { if (GeneralMethods.getBoundAbility(sourceplayer) != null && GeneralMethods.getBoundAbility(sourceplayer).equalsIgnoreCase("Paralyze") && e.getDamage() == 1) { - if (CoreAbility.getAbilitiesFromPlayer(sourceplayer).isEmpty()) { + if (sourceplayer.getWorld().equals(targetplayer.getWorld()) && Math.abs(sourceplayer.getLocation().distance(targetplayer.getLocation())) < 3) { new Paralyze(sourceplayer, targetplayer); } } diff --git a/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java new file mode 100644 index 00000000..45b5c35b --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/api/CoreAbility.java @@ -0,0 +1,333 @@ +package com.projectkorra.projectkorra.ability.api; + +import com.projectkorra.projectkorra.ability.StockAbility; + +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Represents the core of all ProjectKorra abilities and implements the + * {@link Ability} interface. + * + * @author jacklin213 + * @version 1.0.0 + */ +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 + * instance or {@link #getInstance(StockAbility)} from the outside. + */ + 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; + private Integer id; + + /** + * Convenience method to check if a player already has an instance of this + * ability. + * + * @param player The player to check + * @return true if instances contains the player + */ + public static final boolean containsPlayer(Player player, Class ability) { + CoreAbility coreAbility = getAbilityFromPlayer(player, ability); + return coreAbility != null ? true : false; + } + + /** + * Gets the list of ability instances that the player has created. + * + * @param player The player to get + * @return list of abilities + */ + public static List getAbilitiesFromPlayer(Player player) { + List abilities = new ArrayList<>(); + for (CoreAbility ability : instances.values()) { + if (ability.getPlayer().getUniqueId().equals(player.getUniqueId())) { + abilities.add(ability); + } + } + return abilities; + } + + /** + * Gets the ability instance of the player. + * + * @param player The player to get + * @param ability The ability class + * @return the ability instance or null + */ + public static CoreAbility getAbilityFromPlayer(Player player, Class ability) { + for (CoreAbility coreAbility : instances.values()) { + if (ability.isInstance(coreAbility)) { + if (coreAbility.getPlayer().getUniqueId().equals(player.getUniqueId())) { + return coreAbility; + } + } + } + return null; + } + + /** + * Gets the ability instance by its id. + * + * @param id The ability id to get + * @return the ability instance or null + */ + public static final CoreAbility getAbility(int id) { + return instances.get(id); + } + + /** + * 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. + * + * @param ability The instances map to get + * @return a map of instances from the specified {@link StockAbility} + * @see #getInstances(StockAbility) + */ + public final static ConcurrentHashMap getInstances(StockAbility ability) { + ConcurrentHashMap instanceMap = new ConcurrentHashMap<>(); + if (abilityMap.containsKey(ability)) { + for (Integer id : abilityMap.get(ability)) { + instanceMap.put(id, instances.get(id)); + } + } + return instanceMap; + } + + /** + * 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. + * + * @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 = classAbilityMap.get(ability.getClass()); + return instanceMap != null ? instanceMap : new ConcurrentHashMap(); + } + + //TODO: Update bending managers to use below method + // /** + // * Convenience method that calls {@link #progress()} for all instances. + // * + // * @see #progressAll(Class) + // * @see #progressAll(StockAbility) + // */ + // public static void progressAll() { + // for (Integer id : instances.keySet()) { + // instances.get(id).progress(); + // } + // } + + /** + * Convenience method that calls {@link #progress()} for all instances of a + * specified ability. + * + * @see #progressAll(StockAbility) + */ + public static void progressAll(Class ability) { + ConcurrentHashMap classAbilities = classAbilityMap.get(ability); + if (classAbilities != null) { + for (Integer id : classAbilities.keySet()) { + classAbilities.get(id).progress(); + } + } + } + + /** + * Convenience method that calls {@link #progress()} for all instances of a + * specified stock ability. + * + * @see #progressAll(Class) + */ + public static void progressAll(StockAbility ability) { + for (Integer id : getInstances(ability).keySet()) { + getInstances(ability).get(id).progress(); + } + } + + //TODO: Update bending managers to use below method + // /** + // * Convenience method that calls {@link #remove()} for all instances. + // * + // * @see #removeAll(StockAbility) + // * @see #removeAll(Class) + // */ + // public static void removeAll() { + // for (Integer id : instances.keySet()) { + // instances.get(id).remove(); + // } + // } + + /** + * Convenience method that calls {@link #remove()} for all instances of a + * specified stock ability. + * + * @see #removeAll(StockAbility) + */ + public static void removeAll(Class ability) { + for (Integer id : instances.keySet()) { + if (ability.isInstance(instances.get(id))) { + instances.get(id).remove(); + } + } + } + + /** + * Convenience method that calls {@link #remove()} for all instances of a + * specified ability. + * + * @see #removeAll(Class) + */ + public static void removeAll(StockAbility ability) { + for (Integer id : getInstances(ability).keySet()) { + getInstances(ability).get(id).remove(); + } + } + + /** + * Checks if ability is a {@link StockAbility} or not. + * + * @return true if ability is a stock ability + */ + public boolean isStockAbility() { + return getStockAbility() != null ? true : false; + } + + /** + * Gets the id of the ability instance. + * + * @return id of ability + */ + public int getID() { + return id; + } + + /** + * Convenience method to get instance for current ability class. + * + * @return instance of the current ability + */ + public CoreAbility getInstance() { + return instances.get(id); + } + + /** + * Gets the {@link Ability.InstanceType} of the ability. + * + * @return single by default + */ + public InstanceType getInstanceType() { + return InstanceType.SINGLE; + } + + /** + * Gets the player that invoked the ability. + * + * @return player + */ + public Player getPlayer() { + return player; + } + + /** + * Gets the {@link StockAbility} that created this instance. This method + * will return null for abilities that are not stock abilities + * + * @return StockAbility enum or null + */ + public abstract StockAbility getStockAbility(); + + /** + * Gets the {@link UUID} of the player that invoked this ability. + * + * @return the uuid of the player + */ + public UUID getUniqueId() { + return uniqueId; + } + + /** + * Put the instance of the ability into the instances map. + * + * @param player The player + * @param ability The ability involved + */ + protected final void putInstance(Player player, CoreAbility 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); + } else { + abilityMap.put(stockAbility, new ArrayList(Arrays.asList(id))); + } + } + + if (ID == Integer.MAX_VALUE) + ID = Integer.MIN_VALUE; + ID++; + } + + /** + * Calls {@link #removeInstance()}, Developers can override this method to + * do other things when remove is called but they MUST + * remember to call {@code super.remove()} for the ability to be properly + * removed from the {@link #instances}. + */ + @Override + public void remove() { + removeInstance(); + } + + /** + * Removes the ability instance from the instances map. + */ + private final void removeInstance() { + 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); + if (abilityMap.get(stockAbility).isEmpty()) { + abilityMap.remove(stockAbility); + } + } + } + } +} diff --git a/src/com/projectkorra/projectkorra/airbending/AirBlast.java b/src/com/projectkorra/projectkorra/airbending/AirBlast.java index a2923de0..4905d7d5 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBlast.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBlast.java @@ -29,6 +29,7 @@ import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; import com.projectkorra.projectkorra.util.Flight; public class AirBlast implements ConfigLoadable { + public static ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static ConcurrentHashMap origins = new ConcurrentHashMap(); @@ -460,6 +461,12 @@ public class AirBlast implements ConfigLoadable { public void remove() { instances.remove(id); } + + public static void removeAll() { + for (AirBlast ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/airbending/AirBubble.java b/src/com/projectkorra/projectkorra/airbending/AirBubble.java index e961d238..2e143105 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBubble.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBubble.java @@ -1,11 +1,6 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.waterbending.WaterManipulation; -import com.projectkorra.projectkorra.waterbending.WaterMethods; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; @@ -14,10 +9,14 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.entity.Player; -import java.util.concurrent.ConcurrentHashMap; +import com.projectkorra.projectkorra.Element; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.waterbending.WaterManipulation; +import com.projectkorra.projectkorra.waterbending.WaterMethods; public class AirBubble implements ConfigLoadable { - + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static double DEFAULT_AIR_RADIUS = config.get().getDouble("Abilities.Air.AirBubble.Radius"); private static double DEFAULT_WATER_RADIUS = config.get().getDouble("Abilities.Water.WaterBubble.Radius"); @@ -31,13 +30,12 @@ public class AirBubble implements ConfigLoadable { // reloadVariables(); this.player = player; waterorigins = new ConcurrentHashMap(); - // instances.put(uuid, this); - putInstance(player, this); + instances.put(player, this); } public static boolean canFlowTo(Block block) { - for (Integer id : getInstances(StockAbility.AirBubble).keySet()) { - if (((AirBubble) getAbility(id)).blockInBubble(block)) { + for (AirBubble airBubble : instances.values()) { + if (airBubble.blockInBubble(block)) { return false; } } @@ -55,14 +53,14 @@ public class AirBubble implements ConfigLoadable { if (GeneralMethods.getBoundAbility(player) != null) { if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") || GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble")) { - if (!containsPlayer(player, AirBubble.class) && player.isSneaking()) { + if (instances.containsKey(player) && player.isSneaking()) { new AirBubble(player); } } } } - CoreAbility.progressAll(StockAbility.AirBubble); + AirBubble.progressAll(); } public boolean blockInBubble(Block block) { @@ -156,9 +154,13 @@ public class AirBubble implements ConfigLoadable { block.setType(Material.AIR); } } - } - + } + + public static void progressAll() { + for (AirBubble ability : instances.values()) { + ability.progress(); + } } @Override @@ -182,7 +184,13 @@ public class AirBubble implements ConfigLoadable { waterorigins.get(block).update(true); } // instances.remove(uuid); - super.remove(); + instances.remove(player); + } + + public static void removeAll() { + for (AirBubble ability : instances.values()) { + ability.remove(); + } } public void setDefaultAirRadius(double defaultAirRadius) { diff --git a/src/com/projectkorra/projectkorra/airbending/AirBurst.java b/src/com/projectkorra/projectkorra/airbending/AirBurst.java index 99c98412..d90de3c5 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBurst.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBurst.java @@ -1,11 +1,7 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.AvatarState; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -13,10 +9,15 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.util.ArrayList; - -public class AirBurst extends CoreAbility { +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +public class AirBurst implements ConfigLoadable { + + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static double PARTICLES_PERCENTAGE = 50; private static double threshold = config.get().getDouble("Abilities.Air.AirBurst.FallThreshold"); @@ -41,7 +42,7 @@ public class AirBurst extends CoreAbility { BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); if (bPlayer.isOnCooldown("AirBurst")) return; - if (containsPlayer(player, AirBurst.class)) + if (instances.containsKey(player)) return; /* End Initial Checks */ //reloadVariables(); @@ -49,13 +50,12 @@ public class AirBurst extends CoreAbility { if (AvatarState.isAvatarState(player)) chargetime = 0; this.player = player; - //instances.put(player.getUniqueId(), this); - putInstance(player, this); + instances.put(player, this); } public static void coneBurst(Player player) { - if (containsPlayer(player, AirBurst.class)) { - ((AirBurst) getAbilityFromPlayer(player, AirBurst.class)).coneBurst(); + if (instances.containsKey(player)) { + instances.get(player).coneBurst(); } } @@ -69,7 +69,7 @@ public class AirBurst extends CoreAbility { if (GeneralMethods.getBoundAbility(player) == null) { return; } - if (containsPlayer(player, AirBurst.class)) { + if (instances.containsKey(player)) { return; } if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBurst")) { @@ -124,11 +124,6 @@ public class AirBurst extends CoreAbility { remove(); } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirBurst; - } - public void handleSmoothParticles() { for (int i = 0; i < blasts.size(); i++) { final AirBlast blast = blasts.get(i); @@ -147,7 +142,6 @@ public class AirBurst extends CoreAbility { return affectedentities.contains(entity); } - @Override public boolean progress() { if (!GeneralMethods.canBend(player.getName(), "AirBurst")) { remove(); @@ -182,10 +176,26 @@ public class AirBurst extends CoreAbility { // location, // Effect.SMOKE, // Methods.getIntCardinalDirection(player.getEyeLocation() - // .getDirection()), 3); + // .getDirection()), 3); } return true; } + + public static void progressAll() { + for (AirBurst ability : instances.values()) { + ability.progress(); + } + } + + public void remove() { + instances.remove(player); + } + + public static void removeAll() { + for (AirBurst ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/airbending/AirMethods.java b/src/com/projectkorra/projectkorra/airbending/AirMethods.java index 9bad24c8..6d9a2c90 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirMethods.java +++ b/src/com/projectkorra/projectkorra/airbending/AirMethods.java @@ -5,7 +5,6 @@ import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AbilityModuleManager; -import com.projectkorra.projectkorra.ability.StockAbility; import com.projectkorra.projectkorra.util.ParticleEffect; import org.bukkit.ChatColor; @@ -171,17 +170,16 @@ public class AirMethods { * Stops all airbending systems. SHOULD ONLY BE USED ON PLUGIN DISABLING! */ public static void stopBending() { - AirBlast.removeAll(StockAbility.AirBlast); - AirBubble.removeAll(StockAbility.AirBubble); - AirShield.removeAll(StockAbility.AirShield); - AirSuction.removeAll(StockAbility.AirSuction); - AirScooter.removeAll(StockAbility.AirScooter); - AirSpout.removeAll(StockAbility.AirSpout); - AirSwipe.removeAll(StockAbility.AirSwipe); - Tornado.removeAll(StockAbility.Tornado); - ; - AirBurst.removeAll(StockAbility.AirBurst); - Suffocate.removeAll(StockAbility.Suffocate); + AirBlast.removeAll(); + AirBubble.removeAll(); + AirShield.removeAll(); + AirSuction.removeAll(); + AirScooter.removeAll(); + AirSpout.removeAll(); + AirSwipe.removeAll(); + Tornado.removeAll(); + AirBurst.removeAll(); + Suffocate.removeAll(); AirCombo.removeAll(); FlightAbility.removeAll(); } diff --git a/src/com/projectkorra/projectkorra/airbending/AirScooter.java b/src/com/projectkorra/projectkorra/airbending/AirScooter.java index 544c3008..b8ad3404 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirScooter.java +++ b/src/com/projectkorra/projectkorra/airbending/AirScooter.java @@ -1,9 +1,7 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.util.Flight; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.block.Block; @@ -12,9 +10,13 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; -import java.util.ArrayList; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.util.Flight; -public class AirScooter extends CoreAbility { +public class AirScooter implements ConfigLoadable { + + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static double configSpeed = config.get().getDouble("Abilities.Air.AirScooter.Speed"); private static final long interval = 100; @@ -31,12 +33,13 @@ public class AirScooter extends CoreAbility { if (check(player)) { return; } - if (!player.isSprinting() || GeneralMethods.isSolid(player.getEyeLocation().getBlock()) || player.getEyeLocation().getBlock().isLiquid()) + if (!player.isSprinting() || GeneralMethods.isSolid(player.getEyeLocation().getBlock()) + || player.getEyeLocation().getBlock().isLiquid()) return; if (GeneralMethods.isSolid(player.getLocation().add(0, -.5, 0).getBlock())) return; /* End Initial Check */ - //reloadVariables(); + // reloadVariables(); this.player = player; // wasflying = player.isFlying(); // canfly = player.getAllowFlight(); @@ -48,9 +51,8 @@ public class AirScooter extends CoreAbility { for (int i = 0; i < 5; i++) { angles.add((double) (60 * i)); } - //instances.put(uuid, this); + instances.put(player, this); speed = configSpeed; - putInstance(player, this); progress(); } @@ -61,8 +63,8 @@ public class AirScooter extends CoreAbility { * @return false If player doesn't have an instance */ public static boolean check(Player player) { - if (containsPlayer(player, AirScooter.class)) { - getAbilityFromPlayer(player, AirScooter.class).remove(); + if (instances.containsKey(player)) { + instances.get(player).remove(); return true; } return false; @@ -70,8 +72,8 @@ public class AirScooter extends CoreAbility { public static ArrayList getPlayers() { ArrayList players = new ArrayList(); - for (Integer id : getInstances(StockAbility.AirScooter).keySet()) { - players.add(getAbility(id).getPlayer()); + for (AirScooter scooter : instances.values()) { + players.add(scooter.getPlayer()); } return players; } @@ -94,17 +96,11 @@ public class AirScooter extends CoreAbility { public double getSpeed() { return speed; } - + public void setSpeed(double value) { this.speed = value; // Used in PK Items } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirScooter; - } - - @Override public boolean progress() { getFloor(); // Methods.verbose(player); @@ -170,6 +166,12 @@ public class AirScooter extends CoreAbility { } return true; } + + public static void progressAll() { + for (AirScooter ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { @@ -177,14 +179,18 @@ public class AirScooter extends CoreAbility { this.speed = configSpeed; } - @Override public void remove() { - //instances.remove(uuid); - super.remove(); + instances.remove(player); player.setFlying(false); player.setAllowFlight(false); player.setSprinting(false); } + + public static void removeAll() { + for (AirScooter ability : instances.values()) { + ability.remove(); + } + } private void spinScooter() { Location origin = player.getLocation().clone(); @@ -194,8 +200,8 @@ public class AirScooter extends CoreAbility { double y = ((double) i) / 2 * scooterradius - scooterradius; double z = Math.sin(Math.toRadians(angles.get(i))) * scooterradius; AirMethods.playAirbendingParticles(origin.clone().add(x, y, z), 7); - // player.getWorld().playEffect(origin.clone().add(x, y, z), - // Effect.SMOKE, 4, (int) AirBlast.defaultrange); + // player.getWorld().playEffect(origin.clone().add(x, y, z), + // Effect.SMOKE, 4, (int) AirBlast.defaultrange); } for (int i = 0; i < 5; i++) { angles.set(i, angles.get(i) + 10); diff --git a/src/com/projectkorra/projectkorra/airbending/AirShield.java b/src/com/projectkorra/projectkorra/airbending/AirShield.java index 165ed076..4f585ac5 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirShield.java +++ b/src/com/projectkorra/projectkorra/airbending/AirShield.java @@ -1,13 +1,8 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.AvatarState; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.firebending.Combustion; -import com.projectkorra.projectkorra.firebending.FireBlast; -import com.projectkorra.projectkorra.firebending.FireStream; +import java.util.HashMap; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Effect; import org.bukkit.Location; @@ -17,11 +12,18 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.HashMap; -import java.util.Set; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.firebending.Combustion; +import com.projectkorra.projectkorra.firebending.FireBlast; +import com.projectkorra.projectkorra.firebending.FireStream; -public class AirShield extends CoreAbility { +public class AirShield implements ConfigLoadable { + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static double MAX_RADIUS = config.get().getDouble("Abilities.Air.AirShield.Radius"); private static boolean isToggle = config.get().getBoolean("Abilities.Air.AirShield.IsAvatarStateToggle"); private static int numberOfStreams = (int) (.75 * (double) MAX_RADIUS); @@ -35,9 +37,9 @@ public class AirShield extends CoreAbility { public AirShield(Player player) { /* Initial Check */ - if (AvatarState.isAvatarState(player) && containsPlayer(player, AirShield.class) && isToggle) { + if (AvatarState.isAvatarState(player) && instances.containsKey(player) && isToggle) { //instances.remove(player.getUniqueId()); - getAbilityFromPlayer(player, AirShield.class).remove(); + instances.get(player).remove(); return; } /* End Initial Check */ @@ -52,8 +54,7 @@ public class AirShield extends CoreAbility { angle = 0; } - //instances.put(player.getUniqueId(), this); - putInstance(player, this); + instances.put(player, this); } public static String getDescription() { @@ -61,8 +62,7 @@ public class AirShield extends CoreAbility { } public static boolean isWithinShield(Location loc) { - for (Integer id : getInstances(StockAbility.AirShield).keySet()) { - AirShield ashield = (AirShield) getAbility(id); + for (AirShield ashield : instances.values()) { if (ashield.player.getLocation().getWorld() != loc.getWorld()) return false; if (ashield.player.getLocation().distance(loc) <= ashield.radius) @@ -79,12 +79,6 @@ public class AirShield extends CoreAbility { return player; } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirShield; - } - - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); @@ -126,6 +120,22 @@ public class AirShield extends CoreAbility { rotateShield(); return true; } + + public static void progressAll() { + for (AirShield ability : instances.values()) { + ability.progress(); + } + } + + public void remove() { + instances.remove(player); + } + + public static void removeAll() { + for (AirShield ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/airbending/AirSpout.java b/src/com/projectkorra/projectkorra/airbending/AirSpout.java index 3021f9db..88b9f50b 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSpout.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSpout.java @@ -1,19 +1,21 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.util.Flight; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import java.util.ArrayList; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.util.Flight; -public class AirSpout extends CoreAbility { +public class AirSpout implements ConfigLoadable { + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static double HEIGHT = config.get().getDouble("Abilities.Air.AirSpout.Height"); private static final long interval = 100; @@ -24,8 +26,8 @@ public class AirSpout extends CoreAbility { public AirSpout(Player player) { /* Initial Check */ - if (containsPlayer(player, AirSpout.class)) { - getAbilityFromPlayer(player, AirSpout.class).remove(); + if (instances.containsKey(player)) { + instances.get(player).remove(); return; } /* End Initial Check */ @@ -33,23 +35,21 @@ public class AirSpout extends CoreAbility { this.player = player; time = System.currentTimeMillis(); new Flight(player); - //instances.put(player.getUniqueId(), this); - putInstance(player, this); + instances.put(player, this); progress(); } public static ArrayList getPlayers() { ArrayList players = new ArrayList(); - for (Integer id : getInstances(StockAbility.AirSpout).keySet()) { - players.add(getAbility(id).getPlayer()); + for (AirSpout spout : instances.values()) { + players.add(spout.getPlayer()); } return players; } public static boolean removeSpouts(Location loc0, double radius, Player sourceplayer) { boolean removed = false; - for (Integer id : getInstances(StockAbility.AirSpout).keySet()) { - Player player = getAbility(id).getPlayer(); + for (Player player : instances.keySet()) { if (!player.equals(sourceplayer)) { Location loc1 = player.getLocation().getBlock().getLocation(); loc0 = loc0.getBlock().getLocation(); @@ -60,7 +60,7 @@ public class AirSpout extends CoreAbility { double distance = Math.sqrt(dx * dx + dz * dz); if (distance <= radius && dy > 0 && dy < HEIGHT) { - getAbility(id).remove(); + instances.get(player).remove(); removed = true; } } @@ -93,12 +93,6 @@ public class AirSpout extends CoreAbility { return player; } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirSpout; - } - - @Override public boolean progress() { if (!GeneralMethods.canBend(player.getName(), "AirSpout") // || !Methods.hasAbility(player, Abilities.AirSpout) @@ -125,6 +119,12 @@ public class AirSpout extends CoreAbility { } return true; } + + public static void progressAll() { + for (AirSpout ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { @@ -132,11 +132,15 @@ public class AirSpout extends CoreAbility { height = HEIGHT; } - @Override public void remove() { removeFlight(); - //instances.remove(uuid); - super.remove(); + instances.remove(player); + } + + public static void removeAll() { + for (AirSpout ability : instances.values()) { + ability.remove(); + } } private void removeFlight() { diff --git a/src/com/projectkorra/projectkorra/airbending/AirSuction.java b/src/com/projectkorra/projectkorra/airbending/AirSuction.java index 21525986..b220d6e6 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSuction.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSuction.java @@ -1,16 +1,7 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.AvatarState; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.earthbending.EarthMethods; -import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; -import com.projectkorra.projectkorra.util.Flight; -import com.projectkorra.projectkorra.waterbending.WaterSpout; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Effect; import org.bukkit.Location; @@ -18,17 +9,26 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.earthbending.EarthMethods; +import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; +import com.projectkorra.projectkorra.util.Flight; +import com.projectkorra.projectkorra.waterbending.WaterSpout; -public class AirSuction extends CoreAbility { +public class AirSuction implements ConfigLoadable { + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static ConcurrentHashMap origins = new ConcurrentHashMap(); private static final double maxspeed = AirBlast.maxspeed; private static final int maxticks = 10000; - //private static long soonesttime = config.get().getLong("Properties.GlobalCooldown"); + // private static long soonesttime = config.get().getLong("Properties.GlobalCooldown"); private static double SPEED = config.get().getDouble("Abilities.Air.AirSuction.Speed"); private static double RANGE = config.get().getDouble("Abilities.Air.AirSuction.Range"); private static double RADIUS = config.get().getDouble("Abilities.Air.AirSuction.Radius"); @@ -60,10 +60,11 @@ public class AirSuction extends CoreAbility { if (player.getEyeLocation().getBlock().isLiquid()) { return; } - if (AirSpout.getPlayers().contains(player) || WaterSpout.getPlayers().contains(player)) + if (AirSpout.getPlayers().contains(player) || WaterSpout.getPlayers().contains(player)) { return; + } /* End Initial Check */ - //reloadVariables(); + // reloadVariables(); this.player = player; if (origins.containsKey(player)) { origin = origins.get(player); @@ -83,15 +84,17 @@ public class AirSuction extends CoreAbility { } // } - //instances.put(uuid, this); - putInstance(player, this); + instances.put(player, this); bPlayer.addCooldown("AirSuction", GeneralMethods.getGlobalCooldown()); // time = System.currentTimeMillis(); // timers.put(player, System.currentTimeMillis()); } public static String getDescription() { - return "To use, simply left-click in a direction. " + "A gust of wind will originate as far as it can in that direction" + " and flow towards you, sucking anything in its path harmlessly with it." + " Skilled benders can use this technique to pull items from precarious locations. " + "Additionally, tapping sneak will change the origin of your next " + "AirSuction to your targeted location."; + return "To use, simply left-click in a direction. " + "A gust of wind will originate as far as it can in that direction" + + " and flow towards you, sucking anything in its path harmlessly with it." + + " Skilled benders can use this technique to pull items from precarious locations. " + + "Additionally, tapping sneak will change the origin of your next " + "AirSuction to your targeted location."; } private static void playOriginEffect(Player player) { @@ -108,7 +111,8 @@ public class AirSuction extends CoreAbility { return; } - if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSuction") || !GeneralMethods.canBend(player.getName(), "AirSuction")) { + if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSuction") + || !GeneralMethods.canBend(player.getName(), "AirSuction")) { origins.remove(player); return; } @@ -120,12 +124,14 @@ public class AirSuction extends CoreAbility { AirMethods.playAirbendingParticles(origin, 6); // - // origin.getWorld().playEffect(origin, Effect.SMOKE, 4, - // (int) originselectrange); + // origin.getWorld().playEffect(origin, Effect.SMOKE, 4, + // (int) originselectrange); } public static void progressAll() { - CoreAbility.progressAll(StockAbility.AirSuction); + for (AirSuction ability : instances.values()) { + ability.progress(); + } for (Player player : origins.keySet()) { playOriginEffect(player); } @@ -151,8 +157,8 @@ public class AirSuction extends CoreAbility { if (GeneralMethods.rand.nextInt(4) == 0) { AirMethods.playAirbendingSound(location); } - // location.getWorld().playEffect(location, Effect.SMOKE, 4, - // (int) AirBlast.defaultrange); + // location.getWorld().playEffect(location, Effect.SMOKE, 4, + // (int) AirBlast.defaultrange); location = location.add(direction.clone().multiply(speedfactor)); } @@ -164,7 +170,8 @@ public class AirSuction extends CoreAbility { Location location = origin.clone(); for (double i = 1; i <= range; i++) { location = origin.clone().add(direction.clone().multiply(i)); - if (!EarthMethods.isTransparentToEarthbending(player, location.getBlock()) || GeneralMethods.isRegionProtectedFromBuild(player, "AirSuction", location)) { + if (!EarthMethods.isTransparentToEarthbending(player, location.getBlock()) + || GeneralMethods.isRegionProtectedFromBuild(player, "AirSuction", location)) { return origin.clone().add(direction.clone().multiply(i - 1)); } } @@ -187,12 +194,6 @@ public class AirSuction extends CoreAbility { return speed; } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirSuction; - } - - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); @@ -274,15 +275,24 @@ public class AirSuction extends CoreAbility { advanceLocation(); return true; } - + + public void remove() { + instances.remove(player); + } + + public static void removeAll() { + for (AirSuction ability : instances.values()) { + ability.remove(); + } + } + public static boolean removeAirSuctionsAroundPoint(Location location, double radius) { boolean removed = false; - for (Integer id : getInstances(StockAbility.AirSuction).keySet()) { - AirSuction airSuction = ((AirSuction)getAbility(id)); - Location airSuctionlocation = airSuction.location; - if (location.getWorld() == airSuctionlocation.getWorld()) { - if (location.distance(airSuctionlocation) <= radius) - airSuction.remove(); + for (AirSuction airSuction : instances.values()) { + Location airSuctionlocation = airSuction.location; + if (location.getWorld() == airSuctionlocation.getWorld()) { + if (location.distance(airSuctionlocation) <= radius) + airSuction.remove(); removed = true; } } @@ -316,9 +326,4 @@ public class AirSuction extends CoreAbility { public void setSpeed(double speed) { this.speed = speed; } - - @Override - public InstanceType getInstanceType() { - return InstanceType.MULTIPLE; - } } diff --git a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java index 1dd9177b..f9b500e0 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java @@ -1,19 +1,9 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.AvatarState; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.earthbending.EarthBlast; -import com.projectkorra.projectkorra.firebending.Combustion; -import com.projectkorra.projectkorra.firebending.FireBlast; -import com.projectkorra.projectkorra.firebending.Illumination; -import com.projectkorra.projectkorra.util.Flight; -import com.projectkorra.projectkorra.waterbending.WaterManipulation; -import com.projectkorra.projectkorra.waterbending.WaterMethods; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; @@ -24,13 +14,24 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - -public class AirSwipe extends CoreAbility { +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.earthbending.EarthBlast; +import com.projectkorra.projectkorra.firebending.Combustion; +import com.projectkorra.projectkorra.firebending.FireBlast; +import com.projectkorra.projectkorra.firebending.Illumination; +import com.projectkorra.projectkorra.util.Flight; +import com.projectkorra.projectkorra.waterbending.WaterManipulation; +import com.projectkorra.projectkorra.waterbending.WaterMethods; +public class AirSwipe implements ConfigLoadable { + + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static int stepsize = 4; private static int ARC = config.get().getInt("Abilities.Air.AirSwipe.Arc"); @@ -82,8 +83,7 @@ public class AirSwipe extends CoreAbility { origin = player.getEyeLocation(); time = System.currentTimeMillis(); - //instances.put(uuid, this); - putInstance(player, this); + instances.put(player, this); bPlayer.addCooldown("AirSwipe", ProjectKorra.plugin.getConfig().getLong("Abilities.Air.AirSwipe.Cooldown")); @@ -97,9 +97,7 @@ public class AirSwipe extends CoreAbility { public static boolean removeSwipesAroundPoint(Location loc, double radius) { boolean removed = false; - for (Integer id : getInstances(StockAbility.AirSwipe).keySet()) { - AirSwipe aswipe = (AirSwipe) getAbility(id); - + for (AirSwipe aswipe : instances.values()) { for (Vector vec : aswipe.elements.keySet()) { Location vectorLoc = aswipe.elements.get(vec); if (vectorLoc != null && vectorLoc.getWorld().equals(loc.getWorld())) { @@ -259,11 +257,6 @@ public class AirSwipe extends CoreAbility { return speed; } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirSwipe; - } - @SuppressWarnings("deprecation") private boolean isBlockBreakable(Block block) { Integer id = block.getTypeId(); @@ -293,7 +286,6 @@ public class AirSwipe extends CoreAbility { } } - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); @@ -339,7 +331,23 @@ public class AirSwipe extends CoreAbility { } return true; } + + public static void progressAll() { + for (AirSwipe ability : instances.values()) { + ability.progress(); + } + } + + public void remove() { + instances.remove(player); + } + public static void removeAll() { + for (AirSwipe ability : instances.values()) { + ability.remove(); + } + } + @Override public void reloadVariables() { ARC = config.get().getInt("Abilities.Air.AirSwipe.Arc"); diff --git a/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java b/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java index 1f336a62..70699b5e 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java +++ b/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java @@ -16,17 +16,17 @@ public class AirbendingManager implements Runnable { public void run() { AirBlast.progressAll(); AirPassive.handlePassive(Bukkit.getServer()); - AirBurst.progressAll(AirBurst.class); - AirScooter.progressAll(AirScooter.class); - Suffocate.progressAll(Suffocate.class); - AirSpout.progressAll(AirSpout.class); + AirBurst.progressAll(); + AirScooter.progressAll(); + Suffocate.progressAll(); + AirSpout.progressAll(); AirBubble.handleBubbles(Bukkit.getServer()); AirSuction.progressAll(); - AirSwipe.progressAll(AirSwipe.class); - Tornado.progressAll(Tornado.class); - AirShield.progressAll(AirShield.class); + AirSwipe.progressAll(); + Tornado.progressAll(); + AirShield.progressAll(); AirCombo.progressAll(); - FlightAbility.progressAll(FlightAbility.class); + FlightAbility.progressAll(); } } diff --git a/src/com/projectkorra/projectkorra/airbending/FlightAbility.java b/src/com/projectkorra/projectkorra/airbending/FlightAbility.java index 0a8cc2de..d8d42a48 100644 --- a/src/com/projectkorra/projectkorra/airbending/FlightAbility.java +++ b/src/com/projectkorra/projectkorra/airbending/FlightAbility.java @@ -1,16 +1,17 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.util.Flight; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.concurrent.ConcurrentHashMap; - -public class FlightAbility extends CoreAbility { +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.util.Flight; +public class FlightAbility implements ConfigLoadable { + + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static ConcurrentHashMap hits = new ConcurrentHashMap(); private static ConcurrentHashMap hovering = new ConcurrentHashMap(); private Player player; @@ -24,8 +25,7 @@ public class FlightAbility extends CoreAbility { player.setAllowFlight(true); player.setVelocity(player.getEyeLocation().getDirection().normalize()); this.player = player; - //instances.put(player.getUniqueId(), this); - putInstance(player, this); + instances.put(player, this); } public static void addHit(Player player) { @@ -42,7 +42,7 @@ public class FlightAbility extends CoreAbility { } public static boolean contains(Player player) { - return containsPlayer(player, FlightAbility.class); + return instances.containsKey(player); } public static boolean isHovering(Player player) { @@ -51,11 +51,13 @@ public class FlightAbility extends CoreAbility { public static void remove(Player player) { if (contains(player)) - getAbilityFromPlayer(player, FlightAbility.class).remove(); + instances.get(player).remove(); } public static void removeAll() { - CoreAbility.removeAll(StockAbility.Flight); + for (FlightAbility ability : instances.values()) { + ability.remove(); + } hits.clear(); hovering.clear(); } @@ -75,12 +77,6 @@ public class FlightAbility extends CoreAbility { } } - @Override - public StockAbility getStockAbility() { - return StockAbility.Flight; - } - - @Override public boolean progress() { if (!AirMethods.canFly(player, false, isHovering(player))) { remove(player); @@ -99,16 +95,20 @@ public class FlightAbility extends CoreAbility { } return true; } + + public static void progressAll() { + for (FlightAbility ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { } - @Override public void remove() { String name = player.getName(); - //instances.remove(uuid); - super.remove(); + instances.remove(player); hits.remove(name); hovering.remove(name); if (flight != null) diff --git a/src/com/projectkorra/projectkorra/airbending/Suffocate.java b/src/com/projectkorra/projectkorra/airbending/Suffocate.java index c0b7bb8a..bc967cbb 100644 --- a/src/com/projectkorra/projectkorra/airbending/Suffocate.java +++ b/src/com/projectkorra/projectkorra/airbending/Suffocate.java @@ -1,11 +1,8 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.AvatarState; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -15,10 +12,11 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; /** * Suffocate @@ -30,7 +28,9 @@ import java.util.concurrent.ConcurrentHashMap; * entities within a large radius. If the user is damaged while performing this * ability then the ability is removed. */ -public class Suffocate extends CoreAbility { +public class Suffocate implements ConfigLoadable { + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static boolean CAN_SUFFOCATE_UNDEAD = config.get().getBoolean("Abilities.Air.Suffocate.CanBeUsedOnUndeadMobs"); private static boolean REQUIRE_CONSTANT_AIM = config.get().getBoolean("Abilities.Air.Suffocate.RequireConstantAim"); private static double ANIM_RADIUS = config.get().getDouble("Abilities.Air.Suffocate.AnimationRadius"); @@ -96,8 +96,9 @@ public class Suffocate extends CoreAbility { blindDelay = BLIND_DELAY; blindRepeat = BLIND_INTERVAL; - if (containsPlayer(player, Suffocate.class)) + if (instances.containsKey(player)) { return; + } if (AvatarState.isAvatarState(player)) { cooldown = 0; @@ -140,28 +141,21 @@ public class Suffocate extends CoreAbility { else if (bplayer.isOnCooldown("suffocate")) return; bplayer.addCooldown("suffocate", cooldown); - //instances.put(player,this); - putInstance(player, this); + instances.put(player,this); } /** Stops an entity from being suffocated **/ public static void breakSuffocate(Entity entity) { - for (Integer id : getInstances().keySet()) { - Suffocate suffocate = (Suffocate) getAbility(id); + for (Suffocate suffocate : instances.values()) { if (suffocate.targets.contains(entity)) { suffocate.breakSuffocateLocal(entity); } } } - public static ConcurrentHashMap getInstances() { - return getInstances(StockAbility.Suffocate); - } - /** Checks if an entity is being suffocated **/ public static boolean isBreathbent(Entity entity) { - for (Integer id : getInstances().keySet()) { - Suffocate suffocate = (Suffocate) getAbility(id); + for (Suffocate suffocate : instances.values()) { if (suffocate.targets.contains(entity)) { return suffocate.started; } @@ -171,9 +165,7 @@ public class Suffocate extends CoreAbility { /** Determines if a player is Suffocating entities **/ public static boolean isChannelingSphere(Player player) { - if (containsPlayer(player, Suffocate.class)) - return true; - return false; + return instances.containsKey(player); } /** @@ -181,10 +173,17 @@ public class Suffocate extends CoreAbility { * entities **/ public static void remove(Player player) { - if (containsPlayer(player, Suffocate.class)) - getAbilityFromPlayer(player, Suffocate.class).remove(); + if (instances.containsKey(player)) { + instances.get(player).remove(); + } } + public static void removeAll() { + for (Suffocate ability : instances.values()) { + ability.remove(); + } + } + /** * Removes all instances of Suffocate at loc within the radius threshold. * The location of a Suffocate is defined at the benders location, not the @@ -193,15 +192,12 @@ public class Suffocate extends CoreAbility { * @param causer The player causing this instance to be removed **/ public static boolean removeAtLocation(Player causer, Location loc, double radius) { - Iterator it = getInstances().keySet().iterator(); - while (it.hasNext()) { - Integer key = it.next(); - Suffocate val = (Suffocate) getAbility(key); - - if (causer == null || !key.equals(causer)) { - Location playerLoc = val.getPlayer().getLocation(); + for (Player player : instances.keySet()) { + Suffocate suff = instances.get(player); + if (causer == null || !player.equals(causer)) { + Location playerLoc = suff.getPlayer().getLocation(); if (playerLoc.getWorld().equals(loc.getWorld()) && playerLoc.distance(loc) <= radius) { - it.remove(); + suff.remove(); return true; } } @@ -322,11 +318,6 @@ public class Suffocate extends CoreAbility { return speedFactor; } - @Override - public StockAbility getStockAbility() { - return StockAbility.Suffocate; - } - public ArrayList getTargets() { return targets; } @@ -449,6 +440,12 @@ public class Suffocate extends CoreAbility { } return true; } + + public static void progressAll() { + for (Suffocate ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { @@ -475,8 +472,7 @@ public class Suffocate extends CoreAbility { /** Removes this instance of the ability **/ public void remove() { - //instances.remove(player); - super.remove(); + instances.remove(player); for (int i = 0; i < tasks.size(); i++) { tasks.get(i).cancel(); tasks.remove(i); diff --git a/src/com/projectkorra/projectkorra/airbending/Tornado.java b/src/com/projectkorra/projectkorra/airbending/Tornado.java index a02ddd63..bb7e7482 100644 --- a/src/com/projectkorra/projectkorra/airbending/Tornado.java +++ b/src/com/projectkorra/projectkorra/airbending/Tornado.java @@ -1,10 +1,8 @@ package com.projectkorra.projectkorra.airbending; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; -import com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.util.Flight; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; @@ -12,11 +10,14 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.concurrent.ConcurrentHashMap; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.util.Flight; -public class Tornado extends CoreAbility { +public class Tornado implements ConfigLoadable { + + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static double MAX_HEIGHT = config.get().getDouble("Abilities.Air.Tornado.Height"); private static double PLAYER_PUSH_FACTOR = config.get().getDouble("Abilities.Air.Tornado.PlayerPushFactor"); @@ -60,14 +61,13 @@ public class Tornado extends CoreAbility { new Flight(player); player.setAllowFlight(true); - //instances.put(player.getEntityId(), this); - putInstance(player, this); + instances.put(player, this); } public static ArrayList getPlayers() { ArrayList players = new ArrayList(); - for (Integer id : getInstances(StockAbility.Tornado).keySet()) { - players.add(getAbility(id).getPlayer()); + for (Tornado tornado : instances.values()) { + players.add(tornado.getPlayer()); } return players; } @@ -96,12 +96,6 @@ public class Tornado extends CoreAbility { return range; } - @Override - public StockAbility getStockAbility() { - return StockAbility.Tornado; - } - - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); @@ -128,6 +122,22 @@ public class Tornado extends CoreAbility { rotateTornado(); return true; } + + public static void progressAll() { + for (Tornado ability : instances.values()) { + ability.progress(); + } + } + + public void remove() { + instances.remove(player); + } + + public static void removeAll() { + for (Tornado ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/earthbending/Catapult.java b/src/com/projectkorra/projectkorra/earthbending/Catapult.java index 939635c8..3b72e80d 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Catapult.java +++ b/src/com/projectkorra/projectkorra/earthbending/Catapult.java @@ -1,10 +1,7 @@ package com.projectkorra.projectkorra.earthbending; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.StockAbility; -import com.projectkorra.projectkorra.ability.api.CoreAbility; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.block.Block; @@ -12,9 +9,14 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.ArrayList; +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; -public class Catapult extends CoreAbility { +public class Catapult implements ConfigLoadable { + + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static int LENGTH = ProjectKorra.plugin.getConfig().getInt("Abilities.Earth.Catapult.Length"); private static double SPEED = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.Catapult.Speed"); @@ -38,7 +40,7 @@ public class Catapult extends CoreAbility { if (bplayer.isOnCooldown("Catapult")) return; /* End Initial Checks */ - //reloadVariables(); + // reloadVariables(); this.player = player; origin = player.getEyeLocation().clone(); direction = origin.getDirection().clone().normalize(); @@ -66,8 +68,7 @@ public class Catapult extends CoreAbility { distance = distance / 2; moving = true; - putInstance(player, this); - GeneralMethods.invincible.add(this); + instances.put(player, this); bplayer.addCooldown("Catapult", GeneralMethods.getGlobalCooldown()); } @@ -75,7 +76,7 @@ public class Catapult extends CoreAbility { public Catapult(Player player, Catapult source) { this.player = player; - //reloadVariables(); + // reloadVariables(); flying = true; moving = false; @@ -83,7 +84,7 @@ public class Catapult extends CoreAbility { direction = source.direction.clone(); distance = source.distance; - putInstance(player, this); + instances.put(player, this); EarthMethods.playEarthbendingSound(player.getLocation()); fly(); } @@ -99,8 +100,8 @@ public class Catapult extends CoreAbility { public static ArrayList getPlayers() { ArrayList players = new ArrayList(); - for (Integer id : getInstances(Catapult.class).keySet()) { - players.add(getAbility(id).getPlayer()); + for (Catapult cata : instances.values()) { + players.add(cata.getPlayer()); } return players; } @@ -149,11 +150,6 @@ public class Catapult extends CoreAbility { return speed; } - @Override - public StockAbility getStockAbility() { - return StockAbility.Catapult; - } - private boolean moveEarth() { location = location.clone().add(direction); if (catapult) { @@ -179,7 +175,6 @@ public class Catapult extends CoreAbility { return true; } - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); @@ -198,6 +193,18 @@ public class Catapult extends CoreAbility { remove(); return true; } + + public static void progressAll() { + for (Catapult ability : instances.values()) { + ability.progress(); + } + } + + public static void removeAll() { + for (Catapult ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { @@ -205,11 +212,9 @@ public class Catapult extends CoreAbility { SPEED = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.Catapult.Speed"); PUSH = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.Catapult.Push"); } - - @Override + public void remove() { - super.remove(); - GeneralMethods.invincible.remove(this); + instances.remove(player); } public void setLength(int length) { @@ -219,9 +224,9 @@ public class Catapult extends CoreAbility { public void setPush(double push) { this.push = push; } - + public void setSpeed(double speed) { this.speed = speed; } - + } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthMethods.java b/src/com/projectkorra/projectkorra/earthbending/EarthMethods.java index 27f2e90c..f5a36639 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthMethods.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthMethods.java @@ -636,7 +636,7 @@ public class EarthMethods { } public static void stopBending() { - Catapult.removeAll(Catapult.class); + Catapult.removeAll(); CompactColumn.removeAll(); EarthBlast.removeAll(); EarthColumn.removeAll(); diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java b/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java index e3908b4f..2e423754 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java @@ -20,7 +20,7 @@ public class EarthbendingManager implements Runnable { RevertChecker.revertEarthBlocks(); EarthTunnel.progressAll(); EarthArmor.moveArmorAll(); - Catapult.progressAll(Catapult.class); + Catapult.progressAll(); Tremorsense.manage(Bukkit.getServer()); EarthColumn.progressAll(); CompactColumn.progressAll(); diff --git a/src/com/projectkorra/projectkorra/firebending/Combustion.java b/src/com/projectkorra/projectkorra/firebending/Combustion.java index a8546fdd..1ea3f569 100644 --- a/src/com/projectkorra/projectkorra/firebending/Combustion.java +++ b/src/com/projectkorra/projectkorra/firebending/Combustion.java @@ -180,6 +180,12 @@ public class Combustion implements ConfigLoadable { advanceLocation(); return true; } + + public static void progressAll() { + for (Combustion ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/firebending/Cook.java b/src/com/projectkorra/projectkorra/firebending/Cook.java index 1e11be28..dba4450a 100644 --- a/src/com/projectkorra/projectkorra/firebending/Cook.java +++ b/src/com/projectkorra/projectkorra/firebending/Cook.java @@ -17,9 +17,8 @@ import com.projectkorra.projectkorra.util.ParticleEffect; public class Cook { public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static final long COOK_TIME = 2000; - private static final Material[] cookables = { Material.RAW_BEEF, - Material.RAW_CHICKEN, Material.RAW_FISH, Material.PORK, - Material.POTATO_ITEM, Material.RABBIT, Material.MUTTON }; + private static final Material[] cookables = { Material.RAW_BEEF, Material.RAW_CHICKEN, Material.RAW_FISH, Material.PORK, + Material.POTATO_ITEM, Material.RABBIT, Material.MUTTON }; private Player player; private ItemStack items; @@ -27,7 +26,7 @@ public class Cook { private long cooktime = COOK_TIME; public Cook(Player player) { - //reloadVariables(); + // reloadVariables(); this.player = player; items = player.getItemInHand(); time = System.currentTimeMillis(); @@ -86,7 +85,7 @@ public class Cook { cooked = new ItemStack(Material.COOKED_RABBIT); break; default: - break; //Shouldn't happen + break; // Shouldn't happen } return cooked; } @@ -137,6 +136,21 @@ public class Cook { return true; } + public static void progressAll() { + for (Cook ability : instances.values()) { + ability.progress(); + } + } + + public void remove() { + instances.remove(player); + } + + public static void removeAll() { + for (Cook ability : instances.values()) { + ability.remove(); + } + } public void setCooktime(long cooktime) { this.cooktime = cooktime; @@ -145,9 +159,5 @@ public class Cook { public void setTime(long time) { this.time = time; } - - public void remove() { - instances.remove(player); - } } \ No newline at end of file diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlast.java b/src/com/projectkorra/projectkorra/firebending/FireBlast.java index 00583222..0fae5065 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlast.java @@ -311,10 +311,22 @@ public class FireBlast implements ConfigLoadable { return true; } + + public static void progressAll() { + for (FireBlast ability : instances.values()) { + ability.progress(); + } + } public void remove() { instances.remove(id); } + + public static void removeAll() { + for (FireBlast ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/firebending/FireBurst.java b/src/com/projectkorra/projectkorra/firebending/FireBurst.java index 976b1768..b7a1d32f 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBurst.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBurst.java @@ -19,6 +19,7 @@ import com.projectkorra.projectkorra.ability.AvatarState; import com.projectkorra.projectkorra.configuration.ConfigLoadable; public class FireBurst implements ConfigLoadable { + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static double PARTICLES_PERCENTAGE = 5; @@ -115,6 +116,12 @@ public class FireBurst implements ConfigLoadable { public void remove() { instances.remove(player); } + + public static void removeAll() { + for (FireBurst ability : instances.values()) { + ability.remove(); + } + } /** * To combat the sphere FireBurst lag we are only going to show a certain @@ -165,6 +172,12 @@ public class FireBurst implements ConfigLoadable { } return true; } + + public static void progressAll() { + for (FireBurst ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/firebending/FireJet.java b/src/com/projectkorra/projectkorra/firebending/FireJet.java index cd7c258d..fd355aff 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireJet.java +++ b/src/com/projectkorra/projectkorra/firebending/FireJet.java @@ -11,6 +11,7 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.airbending.AirBurst; import com.projectkorra.projectkorra.configuration.ConfigLoadable; import com.projectkorra.projectkorra.util.Flight; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -116,6 +117,12 @@ public class FireJet implements ConfigLoadable { } return true; } + + public static void progressAll() { + for (FireJet ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { @@ -127,6 +134,12 @@ public class FireJet implements ConfigLoadable { public void remove() { instances.remove(player); } + + public static void removeAll() { + for (FireJet ability : instances.values()) { + ability.remove(); + } + } public void setDuration(long duration) { this.duration = duration; diff --git a/src/com/projectkorra/projectkorra/firebending/FireMethods.java b/src/com/projectkorra/projectkorra/firebending/FireMethods.java index c7c1ec5c..5d066bd7 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireMethods.java +++ b/src/com/projectkorra/projectkorra/firebending/FireMethods.java @@ -217,16 +217,16 @@ public class FireMethods { } public static void stopBending() { - FireStream.removeAll(FireStream.class); - Fireball.removeAll(Fireball.class); - WallOfFire.removeAll(WallOfFire.class); - Lightning.removeAll(Lightning.class); - FireShield.removeAll(FireShield.class); - FireBlast.removeAll(FireBlast.class); - FireBurst.removeAll(FireBurst.class); - FireJet.removeAll(FireJet.class); - Cook.removeAll(Cook.class); - Illumination.removeAll(Illumination.class); + FireStream.removeAll(); + Fireball.removeAll(); + WallOfFire.removeAll(); + Lightning.removeAll(); + FireShield.removeAll(); + FireBlast.removeAll(); + FireBurst.removeAll(); + FireJet.removeAll(); + Cook.removeAll(); + Illumination.removeAll(); FireCombo.removeAll(); for (Location loc : tempFire.keySet()){ revertTempFire(loc); diff --git a/src/com/projectkorra/projectkorra/firebending/FireShield.java b/src/com/projectkorra/projectkorra/firebending/FireShield.java index 42591c5a..34338302 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireShield.java +++ b/src/com/projectkorra/projectkorra/firebending/FireShield.java @@ -237,9 +237,21 @@ public class FireShield implements ConfigLoadable { return true; } + public static void progressAll() { + for (FireShield ability : instances.values()) { + ability.progress(); + } + } + public void remove() { instances.remove(player); } + + public static void removeAll() { + for (FireShield ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/firebending/FireStream.java b/src/com/projectkorra/projectkorra/firebending/FireStream.java index 3839c76b..5346398e 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireStream.java +++ b/src/com/projectkorra/projectkorra/firebending/FireStream.java @@ -185,6 +185,12 @@ public class FireStream implements ConfigLoadable { return false; } + public static void progressAll() { + for (FireStream ability : instances.values()) { + ability.progress(); + } + } + public void remove() { instances.remove(id); } diff --git a/src/com/projectkorra/projectkorra/firebending/Fireball.java b/src/com/projectkorra/projectkorra/firebending/Fireball.java index 6ba9baf6..21fc4648 100644 --- a/src/com/projectkorra/projectkorra/firebending/Fireball.java +++ b/src/com/projectkorra/projectkorra/firebending/Fireball.java @@ -332,8 +332,20 @@ public class Fireball implements ConfigLoadable { return true; } + public static void progressAll() { + for (Fireball ability : instances.values()) { + ability.progress(); + } + } + public void remove() { - instances.remove(this.id); + instances.remove(id); + } + + public static void removeAll() { + for (Fireball ability : instances.values()) { + ability.remove(); + } } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java b/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java index 85903fc2..1069fd91 100644 --- a/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java +++ b/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java @@ -15,25 +15,25 @@ public class FirebendingManager implements Runnable { public void run() { FirePassive.handlePassive(); - FireJet.progressAll(FireJet.class); - Cook.progressAll(Cook.class); - Illumination.progressAll(Illumination.class); - FireBlast.progressAll(FireBlast.class); - Fireball.progressAll(Fireball.class); - FireBurst.progressAll(FireBurst.class); - FireShield.progressAll(FireShield.class); - Lightning.progressAll(Lightning.class); - WallOfFire.progressAll(WallOfFire.class); - Combustion.progressAll(Combustion.class); + FireJet.progressAll(); + Cook.progressAll(); + Illumination.progressAll(); + FireBlast.progressAll(); + Fireball.progressAll(); + FireBurst.progressAll(); + FireShield.progressAll(); + Lightning.progressAll(); + WallOfFire.progressAll(); + Combustion.progressAll(); for (Block block : FireStream.ignitedblocks.keySet()) { if (block.getType() != Material.FIRE) { FireStream.ignitedblocks.remove(block); } } FireMethods.removeFire(); - HeatControl.progressAll(HeatControl.class); + HeatControl.progressAll(); FireStream.dissipateAll(); - FireStream.progressAll(FireStream.class); + FireStream.progressAll(); FireCombo.progressAll(); } } diff --git a/src/com/projectkorra/projectkorra/firebending/HeatControl.java b/src/com/projectkorra/projectkorra/firebending/HeatControl.java index c9e11399..733bb8c1 100644 --- a/src/com/projectkorra/projectkorra/firebending/HeatControl.java +++ b/src/com/projectkorra/projectkorra/firebending/HeatControl.java @@ -153,6 +153,12 @@ public class HeatControl implements ConfigLoadable { freeze(area); return true; } + + public static void progressAll() { + for (HeatControl ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/firebending/Illumination.java b/src/com/projectkorra/projectkorra/firebending/Illumination.java index 562b4137..25c18a68 100644 --- a/src/com/projectkorra/projectkorra/firebending/Illumination.java +++ b/src/com/projectkorra/projectkorra/firebending/Illumination.java @@ -82,6 +82,12 @@ public class Illumination implements ConfigLoadable { } return true; } + + public static void progressAll() { + for (Illumination ability : instances.values()) { + ability.progress(); + } + } @Override public void reloadVariables() { @@ -92,6 +98,12 @@ public class Illumination implements ConfigLoadable { revert(); instances.remove(player); } + + public static void removeAll() { + for (Illumination ability : instances.values()) { + ability.remove(); + } + } @SuppressWarnings("deprecation") private void revert() { diff --git a/src/com/projectkorra/projectkorra/firebending/Lightning.java b/src/com/projectkorra/projectkorra/firebending/Lightning.java index 88372ef2..516d524b 100644 --- a/src/com/projectkorra/projectkorra/firebending/Lightning.java +++ b/src/com/projectkorra/projectkorra/firebending/Lightning.java @@ -376,9 +376,21 @@ public class Lightning implements ConfigLoadable { return true; } + public static void progressAll() { + for (Lightning ability : instances.values()) { + ability.progress(); + } + } + public void remove() { instances.remove(id); } + + public static void removeAll() { + for (Lightning ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java index 9552080d..414a41ed 100644 --- a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java +++ b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java @@ -223,9 +223,21 @@ public class WallOfFire implements ConfigLoadable { return true; } + public static void progressAll() { + for (WallOfFire ability : instances.values()) { + ability.progress(); + } + } + public void remove() { instances.remove(player); } + + public static void removeAll() { + for (WallOfFire ability : instances.values()) { + ability.remove(); + } + } @Override public void reloadVariables() { diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterArms.java b/src/com/projectkorra/projectkorra/waterbending/WaterArms.java index 7212e391..5ab3448f 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterArms.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterArms.java @@ -341,8 +341,7 @@ public class WaterArms { } private void checkIfZapped() { - for (Integer id : Lightning.getInstances(Lightning.class).keySet()) { - Lightning l = (Lightning) Lightning.getInstances(Lightning.class).get(id); + for (Lightning l : Lightning.instances.values()) { for (Lightning.Arc arc : l.getArcs()) { for (Block arm : revert.keySet()) { for (Location loc : arc.getPoints()) {