valueMap) {
+ for (final Element element : Element.getMainElements()) {
+ valueMap.put(element.getName(), this.getPlayersWithElement(element));
}
return valueMap;
}
- private int getPlayersWithElement(Element element) {
+ private int getPlayersWithElement(final Element element) {
int counter = 0;
- for (Player player : Bukkit.getOnlinePlayers()) {
- BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
+ for (final Player player : Bukkit.getOnlinePlayers()) {
+ final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer != null && bPlayer.hasElement(element)) {
counter++;
}
@@ -156,20 +142,28 @@ private int getPlayersWithElement(Element element) {
}
});
- double cacheTime = ConfigManager.getConfig().getDouble("Properties.RegionProtection.CacheBlockTime");
+ final double cacheTime = ConfigManager.getConfig().getDouble("Properties.RegionProtection.CacheBlockTime");
if (Bukkit.getPluginManager().getPlugin("Residence") != null) {
FlagPermissions.addFlag(ConfigManager.defaultConfig.get().getString("Properties.RegionProtection.Residence.Flag"));
}
-
+
GeneralMethods.deserializeFile();
GeneralMethods.startCacheCleaner(cacheTime);
- updater.checkUpdate();
}
@Override
public void onDisable() {
GeneralMethods.stopBending();
- if (DBConnection.isOpen != false) {
+ for (final Player player : this.getServer().getOnlinePlayers()) {
+ if (isStatisticsEnabled()) {
+ statistics.save(player.getUniqueId(), false);
+ }
+ final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
+ if (bPlayer != null) {
+ bPlayer.saveCooldowns();
+ }
+ }
+ if (DBConnection.isOpen()) {
DBConnection.sql.close();
}
}
@@ -178,7 +172,7 @@ public static CollisionManager getCollisionManager() {
return collisionManager;
}
- public static void setCollisionManager(CollisionManager collisionManager) {
+ public static void setCollisionManager(final CollisionManager collisionManager) {
ProjectKorra.collisionManager = collisionManager;
}
@@ -186,8 +180,12 @@ public static CollisionInitializer getCollisionInitializer() {
return collisionInitializer;
}
- public static void setCollisionInitializer(CollisionInitializer collisionInitializer) {
+ public static void setCollisionInitializer(final CollisionInitializer collisionInitializer) {
ProjectKorra.collisionInitializer = collisionInitializer;
}
+ public static boolean isStatisticsEnabled() {
+ return ConfigManager.getConfig().getBoolean("Properties.Statistics");
+ }
+
}
diff --git a/src/com/projectkorra/projectkorra/ability/Ability.java b/src/com/projectkorra/projectkorra/ability/Ability.java
index 4936e6ed1..7e70fbd9a 100644
--- a/src/com/projectkorra/projectkorra/ability/Ability.java
+++ b/src/com/projectkorra/projectkorra/ability/Ability.java
@@ -14,7 +14,6 @@
import com.projectkorra.projectkorra.firebending.FireBlastCharged;
import com.projectkorra.projectkorra.firebending.FireBurst;
import com.projectkorra.projectkorra.waterbending.TorrentWave;
-import com.projectkorra.projectkorra.waterbending.passive.WaterPassive;
/**
* The Ability interface defines the set of methods that any CoreAbility,
@@ -23,7 +22,6 @@
* methods, but most will need to be specified by each Ability individually.
*/
public interface Ability {
-
/**
* Causes the ability to be updated.
*/
@@ -38,7 +36,7 @@ public interface Ability {
* Determines if this ability uses the {@link PlayerToggleSneakEvent} as a
* controlling mechanism. Currently {@link WaterPassive} will not work while
* the player has a sneak ability bound.
- *
+ *
* @return true if the ability uses sneak as a controlling mechanism
*/
public boolean isSneakAbility();
@@ -47,7 +45,7 @@ public interface Ability {
* Determines if this ability is considered harmless against other players.
* A harmless ability cannot manipulate another player. For example:
* AirPassive, WaterSpout, AirSpout, and FireJet.
- *
+ *
* @return true if the ability is harmless and should be allowed in both PvP
* and non-PvP zones
*/
@@ -69,7 +67,7 @@ public interface Ability {
* A hidden ability is an ability that should not be shown by commands such
* as /bending display and /bending help. For example: Combos,
* MultiAbility sub abilities, and helper abilities.
- *
+ *
* @return true if the ability should not be displayed to the players
*/
public boolean isHiddenAbility();
@@ -91,7 +89,7 @@ public interface Ability {
* can be null in certain circumstances, for example when calling
* {@link CoreAbility#getAbility(String)}, or if an ability decided to set
* player to null.
- *
+ *
* @return the player that this ability belongs to
*/
public Player getPlayer();
@@ -105,7 +103,7 @@ public interface Ability {
* the same name (SurgeWall/SurgeWave) but need to have independent
* cooldowns, then {@link BendingPlayer#addCooldown(String, long)} should be
* called explicitly.
- *
+ *
* @return Returns the name of the ability
*/
public String getName();
@@ -126,7 +124,7 @@ public interface Ability {
* player can fully utilize the ability. In most cases the description will
* be specified in the config.yml file and will be retrieved by accessing
* the FileConfiguration via {@link CoreAbility#getConfig}.
- *
+ *
* @return the description for this ability
* @see HelpCommand
* @see CoreAbility#getDescription()
@@ -137,7 +135,7 @@ public interface Ability {
* Specifies the Element used to represent this type of ability, favoring
* SubElements over Elements. For example, a LightningAbility would return
* {@link Element#LIGHTNING} instead of {@link Element#FIRE}.
- *
+ *
* @return the most accurate Element that this ability belongs to
* @see SubElement#getParentElement
*/
@@ -150,10 +148,9 @@ public interface Ability {
* while it is possible for an {@link EarthBlast}. The location is useful
* for making sure that the player is currently in the same world as the
* ability.
- *
+ *
* @return the location of the Ability
* @see BendingPlayer#canBend(CoreAbility)
*/
public Location getLocation();
-
}
diff --git a/src/com/projectkorra/projectkorra/ability/AirAbility.java b/src/com/projectkorra/projectkorra/ability/AirAbility.java
index 7b9e23d90..3e0ec60e9 100644
--- a/src/com/projectkorra/projectkorra/ability/AirAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/AirAbility.java
@@ -1,5 +1,14 @@
package com.projectkorra.projectkorra.ability;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
@@ -9,18 +18,9 @@
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.Sound;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-
-import java.util.ArrayList;
-import java.util.List;
-
public abstract class AirAbility extends ElementalAbility {
- public AirAbility(Player player) {
+ public AirAbility(final Player player) {
super(player);
}
@@ -40,10 +40,10 @@ public Element getElement() {
}
@Override
- public void handleCollision(Collision collision) {
+ public void handleCollision(final Collision collision) {
super.handleCollision(collision);
if (collision.isRemovingFirst()) {
- ParticleData particleData = (ParticleEffect.ParticleData) new ParticleEffect.BlockData(Material.WOOL, (byte) 0);
+ final ParticleData particleData = new ParticleEffect.BlockData(Material.WOOL, (byte) 0);
ParticleEffect.BLOCK_CRACK.display(particleData, 1F, 1F, 1F, 0.1F, 10, collision.getLocationFirst(), 50);
}
}
@@ -51,17 +51,17 @@ public void handleCollision(Collision collision) {
/**
* Breaks a breathbendng hold on an entity or one a player is inflicting on
* an entity.
- *
+ *
* @param entity The entity to be acted upon
*/
- public static void breakBreathbendingHold(Entity entity) {
+ public static void breakBreathbendingHold(final Entity entity) {
if (Suffocate.isBreathbent(entity)) {
Suffocate.breakSuffocate(entity);
return;
}
if (entity instanceof Player) {
- Player player = (Player) entity;
+ final Player player = (Player) entity;
if (Suffocate.isChannelingSphere(player)) {
Suffocate.remove(player);
}
@@ -70,11 +70,11 @@ public static void breakBreathbendingHold(Entity entity) {
/**
* Gets the Air Particles from the config.
- *
+ *
* @return Config specified ParticleEffect
*/
public static ParticleEffect getAirbendingParticles() {
- String particle = getConfig().getString("Properties.Air.Particles");
+ final String particle = getConfig().getString("Properties.Air.Particles");
if (particle == null) {
return ParticleEffect.CLOUD;
} else if (particle.equalsIgnoreCase("spell")) {
@@ -95,59 +95,61 @@ public static ParticleEffect getAirbendingParticles() {
* {@link Collision} for the new system.
*
* Checks whether a location is within an AirShield.
- *
+ *
* @param loc The location to check
* @return true If the location is inside an AirShield.
*/
@Deprecated
- public static boolean isWithinAirShield(Location loc) {
- List list = new ArrayList();
+ public static boolean isWithinAirShield(final Location loc) {
+ final List list = new ArrayList();
list.add("AirShield");
return GeneralMethods.blockAbilities(null, list, loc, 0);
}
/**
* Plays an integer amount of air particles in a location.
- *
+ *
* @param loc The location to use
* @param amount The amount of particles
*/
- public static void playAirbendingParticles(Location loc, int amount) {
+ public static void playAirbendingParticles(final Location loc, final int amount) {
playAirbendingParticles(loc, amount, (float) Math.random(), (float) Math.random(), (float) Math.random());
}
/**
* Plays an integer amount of air particles in a location with a given
* xOffset, yOffset, and zOffset.
- *
+ *
* @param loc The location to use
* @param amount The amount of particles
* @param xOffset The xOffset to use
* @param yOffset The yOffset to use
* @param zOffset The zOffset to use
*/
- public static void playAirbendingParticles(Location loc, int amount, float xOffset, float yOffset, float zOffset) {
+ public static void playAirbendingParticles(final Location loc, final int amount, final float xOffset, final float yOffset, final float zOffset) {
getAirbendingParticles().display(loc, xOffset, yOffset, zOffset, 0, amount);
}
/**
* Plays the Airbending Sound at a location if enabled in the config.
- *
+ *
* @param loc The location to play the sound at
*/
- public static void playAirbendingSound(Location loc) {
+ public static void playAirbendingSound(final Location loc) {
if (getConfig().getBoolean("Properties.Air.PlaySound")) {
- float volume = (float) getConfig().getDouble("Properties.Air.Sound.Volume");
- float pitch = (float) getConfig().getDouble("Properties.Air.Sound.Pitch");
+ final float volume = (float) getConfig().getDouble("Properties.Air.Sound.Volume");
+ final float pitch = (float) getConfig().getDouble("Properties.Air.Sound.Pitch");
Sound sound = Sound.ENTITY_CREEPER_HURT;
-
+
try {
sound = Sound.valueOf(getConfig().getString("Properties.Air.Sound.Sound"));
- } catch (IllegalArgumentException exception) {
+ }
+ catch (final IllegalArgumentException exception) {
ProjectKorra.log.warning("Your current value for 'Properties.Air.Sound.Sound' is not valid.");
- } finally {
- loc.getWorld().playSound(loc, sound, volume, pitch);
+ }
+ finally {
+ loc.getWorld().playSound(loc, sound, volume, pitch);
}
}
}
@@ -157,13 +159,13 @@ public static void playAirbendingSound(Location loc) {
* {@link Collision} for the new system.
*
* Removes all air spouts in a location within a certain radius.
- *
+ *
* @param loc The location to use
* @param radius The radius around the location to remove spouts in
* @param source The player causing the removal
*/
@Deprecated
- public static void removeAirSpouts(Location loc, double radius, Player source) {
+ public static void removeAirSpouts(final Location loc, final double radius, final Player source) {
AirSpout.removeSpouts(loc, radius, source);
}
@@ -172,13 +174,13 @@ public static void removeAirSpouts(Location loc, double radius, Player source) {
* {@link Collision} for the new system.
*
* Removes all air spouts in a location with a radius of 1.5.
- *
+ *
* @param loc The location to use
* @param source The player causing the removal
*/
@Deprecated
- public static void removeAirSpouts(Location loc, Player source) {
+ public static void removeAirSpouts(final Location loc, final Player source) {
removeAirSpouts(loc, 1.5, source);
}
-}
\ No newline at end of file
+}
diff --git a/src/com/projectkorra/projectkorra/ability/AvatarAbility.java b/src/com/projectkorra/projectkorra/ability/AvatarAbility.java
index 441a19534..112180c27 100644
--- a/src/com/projectkorra/projectkorra/ability/AvatarAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/AvatarAbility.java
@@ -1,15 +1,15 @@
package com.projectkorra.projectkorra.ability;
-import com.projectkorra.projectkorra.Element;
-import com.projectkorra.projectkorra.ProjectKorra;
-
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
+import com.projectkorra.projectkorra.Element;
+import com.projectkorra.projectkorra.ProjectKorra;
+
public abstract class AvatarAbility extends ElementalAbility {
- public AvatarAbility(Player player) {
+ public AvatarAbility(final Player player) {
super(player);
}
@@ -28,19 +28,21 @@ public final Element getElement() {
return Element.AVATAR;
}
- public static void playAvatarSound(Location loc) {
+ public static void playAvatarSound(final Location loc) {
if (getConfig().getBoolean("Abilities.Avatar.AvatarState.PlaySound")) {
- float volume = (float) getConfig().getDouble("Abilities.Avatar.AvatarState.Sound.Volume");
- float pitch = (float) getConfig().getDouble("Abilities.Avatar.AvatarState.Sound.Pitch");
-
+ final float volume = (float) getConfig().getDouble("Abilities.Avatar.AvatarState.Sound.Volume");
+ final float pitch = (float) getConfig().getDouble("Abilities.Avatar.AvatarState.Sound.Pitch");
+
Sound sound = Sound.BLOCK_ANVIL_LAND;
-
+
try {
- sound = Sound.valueOf(getConfig().getString("Properties.Avatar.AvatarState.Sound.Sound"));
- } catch (IllegalArgumentException exception) {
- ProjectKorra.log.warning("Your current value for 'Properties.Avatar.AvatarState.Sound.Sound' is not valid.");
- } finally {
- loc.getWorld().playSound(loc, sound, volume, pitch);
+ sound = Sound.valueOf(getConfig().getString("Abilities.Avatar.AvatarState.Sound.Sound"));
+ }
+ catch (final IllegalArgumentException exception) {
+ ProjectKorra.log.warning("Your current value for 'Abilities.Avatar.AvatarState.Sound.Sound' is not valid.");
+ }
+ finally {
+ loc.getWorld().playSound(loc, sound, volume, pitch);
}
}
}
@@ -54,4 +56,4 @@ public boolean requireAvatar() {
return true;
}
-}
\ No newline at end of file
+}
diff --git a/src/com/projectkorra/projectkorra/ability/BloodAbility.java b/src/com/projectkorra/projectkorra/ability/BloodAbility.java
index 36609ff30..7c7d48ffc 100644
--- a/src/com/projectkorra/projectkorra/ability/BloodAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/BloodAbility.java
@@ -1,12 +1,12 @@
package com.projectkorra.projectkorra.ability;
-import com.projectkorra.projectkorra.Element;
-
import org.bukkit.entity.Player;
+import com.projectkorra.projectkorra.Element;
+
public abstract class BloodAbility extends WaterAbility implements SubAbility {
- public BloodAbility(Player player) {
+ public BloodAbility(final Player player) {
super(player);
}
diff --git a/src/com/projectkorra/projectkorra/ability/ChiAbility.java b/src/com/projectkorra/projectkorra/ability/ChiAbility.java
index 8c975a9a5..49a582664 100644
--- a/src/com/projectkorra/projectkorra/ability/ChiAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/ChiAbility.java
@@ -1,12 +1,12 @@
package com.projectkorra.projectkorra.ability;
-import com.projectkorra.projectkorra.Element;
-
import org.bukkit.entity.Player;
+import com.projectkorra.projectkorra.Element;
+
public abstract class ChiAbility extends ElementalAbility {
- public ChiAbility(Player player) {
+ public ChiAbility(final Player player) {
super(player);
}
diff --git a/src/com/projectkorra/projectkorra/ability/ComboAbility.java b/src/com/projectkorra/projectkorra/ability/ComboAbility.java
index 151933910..1c6c98eba 100644
--- a/src/com/projectkorra/projectkorra/ability/ComboAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/ComboAbility.java
@@ -1,10 +1,10 @@
package com.projectkorra.projectkorra.ability;
-import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation;
+import java.util.ArrayList;
import org.bukkit.entity.Player;
-import java.util.ArrayList;
+import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation;
public interface ComboAbility {
@@ -22,5 +22,4 @@ public interface ComboAbility {
* @return An ArrayList containing the combo's steps.
*/
public abstract ArrayList getCombination();
-
}
diff --git a/src/com/projectkorra/projectkorra/ability/CombustionAbility.java b/src/com/projectkorra/projectkorra/ability/CombustionAbility.java
index 80bac3dbf..786385ce0 100644
--- a/src/com/projectkorra/projectkorra/ability/CombustionAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/CombustionAbility.java
@@ -1,12 +1,12 @@
package com.projectkorra.projectkorra.ability;
-import com.projectkorra.projectkorra.Element;
-
import org.bukkit.entity.Player;
+import com.projectkorra.projectkorra.Element;
+
public abstract class CombustionAbility extends FireAbility implements SubAbility {
- public CombustionAbility(Player player) {
+ public CombustionAbility(final Player player) {
super(player);
}
diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java
index 5b43cc7b6..dc41014f1 100644
--- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java
+++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java
@@ -53,7 +53,7 @@
* For {@link CollisionManager} and {@link Collision}, a CoreAbility may need to
* override {@link #isCollidable()}, {@link #getCollisionRadius()},
* {@link #handleCollision(Collision)}, and {@link #getLocations()}.
- *
+ *
* @see #start()
* @see #progress()
* @see #remove()
@@ -65,7 +65,7 @@ public abstract class CoreAbility implements Ability {
private static final Set INSTANCES = Collections.newSetFromMap(new ConcurrentHashMap());
private static final Map, Map>> INSTANCES_BY_PLAYER = new ConcurrentHashMap<>();
private static final Map, Set> INSTANCES_BY_CLASS = new ConcurrentHashMap<>();
- private static final Map ABILITIES_BY_NAME = new ConcurrentSkipListMap<>(); // preserves ordering
+ private static final Map ABILITIES_BY_NAME = new ConcurrentSkipListMap<>(); // preserves ordering.
private static final Map, CoreAbility> ABILITIES_BY_CLASS = new ConcurrentHashMap<>();
private static final double DEFAULT_COLLISION_RADIUS = 0.3;
private static final List ADDON_PLUGINS = new ArrayList<>();
@@ -93,7 +93,7 @@ public abstract class CoreAbility implements Ability {
* getDeclaredConstructor which is only usable with a public default
* constructor. Reflection lets us create a list of all of the plugin's
* abilities when the plugin first loads.
- *
+ *
* @see #ABILITIES_BY_NAME
* @see #getAbility(String)
*/
@@ -102,12 +102,12 @@ public CoreAbility() {
/**
* Creates a new CoreAbility instance but does not start it.
- *
+ *
* @param player the non-null player that created this instance
* @see #start()
*/
- public CoreAbility(Player player) {
- if (player == null) {
+ public CoreAbility(final Player player) {
+ if (player == null || !this.isEnabled()) {
return;
}
@@ -116,7 +116,7 @@ public CoreAbility(Player player) {
this.startTime = System.currentTimeMillis();
this.started = false;
this.id = CoreAbility.idCounter;
- this.startTick = getCurrentTick();
+ this.startTick = this.getCurrentTick();
if (idCounter == Integer.MAX_VALUE) {
idCounter = Integer.MIN_VALUE;
@@ -130,25 +130,25 @@ public CoreAbility(Player player) {
* {@link #progress()} until {@link #remove()} is called. This method cannot
* be overridden, and any code that needs to be performed before start
* should be handled in the constructor.
- *
+ *
* @see #getStartTime()
* @see #isStarted()
* @see #isRemoved()
*/
- public final void start() {
- if (player == null) {
+ public void start() {
+ if (this.player == null || !this.isEnabled()) {
return;
}
- AbilityStartEvent event = new AbilityStartEvent(this);
+ final AbilityStartEvent event = new AbilityStartEvent(this);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
- remove();
+ this.remove();
return;
}
this.started = true;
this.startTime = System.currentTimeMillis();
- Class extends CoreAbility> clazz = getClass();
- UUID uuid = player.getUniqueId();
+ final Class extends CoreAbility> clazz = this.getClass();
+ final UUID uuid = this.player.getUniqueId();
if (!INSTANCES_BY_PLAYER.containsKey(clazz)) {
INSTANCES_BY_PLAYER.put(clazz, new ConcurrentHashMap>());
@@ -169,37 +169,37 @@ public final void start() {
* Causes this CoreAbility instance to be removed, and {@link #progress}
* will no longer be called every tick. If this method is overridden then
* the new method must call super.remove().
- *
+ *
* {@inheritDoc}
- *
+ *
* @see #isRemoved()
*/
@Override
public void remove() {
- if (player == null) {
+ if (this.player == null) {
return;
}
Bukkit.getServer().getPluginManager().callEvent(new AbilityEndEvent(this));
- removed = true;
+ this.removed = true;
- Map> classMap = INSTANCES_BY_PLAYER.get(getClass());
+ final Map> classMap = INSTANCES_BY_PLAYER.get(this.getClass());
if (classMap != null) {
- Map playerMap = classMap.get(player.getUniqueId());
+ final Map playerMap = classMap.get(this.player.getUniqueId());
if (playerMap != null) {
playerMap.remove(this.id);
if (playerMap.size() == 0) {
- classMap.remove(player.getUniqueId());
+ classMap.remove(this.player.getUniqueId());
}
}
if (classMap.size() == 0) {
- INSTANCES_BY_PLAYER.remove(getClass());
+ INSTANCES_BY_PLAYER.remove(this.getClass());
}
}
- if (INSTANCES_BY_CLASS.containsKey(getClass())) {
- INSTANCES_BY_CLASS.get(getClass()).remove(this);
+ if (INSTANCES_BY_CLASS.containsKey(this.getClass())) {
+ INSTANCES_BY_CLASS.get(this.getClass()).remove(this);
}
INSTANCES.remove(this);
}
@@ -209,28 +209,37 @@ public void remove() {
* that has been started and has not been removed.
*/
public static void progressAll() {
- for (Set setAbils : INSTANCES_BY_CLASS.values()) {
- for (CoreAbility abil : setAbils) {
+ for (final Set setAbils : INSTANCES_BY_CLASS.values()) {
+ for (final CoreAbility abil : setAbils) {
if (abil instanceof PassiveAbility) {
- BendingPlayer bPlayer = abil.getBendingPlayer();
- if (bPlayer == null || !abil.getPlayer().isOnline()) {
- abil.remove();
+ if (!((PassiveAbility) abil).isProgressable()) {
continue;
- } else if (!bPlayer.canBendPassive(abil.getElement())) { // Check for if the passive should be removed
- abil.remove();
+ }
+
+ if (!abil.getPlayer().isOnline()) { // This has to be before isDead as isDead.
+ abil.remove(); // will return true if they are offline.
continue;
- } else if (!bPlayer.canUsePassive(abil.getElement())) { // Check for if the passive should be prevented from happening, but not remove it
+ } else if (abil.getPlayer().isDead()) {
continue;
}
+ } else if (abil.getPlayer().isDead()) {
+ abil.remove();
+ continue;
+ } else if (!abil.getPlayer().isOnline()) {
+ abil.remove();
+ continue;
}
+
try {
abil.progress();
Bukkit.getServer().getPluginManager().callEvent(new AbilityProgressEvent(abil));
- } catch (Exception e) {
+ }
+ catch (final Exception e) {
e.printStackTrace();
try {
abil.remove();
- } catch (Exception re) {
+ }
+ catch (final Exception re) {
re.printStackTrace();
}
}
@@ -243,15 +252,15 @@ public static void progressAll() {
* removed.
*/
public static void removeAll() {
- for (Set setAbils : INSTANCES_BY_CLASS.values()) {
- for (CoreAbility abil : setAbils) {
+ for (final Set setAbils : INSTANCES_BY_CLASS.values()) {
+ for (final CoreAbility abil : setAbils) {
abil.remove();
}
}
- for (CoreAbility coreAbility : ABILITIES_BY_NAME.values()) {
+ for (final CoreAbility coreAbility : ABILITIES_BY_NAME.values()) {
if (coreAbility instanceof AddonAbility) {
- AddonAbility addon = (AddonAbility) coreAbility;
+ final AddonAbility addon = (AddonAbility) coreAbility;
addon.stop();
}
}
@@ -260,13 +269,13 @@ public static void removeAll() {
/**
* Returns any T CoreAbility that has been started and not yet removed. May
* return null if no such ability exists.
- *
+ *
* @param player the player that created the CoreAbility instance
* @param clazz the class of the type of CoreAbility
* @return a CoreAbility instance or null
*/
- public static T getAbility(Player player, Class clazz) {
- Collection abils = getAbilities(player, clazz);
+ public static T getAbility(final Player player, final Class clazz) {
+ final Collection abils = getAbilities(player, clazz);
if (abils.iterator().hasNext()) {
return abils.iterator().next();
}
@@ -279,30 +288,30 @@ public static T getAbility(Player player, Class clazz
* Players, instead this method looks at the CoreAbilities that were created
* via Reflection by {@link #registerAbilities()} when the plugin was first
* loaded.
- *
+ *
*
* These "fake" instances have a null player, but methods such as
* {@link Ability#getName()}, and {@link Ability#getElement()} will still
* work, as will checking the type of the ability with instanceof.
- *
+ *
*
* CoreAbility coreAbil = getAbility(someString);
* if (coreAbil instanceof FireAbility && coreAbil.isSneakAbility())
- *
+ *
* @param abilityName the name of a loaded CoreAbility
* @return a "fake" CoreAbility instance, or null if no such ability exists
*/
- public static CoreAbility getAbility(String abilityName) {
+ public static CoreAbility getAbility(final String abilityName) {
return abilityName != null ? ABILITIES_BY_NAME.get(abilityName.toLowerCase()) : null;
}
/**
* Returns a "fake" instance for a CoreAbility with the specific class.
- *
+ *
* @param clazz the class for the type of CoreAbility to be returned
* @return a "fake" CoreAbility instance or null
*/
- public static CoreAbility getAbility(Class extends CoreAbility> clazz) {
+ public static CoreAbility getAbility(final Class extends CoreAbility> clazz) {
return clazz != null ? ABILITIES_BY_CLASS.get(clazz) : null;
}
@@ -314,15 +323,22 @@ public static ArrayList getAbilities() {
return new ArrayList(ABILITIES_BY_CLASS.values());
}
+ /**
+ * @return a list of "fake" instances for each ability that was loaded by
+ * {@link #registerAbilities()}
+ */
+ public static ArrayList getAbilitiesByName() {
+ return new ArrayList(ABILITIES_BY_NAME.values());
+ }
+
/**
* Returns a Collection of all of the player created instances for a
* specific type of CoreAbility.
- *
+ *
* @param clazz the class for the type of CoreAbilities
* @return a Collection of real instances
*/
- @SuppressWarnings("unchecked")
- public static Collection getAbilities(Class clazz) {
+ public static Collection getAbilities(final Class clazz) {
if (clazz == null || INSTANCES_BY_CLASS.get(clazz) == null || INSTANCES_BY_CLASS.get(clazz).size() == 0) {
return Collections.emptySet();
}
@@ -332,13 +348,12 @@ public static Collection getAbilities(Class clazz)
/**
* Returns a Collection of specific CoreAbility instances that were created
* by the specified player.
- *
+ *
* @param player the player that created the instances
* @param clazz the class for the type of CoreAbilities
* @return a Collection of real instances
*/
- @SuppressWarnings("unchecked")
- public static Collection getAbilities(Player player, Class clazz) {
+ public static Collection getAbilities(final Player player, final Class clazz) {
if (player == null || clazz == null || INSTANCES_BY_PLAYER.get(clazz) == null || INSTANCES_BY_PLAYER.get(clazz).get(player.getUniqueId()) == null) {
return Collections.emptySet();
}
@@ -356,18 +371,18 @@ public static Collection getAbilitiesByInstances() {
/**
* Returns an List of fake instances that were loaded by
* {@link #registerAbilities()} filtered by Element.
- *
+ *
* @param element the Element of the loaded abilities
* @return a list of fake CoreAbility instances
*/
- public static List getAbilitiesByElement(Element element) {
- ArrayList abilities = new ArrayList();
+ public static List getAbilitiesByElement(final Element element) {
+ final ArrayList abilities = new ArrayList();
if (element != null) {
- for (CoreAbility ability : getAbilities()) {
+ for (final CoreAbility ability : getAbilities()) {
if (ability.getElement() == element) {
abilities.add(ability);
} else if (ability.getElement() instanceof SubElement) {
- Element parentElement = ((SubElement) ability.getElement()).getParentElement();
+ final Element parentElement = ((SubElement) ability.getElement()).getParentElement();
if (parentElement == element) {
abilities.add(ability);
}
@@ -376,12 +391,14 @@ public static List getAbilitiesByElement(Element element) {
}
return abilities;
}
-
+
/**
- * CoreAbility keeps track of plugins that have registered abilities
- * to use for bending reload purposes
- *
This isn't a simple list, external use isn't recommended
- * @return a list of entrys with the plugin name and path abilities can be found at
+ * CoreAbility keeps track of plugins that have registered abilities to use
+ * for bending reload purposes
+ * This isn't a simple list, external use isn't recommended
+ *
+ * @return a list of entrys with the plugin name and path abilities can be
+ * found at
*/
public static List getAddonPlugins() {
return ADDON_PLUGINS;
@@ -389,24 +406,25 @@ public static List