From 6760985369e0540c337fa82a60accdd281b6d59e Mon Sep 17 00:00:00 2001 From: nathank33 Date: Wed, 11 Nov 2015 01:26:39 -0800 Subject: [PATCH] Decoreability Fire and Air --- .../projectkorra/airbending/AirBlast.java | 106 +++++++------- .../projectkorra/airbending/AirBubble.java | 27 ++-- .../projectkorra/firebending/FireBlast.java | 42 ++++-- .../firebending/Illumination.java | 1 - .../projectkorra/firebending/Lightning.java | 137 +++++++++--------- .../projectkorra/firebending/WallOfFire.java | 38 +++-- 6 files changed, 178 insertions(+), 173 deletions(-) diff --git a/src/com/projectkorra/projectkorra/airbending/AirBlast.java b/src/com/projectkorra/projectkorra/airbending/AirBlast.java index 9498eebd..a2923de0 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBlast.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBlast.java @@ -1,14 +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 com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; -import com.projectkorra.projectkorra.util.Flight; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Effect; import org.bukkit.Location; @@ -25,12 +19,17 @@ import org.bukkit.material.Lever; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; - -public class AirBlast 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.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(); public static double speed = config.get().getDouble("Abilities.Air.AirBlast.Speed"); @@ -38,13 +37,14 @@ public class AirBlast extends CoreAbility { public static double affectingradius = config.get().getDouble("Abilities.Air.AirBlast.Radius"); public static double defaultpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push.Entities"); public static double otherpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push.Self"); - + public static boolean flickLevers = config.get().getBoolean("Abilities.Air.AirBlast.CanFlickLevers"); public static boolean openDoors = config.get().getBoolean("Abilities.Air.AirBlast.CanOpenDoors"); public static boolean pressButtons = config.get().getBoolean("Abilities.Air.AirBlast.CanPressButtons"); public static boolean coolLava = config.get().getBoolean("Abilities.Air.AirBlast.CanCoolLava"); - + private static double originselectrange = 10; + private static int idCounter = 0; private static final int maxticks = 10000; /* Package visible variables */ static double maxspeed = 1. / defaultpushfactor; @@ -65,6 +65,7 @@ public class AirBlast extends CoreAbility { private boolean otherorigin = false; private boolean showParticles = true; private int ticks = 0; + private int id = 0; private ArrayList affectedlevers = new ArrayList(); private ArrayList affectedentities = new ArrayList(); @@ -76,8 +77,6 @@ public class AirBlast extends CoreAbility { if (location.getBlock().isLiquid()) { return; } - - //reloadVariables(); source = burst; this.player = player; @@ -85,8 +84,9 @@ public class AirBlast extends CoreAbility { this.direction = direction.clone(); this.location = location.clone(); pushfactor *= factorpush; - //instances.put(uuid, this); - putInstance(player, this); + instances.put(idCounter, this); + this.id = idCounter; + idCounter = (idCounter + 1) % Integer.MAX_VALUE; } public AirBlast(Player player) { @@ -98,7 +98,7 @@ public class AirBlast extends CoreAbility { return; } /* End Initial Checks */ - //reloadVariables(); + // reloadVariables(); this.player = player; if (origins.containsKey(player)) { otherorigin = true; @@ -115,8 +115,9 @@ public class AirBlast extends CoreAbility { direction = player.getEyeLocation().getDirection().normalize(); } location = origin.clone(); - putInstance(player, this); - //instances.put(uuid, this); + instances.put(idCounter, this); + this.id = idCounter; + idCounter = (idCounter + 1) % Integer.MAX_VALUE; bPlayer.addCooldown("AirBlast", GeneralMethods.getGlobalCooldown()); // time = System.currentTimeMillis(); @@ -137,7 +138,8 @@ public class AirBlast extends CoreAbility { return; } - if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBlast") || !GeneralMethods.canBend(player.getName(), "AirBlast")) { + if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBlast") + || !GeneralMethods.canBend(player.getName(), "AirBlast")) { origins.remove(player); return; } @@ -148,12 +150,14 @@ public class AirBlast extends CoreAbility { } AirMethods.playAirbendingParticles(origin, 4); - // 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.AirBlast); + for (AirBlast blast : instances.values()) { + blast.progress(); + } for (Player player : origins.keySet()) { playOriginEffect(player); } @@ -263,14 +267,9 @@ public class AirBlast extends CoreAbility { return this.showParticles; } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirBlast; - } - @SuppressWarnings("deprecation") public boolean progress() { - //ProjectKorra.log.info("FireBlast id: " + getID()); + // ProjectKorra.log.info("FireBlast id: " + getID()); if (player.isDead() || !player.isOnline()) { remove(); return false; @@ -296,9 +295,11 @@ public class AirBlast extends CoreAbility { testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0); } - if (GeneralMethods.isRegionProtectedFromBuild(getPlayer(), "AirBlast", block.getLocation())) continue; - - Material doorTypes[] = { Material.WOODEN_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR }; + if (GeneralMethods.isRegionProtectedFromBuild(getPlayer(), "AirBlast", block.getLocation())) + continue; + + Material doorTypes[] = { Material.WOODEN_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, + Material.ACACIA_DOOR, Material.DARK_OAK_DOOR }; if (Arrays.asList(doorTypes).contains(block.getType()) && openDoors) { if (block.getData() >= 8) { block = block.getRelative(BlockFace.DOWN); @@ -425,10 +426,9 @@ public class AirBlast extends CoreAbility { } /* - * If a player presses shift and AirBlasts straight down then the - * AirBlast's location gets messed up and reading the distance returns - * Double.NaN. If we don't remove this instance then the AirBlast will - * never be removed. + * If a player presses shift and AirBlasts straight down then the AirBlast's location gets + * messed up and reading the distance returns Double.NaN. If we don't remove this instance + * then the AirBlast will never be removed. */ double dist = location.distance(origin); if (Double.isNaN(dist) || dist > range) { @@ -443,28 +443,31 @@ public class AirBlast extends CoreAbility { advanceLocation(); return true; } - + public static boolean removeAirBlastsAroundPoint(Location location, double radius) { boolean removed = false; - for (Integer id : getInstances(StockAbility.AirBlast).keySet()) { - AirBlast airBlast = ((AirBlast)getAbility(id)); - Location airBlastlocation = airBlast.location; - if (location.getWorld() == airBlastlocation.getWorld()) { - if (location.distance(airBlastlocation) <= radius) - airBlast.remove(); - removed = true; + for (AirBlast airBlast : instances.values()) { + Location airBlastlocation = airBlast.location; + if (location.getWorld() == airBlastlocation.getWorld()) { + if (location.distance(airBlastlocation) <= radius) + airBlast.remove(); + removed = true; } } return removed; } + public void remove() { + instances.remove(id); + } + @Override public void reloadVariables() { speed = config.get().getDouble("Abilities.Air.AirBlast.Speed"); defaultrange = config.get().getDouble("Abilities.Air.AirBlast.Range"); affectingradius = config.get().getDouble("Abilities.Air.AirBlast.Radius"); defaultpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push"); - + flickLevers = config.get().getBoolean("Abilities.Air.AirBlast.CanFlickLevers"); openDoors = config.get().getBoolean("Abilities.Air.AirBlast.CanOpenDoors"); pressButtons = config.get().getBoolean("Abilities.Air.AirBlast.CanPressButtons"); @@ -490,9 +493,4 @@ public class AirBlast extends CoreAbility { this.showParticles = show; } - @Override - public InstanceType getInstanceType() { - return InstanceType.MULTIPLE; - } - } diff --git a/src/com/projectkorra/projectkorra/airbending/AirBubble.java b/src/com/projectkorra/projectkorra/airbending/AirBubble.java index 0a7dca80..e961d238 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBubble.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBubble.java @@ -16,7 +16,7 @@ import org.bukkit.entity.Player; import java.util.concurrent.ConcurrentHashMap; -public class AirBubble extends CoreAbility { +public class AirBubble implements ConfigLoadable { 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"); @@ -28,10 +28,10 @@ public class AirBubble extends CoreAbility { private ConcurrentHashMap waterorigins; public AirBubble(Player player) { - //reloadVariables(); + // reloadVariables(); this.player = player; waterorigins = new ConcurrentHashMap(); - //instances.put(uuid, this); + // instances.put(uuid, this); putInstance(player, this); } @@ -45,13 +45,16 @@ public class AirBubble extends CoreAbility { } public static String getDescription() { - return "To use, the bender must merely have the ability selected." + " All water around the user in a small bubble will vanish," + " replacing itself once the user either gets too far away or selects a different ability."; + return "To use, the bender must merely have the ability selected." + + " All water around the user in a small bubble will vanish," + + " replacing itself once the user either gets too far away or selects a different ability."; } public static void handleBubbles(Server server) { for (Player player : server.getOnlinePlayers()) { if (GeneralMethods.getBoundAbility(player) != null) { - if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") || GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble")) { + if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") + || GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble")) { if (!containsPlayer(player, AirBubble.class) && player.isSneaking()) { new AirBubble(player); } @@ -88,12 +91,6 @@ public class AirBubble extends CoreAbility { return radius; } - @Override - public StockAbility getStockAbility() { - return StockAbility.AirBubble; - } - - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { remove(); @@ -105,11 +102,13 @@ public class AirBubble extends CoreAbility { return false; } if (GeneralMethods.getBoundAbility(player) != null) { - if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") && GeneralMethods.canBend(player.getName(), "AirBubble")) { + if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") + && GeneralMethods.canBend(player.getName(), "AirBubble")) { pushWater(); return false; } - if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble") && GeneralMethods.canBend(player.getName(), "WaterBubble")) { + if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble") + && GeneralMethods.canBend(player.getName(), "WaterBubble")) { pushWater(); return false; } @@ -182,7 +181,7 @@ public class AirBubble extends CoreAbility { if (block.getType() == Material.AIR || block.isLiquid()) waterorigins.get(block).update(true); } - //instances.remove(uuid); + // instances.remove(uuid); super.remove(); } diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlast.java b/src/com/projectkorra/projectkorra/firebending/FireBlast.java index 9b5b222f..00583222 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlast.java @@ -28,7 +28,6 @@ import com.projectkorra.projectkorra.waterbending.WaterManipulation; import com.projectkorra.projectkorra.waterbending.WaterMethods; public class FireBlast implements ConfigLoadable { - public static ConcurrentHashMap instances = new ConcurrentHashMap<>(); private static double SPEED = config.get().getDouble("Abilities.Fire.FireBlast.Speed"); @@ -37,7 +36,7 @@ public class FireBlast implements ConfigLoadable { private static int DAMAGE = config.get().getInt("Abilities.Fire.FireBlast.Damage"); private static double fireticks = config.get().getDouble("Abilities.Fire.FireBlast.FireTicks"); private static int idCounter = 0; - + /* Package visible variables */ static boolean dissipate = config.get().getBoolean("Abilities.Fire.FireBlast.Dissipate"); /* End Package visible variables */ @@ -72,7 +71,7 @@ public class FireBlast implements ConfigLoadable { return; } /* End Initial Checks */ - //reloadVariables(); + // reloadVariables(); safe = safeblocks; range = FireMethods.getFirebendingDayAugment(range, player.getWorld()); // timers.put(player, System.currentTimeMillis()); @@ -95,7 +94,7 @@ public class FireBlast implements ConfigLoadable { return; } /* End Initial Checks */ - //reloadVariables(); + // reloadVariables(); range = FireMethods.getFirebendingDayAugment(range, player.getWorld()); this.player = player; location = player.getEyeLocation(); @@ -139,7 +138,14 @@ public class FireBlast implements ConfigLoadable { } public static String getDescription() { - return "FireBlast is the most fundamental bending technique of a firebender. " + "To use, simply left-click in a direction. A blast of fire will be created at your fingertips. " + "If this blast contacts an enemy, it will dissipate and engulf them in flames, " + "doing additional damage and knocking them back slightly. " + "If the blast hits terrain, it will ignite the nearby area. " + "Additionally, if you hold sneak, you will charge up the fireblast. " + "If you release it when it's charged, it will instead launch a powerful " + "fireball that explodes on contact."; + return "FireBlast is the most fundamental bending technique of a firebender. " + + "To use, simply left-click in a direction. A blast of fire will be created at your fingertips. " + + "If this blast contacts an enemy, it will dissipate and engulf them in flames, " + + "doing additional damage and knocking them back slightly. " + + "If the blast hits terrain, it will ignite the nearby area. " + + "Additionally, if you hold sneak, you will charge up the fireblast. " + + "If you release it when it's charged, it will instead launch a powerful " + + "fireball that explodes on contact."; } public static void removeFireBlastsAroundPoint(Location location, double radius) { @@ -155,7 +161,8 @@ public class FireBlast implements ConfigLoadable { private void advanceLocation() { if (showParticles) { - //ParticleEffect.RED_DUST.display((float) 16, (float) 111, (float) 227, 0.01F, 0, location, 256D); + // ParticleEffect.RED_DUST.display((float) 16, (float) 111, (float) 227, 0.01F, 0, + // location, 256D); ParticleEffect.FLAME.display(location, 0.275F, 0.275F, 0.275F, 0, 6); ParticleEffect.SMOKE.display(location, 0.3F, 0.3F, 0.3F, 0, 3); } @@ -174,7 +181,8 @@ public class FireBlast implements ConfigLoadable { } if (entity instanceof LivingEntity) { entity.setFireTicks((int) (fireticks * 20)); - GeneralMethods.damageEntity(player, entity, (int) FireMethods.getFirebendingDayAugment((double) damage, entity.getWorld()), "FireBlast"); + GeneralMethods.damageEntity(player, entity, + (int) FireMethods.getFirebendingDayAugment((double) damage, entity.getWorld()), "FireBlast"); AirMethods.breakBreathbendingHold(entity); new Enflamed(entity, player); remove(); @@ -213,15 +221,16 @@ public class FireBlast implements ConfigLoadable { private void ignite(Location location) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { if (FireStream.isIgnitable(player, block) && !safe.contains(block)) { - /*if (WaterMethods.isPlantbendable(block)) { - new Plantbending(block); - }*/ + /* + * if (WaterMethods.isPlantbendable(block)) { new Plantbending(block); } + */ if (FireMethods.canFireGrief()) { - if (WaterMethods.isPlantbendable(block)) new Plantbending(block); + if (WaterMethods.isPlantbendable(block)) + new Plantbending(block); block.setType(Material.FIRE); - } - else FireMethods.createTempFire(block.getLocation()); - //block.setType(Material.FIRE); + } else + FireMethods.createTempFire(block.getLocation()); + // block.setType(Material.FIRE); if (dissipate) { FireStream.ignitedblocks.put(block, player); FireStream.ignitedtimes.put(block, System.currentTimeMillis()); @@ -275,7 +284,8 @@ public class FireBlast implements ConfigLoadable { double radius = affectingradius; Player source = player; - if (EarthBlast.annihilateBlasts(location, radius, source) || WaterManipulation.annihilateBlasts(location, radius, source) || FireBlast.annihilateBlasts(location, radius, source)) { + if (EarthBlast.annihilateBlasts(location, radius, source) || WaterManipulation.annihilateBlasts(location, radius, source) + || FireBlast.annihilateBlasts(location, radius, source)) { remove(); return false; } @@ -301,7 +311,7 @@ public class FireBlast implements ConfigLoadable { return true; } - + public void remove() { instances.remove(id); } diff --git a/src/com/projectkorra/projectkorra/firebending/Illumination.java b/src/com/projectkorra/projectkorra/firebending/Illumination.java index 463b43bf..562b4137 100644 --- a/src/com/projectkorra/projectkorra/firebending/Illumination.java +++ b/src/com/projectkorra/projectkorra/firebending/Illumination.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.StockAbility; import com.projectkorra.projectkorra.configuration.ConfigLoadable; public class Illumination implements ConfigLoadable { diff --git a/src/com/projectkorra/projectkorra/firebending/Lightning.java b/src/com/projectkorra/projectkorra/firebending/Lightning.java index 6fef492a..88372ef2 100644 --- a/src/com/projectkorra/projectkorra/firebending/Lightning.java +++ b/src/com/projectkorra/projectkorra/firebending/Lightning.java @@ -1,13 +1,8 @@ package com.projectkorra.projectkorra.firebending; -import com.projectkorra.projectkorra.BendingManager; -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.earthbending.EarthMethods; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; @@ -19,10 +14,17 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.Arrays; +import com.projectkorra.projectkorra.BendingManager; +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; +import com.projectkorra.projectkorra.earthbending.EarthMethods; + +public class Lightning implements ConfigLoadable { + public static ConcurrentHashMap instances = new ConcurrentHashMap<>(); -public class Lightning extends CoreAbility { public static boolean SELF_HIT_WATER = config.get().getBoolean("Abilities.Fire.Lightning.SelfHitWater"); public static boolean SELF_HIT_CLOSE = config.get().getBoolean("Abilities.Fire.Lightning.SelfHitClose"); public static boolean ARC_ON_ICE = config.get().getBoolean("Abilities.Fire.Lightning.ArcOnIce"); @@ -40,13 +42,14 @@ public class Lightning extends CoreAbility { public static long CHARGETIME = (long) config.get().getDouble("Abilities.Fire.Lightning.ChargeTime"); public static long COOLDOWN = (long) config.get().getDouble("Abilities.Fire.Lightning.Cooldown"); private static final int POINT_GENERATION = 5; + private static int idCounter = 0; private Player player; private BendingPlayer bplayer; private Location origin, destination; - private double range, chargeTime, cooldown, subArcChance, damage, chainArcs, chainRange, - waterRange; + private int id; + private double range, chargeTime, cooldown, subArcChance, damage, chainArcs, chainRange, waterRange; private double chainArcChance, stunChance, stunDuration; private long time; private boolean charged, hitWater, hitIce; @@ -58,7 +61,7 @@ public class Lightning extends CoreAbility { private double newY; public Lightning(Player player) { - //reloadVariables(); + // reloadVariables(); this.player = player; bplayer = GeneralMethods.getBendingPlayer(player.getName()); charged = false; @@ -79,8 +82,8 @@ public class Lightning extends CoreAbility { if (AvatarState.isAvatarState(player)) { /* - * Some variables aren't considered here because it makes AS too - * overpowered and causes crashing. + * Some variables aren't considered here because it makes AS too overpowered and causes + * crashing. */ chargeTime = 0; cooldown = 0; @@ -93,14 +96,14 @@ public class Lightning extends CoreAbility { chargeTime = 0; cooldown = 0; } - //instances.add(this); - putInstance(player, this); + instances.put(idCounter, this); + this.id = idCounter; + idCounter = (idCounter + 1) % Integer.MAX_VALUE; } public static ArrayList getAllArcs() { ArrayList a = new ArrayList(); - for (Integer id : getInstances(StockAbility.Lightning).keySet()) { - Lightning light = (Lightning) getAbility(id); + for (Lightning light : instances.values()) { for (Arc arcs : light.getArcs()) { a.add(arcs); } @@ -115,8 +118,7 @@ public class Lightning extends CoreAbility { * @return the ability */ public static Lightning getLightning(Player player) { - for (Integer id : getInstances(StockAbility.Lightning).keySet()) { - Lightning light = (Lightning) getAbility(id); + for (Lightning light : instances.values()) { if (light.player == player) return light; } @@ -227,11 +229,6 @@ public class Lightning extends CoreAbility { return range; } - @Override - public StockAbility getStockAbility() { - return StockAbility.Lightning; - } - public double getStunChance() { return stunChance; } @@ -261,8 +258,7 @@ public class Lightning extends CoreAbility { } /** - * Checks if a block is transparent, also considers the ARC_ON_ICE config - * option. + * Checks if a block is transparent, also considers the ARC_ON_ICE config option. * * @param player the player that is viewing the block * @param block the block @@ -282,19 +278,18 @@ public class Lightning extends CoreAbility { } /** - * Progresses the instance of this ability by 1 tick. This is the heart of - * the ability, it checks if it needs to remove itself, and handles the - * initial Lightning Arc generation. + * Progresses the instance of this ability by 1 tick. This is the heart of the ability, it + * checks if it needs to remove itself, and handles the initial Lightning Arc generation. * - * Once all of the arcs have been created then this ability instance gets - * removed, but the BukkitRunnables continue until they remove themselves. + * Once all of the arcs have been created then this ability instance gets removed, but the + * BukkitRunnables continue until they remove themselves. **/ - @Override public boolean progress() { if (player.isDead() || !player.isOnline()) { removeWithTasks(); return false; - } else if (GeneralMethods.getBoundAbility(player) == null || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("Lightning")) { + } else if (GeneralMethods.getBoundAbility(player) == null + || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("Lightning")) { remove(); return false; } @@ -318,7 +313,8 @@ public class Lightning extends CoreAbility { if (target != null) destination = target.getLocation(); else - destination = player.getEyeLocation().add(player.getEyeLocation().getDirection().normalize().multiply(range)); + destination = player.getEyeLocation().add( + player.getEyeLocation().getDirection().normalize().multiply(range)); } } else { if (!player.isSneaking()) { @@ -355,7 +351,8 @@ public class Lightning extends CoreAbility { for (int j = 0; j < arc.getAnimLocs().size() - 1; j++) { final Location iterLoc = arc.getAnimLocs().get(j).getLoc().clone(); final Location dest = arc.getAnimLocs().get(j + 1).getLoc().clone(); - if (SELF_HIT_CLOSE && player.getLocation().distance(iterLoc) < 3 && !isTransparent(player, iterLoc.getBlock()) && !affectedEntities.contains(player)) { + if (SELF_HIT_CLOSE && player.getLocation().distance(iterLoc) < 3 + && !isTransparent(player, iterLoc.getBlock()) && !affectedEntities.contains(player)) { affectedEntities.add(player); electrocute(player); } @@ -378,6 +375,10 @@ public class Lightning extends CoreAbility { } return true; } + + public void remove() { + instances.remove(id); + } @Override public void reloadVariables() { @@ -473,9 +474,8 @@ public class Lightning extends CoreAbility { } /** - * Represents a Lightning Arc Point particle animation. This basically just - * holds a location and counts the amount of times that a particle has been - * animated. + * Represents a Lightning Arc Point particle animation. This basically just holds a location and + * counts the amount of times that a particle has been animated. * **/ public class AnimLocation { private Location loc; @@ -504,9 +504,9 @@ public class Lightning extends CoreAbility { } /** - * An Arc represents a Lightning arc for the specific ability. These Arcs - * contain a list of Particles that are used to display the entire arc. Arcs - * can also generate a list of subarcs that chain off of their own instance. + * An Arc represents a Lightning arc for the specific ability. These Arcs contain a list of + * Particles that are used to display the entire arc. Arcs can also generate a list of subarcs + * that chain off of their own instance. **/ public class Arc { private ArrayList points; @@ -543,9 +543,9 @@ public class Lightning extends CoreAbility { /** * Randomly generates subarcs off of this arc. * - * @param chance The chance that an arc will be generated for each - * specific point in the arc. Note: if you generate a lot of - * points then chance will need to be lowered. + * @param chance The chance that an arc will be generated for each specific point in the + * arc. Note: if you generate a lot of points then chance will need to be + * lowered. * @param range The length of each subarc. * **/ @@ -570,15 +570,14 @@ public class Lightning extends CoreAbility { } /** - * Runs an arc generation algorithm by first creating two points, the - * starting point and the ending point. Next, it creates a point in the - * middle that has an offset relative to the beginning and end points. - * Now that the arc is split into 3 points, we continue this processes - * by generating middle points in the two halfs of this arc. This - * process continues the amount of times specified. + * Runs an arc generation algorithm by first creating two points, the starting point and the + * ending point. Next, it creates a point in the middle that has an offset relative to the + * beginning and end points. Now that the arc is split into 3 points, we continue this + * processes by generating middle points in the two halfs of this arc. This process + * continues the amount of times specified. * - * @param times The amount of times that the arc will be split in half - * causes O(n^2) complexity + * @param times The amount of times that the arc will be split in half causes O(n^2) + * complexity **/ public void generatePoints(int times) { for (int i = 0; i < times; i++) { @@ -645,12 +644,11 @@ public class Lightning extends CoreAbility { } /** - * A Runnable Particle that continuously displays itself until it reaches a - * certain time limit. + * A Runnable Particle that continuously displays itself until it reaches a certain time limit. * - * These LightningParticles do the actual checking for player collision and - * handle damaging any entities. These Runnables also check to see if they - * reach water, in which case they will generate subarcs to branch out. + * These LightningParticles do the actual checking for player collision and handle damaging any + * entities. These Runnables also check to see if they reach water, in which case they will + * generate subarcs to branch out. * **/ public class LightningParticle extends BukkitRunnable { private Arc arc; @@ -670,8 +668,8 @@ public class Lightning extends CoreAbility { } /** - * Animates the Location, checks for water/player collision and also - * deals with any chain subarcs. + * Animates the Location, checks for water/player collision and also deals with any chain + * subarcs. */ public void run() { FireMethods.playLightningbendingParticle(loc, 0F, 0F, 0F); @@ -692,7 +690,9 @@ public class Lightning extends CoreAbility { for (int i = 0; i < WATER_ARCS; i++) { Location origin = loc.clone(); origin.add(new Vector((Math.random() - 0.5) * 2, 0, (Math.random() - 0.5) * 2)); - destination = origin.clone().add(new Vector((Math.random() - 0.5) * waterRange, Math.random() - 0.7, (Math.random() - 0.5) * waterRange)); + destination = origin.clone().add( + new Vector((Math.random() - 0.5) * waterRange, Math.random() - 0.7, (Math.random() - 0.5) + * waterRange)); Arc newArc = new Arc(origin, destination); newArc.generatePoints(POINT_GENERATION); arcs.add(newArc); @@ -701,11 +701,11 @@ public class Lightning extends CoreAbility { for (Entity entity : GeneralMethods.getEntitiesAroundPoint(loc, 2.5)) { /* - * If the player is in water we will electrocute them only - * if they are standing in water. If the lightning hit ice - * we can electrocute them all the time. + * If the player is in water we will electrocute them only if they are standing + * in water. If the lightning hit ice we can electrocute them all the time. */ - if (entity.equals(player) && !(SELF_HIT_WATER && hitWater && isWater(player.getLocation())) && !(SELF_HIT_WATER && hitIce)) + if (entity.equals(player) && !(SELF_HIT_WATER && hitWater && isWater(player.getLocation())) + && !(SELF_HIT_WATER && hitIce)) continue; if (entity instanceof LivingEntity && !affectedEntities.contains(entity)) { @@ -728,7 +728,8 @@ public class Lightning extends CoreAbility { if (chainArcs >= 1 && Math.random() <= chainArcChance) { chainArcs--; for (Entity ent : GeneralMethods.getEntitiesAroundPoint(lent.getLocation(), chainRange)) { - if (!ent.equals(player) && !ent.equals(lent) && ent instanceof LivingEntity && !affectedEntities.contains(ent)) { + if (!ent.equals(player) && !ent.equals(lent) && ent instanceof LivingEntity + && !affectedEntities.contains(ent)) { origin = lent.getLocation().add(0, 1, 0); destination = ent.getLocation().add(0, 1, 0); Arc newArc = new Arc(origin, destination); diff --git a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java index ab449d9a..9552080d 100644 --- a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java +++ b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java @@ -1,12 +1,8 @@ package com.projectkorra.projectkorra.firebending; -import com.projectkorra.projectkorra.BendingPlayer; -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.airbending.AirMethods; -import com.projectkorra.projectkorra.util.ParticleEffect; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.World; @@ -16,11 +12,16 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.List; - -public class WallOfFire extends CoreAbility { +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.AvatarState; +import com.projectkorra.projectkorra.airbending.AirMethods; +import com.projectkorra.projectkorra.configuration.ConfigLoadable; +import com.projectkorra.projectkorra.util.ParticleEffect; +public class WallOfFire implements ConfigLoadable { + public static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + private static double maxangle = 50; private static int RANGE = config.get().getInt("Abilities.Fire.WallOfFire.Range"); @@ -50,7 +51,7 @@ public class WallOfFire extends CoreAbility { public WallOfFire(Player player) { /* Initial Checks */ - if (containsPlayer(player, WallOfFire.class) && !AvatarState.isAvatarState(player)) { + if (instances.containsKey(player) && !AvatarState.isAvatarState(player)) { return; } BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); @@ -90,8 +91,7 @@ public class WallOfFire extends CoreAbility { initializeBlocks(); - //instances.put(player, this); - putInstance(player, this); + instances.put(player, this); bPlayer.addCooldown("WallOfFire", cooldown); } @@ -164,11 +164,6 @@ public class WallOfFire extends CoreAbility { return range; } - @Override - public StockAbility getStockAbility() { - return StockAbility.WallOfFire; - } - public int getWidth() { return width; } @@ -200,7 +195,6 @@ public class WallOfFire extends CoreAbility { } - @Override public boolean progress() { time = System.currentTimeMillis(); @@ -228,6 +222,10 @@ public class WallOfFire extends CoreAbility { } return true; } + + public void remove() { + instances.remove(player); + } @Override public void reloadVariables() {