From 9c15e20924125887f82eaadda3ce2b04853738ca Mon Sep 17 00:00:00 2001 From: jayoevans Date: Tue, 29 Oct 2019 09:38:59 +1000 Subject: [PATCH] Updated ability util classes --- .../projectkorra/ability/Ability.java | 7 ++- .../projectkorra/ability/AbilityManager.java | 46 ++++++++++-------- .../ability/api/AddonAbility.java | 28 ----------- .../projectkorra/ability/api/AirAbility.java | 4 +- .../ability/api/AvatarAbility.java | 28 +++-------- .../ability/api/BloodAbility.java | 8 ++-- .../projectkorra/ability/api/ChiAbility.java | 17 ++----- .../ability/api/ComboAbility.java | 22 --------- .../ability/api/CombustionAbility.java | 18 +++---- .../ability/api/EarthAbility.java | 48 ++++++++----------- .../ability/api/ElementalAbility.java | 4 +- .../projectkorra/ability/api/FireAbility.java | 36 +++++--------- .../ability/api/FlightAbility.java | 18 +++---- .../ability/api/HealingAbility.java | 18 +++---- .../projectkorra/ability/api/IceAbility.java | 18 +++---- .../projectkorra/ability/api/LavaAbility.java | 18 +++---- .../ability/api/LightningAbility.java | 18 +++---- .../ability/api/MetalAbility.java | 18 +++---- .../ability/api/MultiAbility.java | 19 -------- .../ability/api/PassiveAbility.java | 21 -------- .../ability/api/PlantAbility.java | 18 +++---- .../projectkorra/ability/api/SandAbility.java | 18 +++---- .../ability/api/SpiritualAbility.java | 18 +++---- .../projectkorra/ability/api/SubAbility.java | 2 + .../ability/api/WaterAbility.java | 36 ++++++-------- .../projectkorra/ability/util/Collision.java | 19 ++++---- .../ability/util/CollisionManager.java | 41 ++++++++-------- .../projectkorra/command/BindCommand.java | 4 +- .../projectkorra/player/BendingPlayer.java | 8 ++-- 29 files changed, 198 insertions(+), 380 deletions(-) delete mode 100644 src/com/projectkorra/projectkorra/ability/api/AddonAbility.java delete mode 100644 src/com/projectkorra/projectkorra/ability/api/ComboAbility.java delete mode 100644 src/com/projectkorra/projectkorra/ability/api/MultiAbility.java delete mode 100644 src/com/projectkorra/projectkorra/ability/api/PassiveAbility.java diff --git a/src/com/projectkorra/projectkorra/ability/Ability.java b/src/com/projectkorra/projectkorra/ability/Ability.java index c15b8a36..a4835a53 100644 --- a/src/com/projectkorra/projectkorra/ability/Ability.java +++ b/src/com/projectkorra/projectkorra/ability/Ability.java @@ -52,6 +52,7 @@ public abstract class Ability) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0])); protected Player player; @@ -101,7 +102,7 @@ public abstract class Ability getConfigType(); diff --git a/src/com/projectkorra/projectkorra/ability/AbilityManager.java b/src/com/projectkorra/projectkorra/ability/AbilityManager.java index c5c4286f..6971998e 100644 --- a/src/com/projectkorra/projectkorra/ability/AbilityManager.java +++ b/src/com/projectkorra/projectkorra/ability/AbilityManager.java @@ -2,7 +2,6 @@ package com.projectkorra.projectkorra.ability; import co.aikar.timings.lib.MCTiming; import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.api.PassiveAbility; import com.projectkorra.projectkorra.ability.info.*; import com.projectkorra.projectkorra.ability.util.AbilityRegistry; import com.projectkorra.projectkorra.ability.util.AddonAbilityRegistry; @@ -32,6 +31,7 @@ public class AbilityManager extends Module { private final PassiveAbilityManager passiveAbilityManager; private final Map abilities = new HashMap<>(); + private final Map, AbilityInfo> abilityInfoMap = new HashMap<>(); private final Set playerAbilitySet = new HashSet<>(); private final Map, LinkedList>> playerAbilityMap = new HashMap<>(); @@ -47,8 +47,8 @@ public class AbilityManager extends Module { runTimer(() -> { for (Ability ability : playerAbilitySet) { - if (ability instanceof PassiveAbility) { - if (!((PassiveAbility) ability).isProgressable()) { + if (ability.getInfo() instanceof PassiveAbilityInfo) { + if (!((PassiveAbilityInfo) ability).isProgressable()) { return; } @@ -119,7 +119,7 @@ public class AbilityManager extends Module { * @param plugin a JavaPlugin containing Ability class files * @param packageBase a prefix of the package name, used to increase * performance - * @see #getAbilities() + * @see #getAllAbilityInfo() * @see #getAbility(String) */ public void registerPluginAbilities(String packageBase) { @@ -141,7 +141,7 @@ public class AbilityManager extends Module { * all of the Ability class files that were found. * * @param folder the name of the folder to scan - * @see #getAbilities() + * @see #getAllAbilityInfo() * @see #getAbility(String) */ public void registerAddonAbilities(String folder) { @@ -214,14 +214,6 @@ public class AbilityManager extends Module { this.abilities.put(abilityInfo.getName(), abilityInfo); } - protected AbilityInfo getAbilityInfo(Class abilityClass) throws AbilityException { - try { - return ((Class) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[0]).newInstance(); - } catch (Exception e) { - throw new AbilityException(e); - } - } - private AbilityConfig getAbilityConfig(Class abilityClass) throws AbilityException { try { return ConfigManager.getConfig(((Class) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[1])); @@ -308,6 +300,26 @@ public class AbilityManager extends Module { return abilities.get(abilities).stream().map(ability::cast).collect(Collectors.toList()); } + public AbilityInfo getAbilityInfo(String abilityName) { + return this.abilities.get(abilityName); + } + + public AbilityInfo getAbilityInfo(Class abilityClass) { + return this.abilityInfoMap.computeIfAbsent(abilityClass, k -> + { + try { + return ((Class) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[0]).newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + return null; + } + }); + } + + public List getAbilityInfo() { + return new ArrayList<>(this.abilities.values()); + } + public LinkedList getAbilities(Class abilityClass) { LinkedList abilities = new LinkedList<>(); @@ -318,12 +330,8 @@ public class AbilityManager extends Module { return abilities; } - public AbilityInfo getAbilityInfo(String abilityName) { - return this.abilities.get(abilityName); - } - - public List getAbilities() { - return new ArrayList<>(this.abilities.values()); + public List getAbilities() { + return new ArrayList<>(this.playerAbilitySet); } public List getAbilities(Element element) { diff --git a/src/com/projectkorra/projectkorra/ability/api/AddonAbility.java b/src/com/projectkorra/projectkorra/ability/api/AddonAbility.java deleted file mode 100644 index 3f2c4dd9..00000000 --- a/src/com/projectkorra/projectkorra/ability/api/AddonAbility.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.projectkorra.projectkorra.ability.api; - -public interface AddonAbility { - - /** - * Called when the ability is loaded by PK. This is where the developer - * registers Listeners and Permissions. - */ - public void load(); - - /** - * Called whenever ProjectKorra stops and the ability is unloaded. This - * method is useful for cleaning up leftover objects such as frozen blocks. - * Any CoreAbility instances do not need to be cleaned up by stop method, as - * they will be cleaned up by {@link CoreAbility#removeAll()}. - */ - public void stop(); - - /** - * @return the name of the author of this AddonAbility - */ - public String getAuthor(); - - /** - * @return The version of the ability as a String. - */ - public String getVersion(); -} diff --git a/src/com/projectkorra/projectkorra/ability/api/AirAbility.java b/src/com/projectkorra/projectkorra/ability/api/AirAbility.java index 94a8c253..cf35df97 100644 --- a/src/com/projectkorra/projectkorra/ability/api/AirAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/AirAbility.java @@ -20,8 +20,8 @@ import com.projectkorra.projectkorra.util.ParticleEffect; public abstract class AirAbility extends ElementalAbility { - public AirAbility(final C config, final Player player) { - super(config, player); + public AirAbility(final Player player) { + super(player); } @Override diff --git a/src/com/projectkorra/projectkorra/ability/api/AvatarAbility.java b/src/com/projectkorra/projectkorra/ability/api/AvatarAbility.java index 48c6a24b..d81319bc 100644 --- a/src/com/projectkorra/projectkorra/ability/api/AvatarAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/AvatarAbility.java @@ -1,17 +1,16 @@ package com.projectkorra.projectkorra.ability.api; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import com.projectkorra.projectkorra.Element; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import com.projectkorra.projectkorra.configuration.configs.abilities.avatar.AvatarStateConfig; +import org.bukkit.Location; +import org.bukkit.entity.Player; -public abstract class AvatarAbility extends ElementalAbility { +public abstract class AvatarAbility extends ElementalAbility { - public AvatarAbility(final C config, final Player player) { - super(config, player); + public AvatarAbility(final Player player) { + super(player); } @Override @@ -24,25 +23,10 @@ public abstract class AvatarAbility extends ElementalAb return false; } - @Override - public final Element getElement() { - return Element.AVATAR; - } - public static void playAvatarSound(final Location loc) { AvatarStateConfig avatar = ConfigManager.getConfig(AvatarStateConfig.class); if (avatar.PlaySound) { loc.getWorld().playSound(loc, avatar.SoundType, avatar.SoundVolume, avatar.SoundPitch); } } - - /** - * Determines whether the ability requires the user to be an avatar in order - * to be able to use it. Set this to false for moves that should be - * able to be used without players needing to have the avatar element - */ - public boolean requireAvatar() { - return true; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/BloodAbility.java b/src/com/projectkorra/projectkorra/ability/api/BloodAbility.java index 5dc197b8..379cc1a2 100644 --- a/src/com/projectkorra/projectkorra/ability/api/BloodAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/BloodAbility.java @@ -1,14 +1,16 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; -public abstract class BloodAbility extends WaterAbility implements SubAbility { +public abstract class BloodAbility extends WaterAbility implements SubAbility { - public BloodAbility(final C config, final Player player) { - super(config, player); + public BloodAbility(final Player player) { + super(player); } @Override diff --git a/src/com/projectkorra/projectkorra/ability/api/ChiAbility.java b/src/com/projectkorra/projectkorra/ability/api/ChiAbility.java index 09ffe1d4..01acd102 100644 --- a/src/com/projectkorra/projectkorra/ability/api/ChiAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/ChiAbility.java @@ -1,14 +1,13 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class ChiAbility extends ElementalAbility { -public abstract class ChiAbility extends ElementalAbility { - - public ChiAbility(final C config, final Player player) { - super(config, player); + public ChiAbility(final Player player) { + super(player); } @Override @@ -20,10 +19,4 @@ public abstract class ChiAbility extends ElementalAbili public boolean isExplosiveAbility() { return false; } - - @Override - public Element getElement() { - return Element.CHI; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/ComboAbility.java b/src/com/projectkorra/projectkorra/ability/api/ComboAbility.java deleted file mode 100644 index 21b690a9..00000000 --- a/src/com/projectkorra/projectkorra/ability/api/ComboAbility.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.projectkorra.projectkorra.ability.api; - -import java.util.ArrayList; - -import org.bukkit.entity.Player; - -import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; - -public interface ComboAbility { - - /** - * Creates a new instance of this combo type with default config - */ - public abstract Object createNewComboInstance(Player player); - - /** - * Returns the list of abilities which constitute the combo. - * - * @return An ArrayList containing the combo's steps. - */ - public abstract ArrayList getCombination(); -} diff --git a/src/com/projectkorra/projectkorra/ability/api/CombustionAbility.java b/src/com/projectkorra/projectkorra/ability/api/CombustionAbility.java index 458397c7..5e849f7b 100644 --- a/src/com/projectkorra/projectkorra/ability/api/CombustionAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/CombustionAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class CombustionAbility extends FireAbility implements SubAbility { -public abstract class CombustionAbility extends FireAbility implements SubAbility { - - public CombustionAbility(final C config, final Player player) { - super(config, player); + public CombustionAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return FireAbility.class; } - - @Override - public Element getElement() { - return Element.COMBUSTION; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/EarthAbility.java b/src/com/projectkorra/projectkorra/ability/api/EarthAbility.java index 52480c6f..ff03896c 100644 --- a/src/com/projectkorra/projectkorra/ability/api/EarthAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/EarthAbility.java @@ -1,10 +1,19 @@ package com.projectkorra.projectkorra.ability.api; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +import com.projectkorra.projectkorra.configuration.configs.properties.EarthPropertiesConfig; +import com.projectkorra.projectkorra.earthbending.RaiseEarth; +import com.projectkorra.projectkorra.earthbending.lava.LavaFlow; +import com.projectkorra.projectkorra.earthbending.passive.DensityShift; +import com.projectkorra.projectkorra.util.BlockSource; +import com.projectkorra.projectkorra.util.Information; +import com.projectkorra.projectkorra.util.ParticleEffect; +import com.projectkorra.projectkorra.util.TempBlock; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -17,30 +26,20 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.util.Collision; -import com.projectkorra.projectkorra.configuration.ConfigManager; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; -import com.projectkorra.projectkorra.configuration.configs.properties.EarthPropertiesConfig; -import com.projectkorra.projectkorra.earthbending.RaiseEarth; -import com.projectkorra.projectkorra.earthbending.lava.LavaFlow; -import com.projectkorra.projectkorra.earthbending.passive.DensityShift; -import com.projectkorra.projectkorra.util.BlockSource; -import com.projectkorra.projectkorra.util.Information; -import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.TempBlock; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; -public abstract class EarthAbility extends ElementalAbility { +public abstract class EarthAbility extends ElementalAbility { private static final HashSet PREVENT_EARTHBENDING = new HashSet(); private static final Map MOVED_EARTH = new ConcurrentHashMap(); private static final Map TEMP_AIR_LOCATIONS = new ConcurrentHashMap(); private static final ArrayList PREVENT_PHYSICS = new ArrayList(); - public EarthAbility(final C config, final Player player) { - super(config, player); + public EarthAbility(final Player player) { + super(player); } public int getEarthbendableBlocksLength(final Block block, Vector direction, final int maxlength) { @@ -59,11 +58,6 @@ public abstract class EarthAbility extends ElementalAbi return getEarthSourceBlock(this.player, this.getName(), range); } - @Override - public Element getElement() { - return Element.EARTH; - } - public Block getLavaSourceBlock(final double range) { return getLavaSourceBlock(this.player, this.getName(), range); } diff --git a/src/com/projectkorra/projectkorra/ability/api/ElementalAbility.java b/src/com/projectkorra/projectkorra/ability/api/ElementalAbility.java index 6013e5ca..c4722f26 100644 --- a/src/com/projectkorra/projectkorra/ability/api/ElementalAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/ElementalAbility.java @@ -42,8 +42,8 @@ public abstract class ElementalAbility extends ElementalAbility { +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public abstract class FireAbility extends ElementalAbility { private static final Map TEMP_FIRE = new ConcurrentHashMap(); - public FireAbility(final C config, final Player player) { - super(config, player); + public FireAbility(final Player player) { + super(player); } @Override @@ -42,11 +37,6 @@ public abstract class FireAbility extends ElementalAbil return true; } - @Override - public Element getElement() { - return Element.FIRE; - } - @Override public void handleCollision(final Collision collision) { super.handleCollision(collision); diff --git a/src/com/projectkorra/projectkorra/ability/api/FlightAbility.java b/src/com/projectkorra/projectkorra/ability/api/FlightAbility.java index e4305e1e..47858908 100644 --- a/src/com/projectkorra/projectkorra/ability/api/FlightAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/FlightAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class FlightAbility extends AirAbility implements SubAbility { -public abstract class FlightAbility extends AirAbility implements SubAbility { - - public FlightAbility(final C config, final Player player) { - super(config, player); + public FlightAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return AirAbility.class; } - - @Override - public Element getElement() { - return Element.FLIGHT; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/HealingAbility.java b/src/com/projectkorra/projectkorra/ability/api/HealingAbility.java index a01c447f..81f1ca82 100644 --- a/src/com/projectkorra/projectkorra/ability/api/HealingAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/HealingAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class HealingAbility extends WaterAbility implements SubAbility { -public abstract class HealingAbility extends WaterAbility implements SubAbility { - - public HealingAbility(final C config, final Player player) { - super(config, player); + public HealingAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return WaterAbility.class; } - - @Override - public Element getElement() { - return Element.HEALING; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/IceAbility.java b/src/com/projectkorra/projectkorra/ability/api/IceAbility.java index f11819a9..a0fd016f 100644 --- a/src/com/projectkorra/projectkorra/ability/api/IceAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/IceAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class IceAbility extends WaterAbility implements SubAbility { -public abstract class IceAbility extends WaterAbility implements SubAbility { - - public IceAbility(final C config, final Player player) { - super(config, player); + public IceAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return WaterAbility.class; } - - @Override - public Element getElement() { - return Element.ICE; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/LavaAbility.java b/src/com/projectkorra/projectkorra/ability/api/LavaAbility.java index c8de01bd..ed905189 100644 --- a/src/com/projectkorra/projectkorra/ability/api/LavaAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/LavaAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class LavaAbility extends EarthAbility implements SubAbility { -public abstract class LavaAbility extends EarthAbility implements SubAbility { - - public LavaAbility(final C config, final Player player) { - super(config, player); + public LavaAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return EarthAbility.class; } - - @Override - public Element getElement() { - return Element.LAVA; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/LightningAbility.java b/src/com/projectkorra/projectkorra/ability/api/LightningAbility.java index 54bf8fc2..969ca88e 100644 --- a/src/com/projectkorra/projectkorra/ability/api/LightningAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/LightningAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class LightningAbility extends FireAbility implements SubAbility { -public abstract class LightningAbility extends FireAbility implements SubAbility { - - public LightningAbility(final C config, final Player player) { - super(config, player); + public LightningAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return FireAbility.class; } - - @Override - public Element getElement() { - return Element.LIGHTNING; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/MetalAbility.java b/src/com/projectkorra/projectkorra/ability/api/MetalAbility.java index 77556c6f..894a864b 100644 --- a/src/com/projectkorra/projectkorra/ability/api/MetalAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/MetalAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class MetalAbility extends EarthAbility implements SubAbility { -public abstract class MetalAbility extends EarthAbility implements SubAbility { - - public MetalAbility(final C config, final Player player) { - super(config, player); + public MetalAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return EarthAbility.class; } - - @Override - public Element getElement() { - return Element.METAL; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/MultiAbility.java b/src/com/projectkorra/projectkorra/ability/api/MultiAbility.java deleted file mode 100644 index e684f93b..00000000 --- a/src/com/projectkorra/projectkorra/ability/api/MultiAbility.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.projectkorra.projectkorra.ability.api; - -import java.util.ArrayList; - -import com.projectkorra.projectkorra.ability.util.MultiAbilityManager.MultiAbilityInfoSub; - -public interface MultiAbility { - - /** - * Returns the sub abilities of a MultiAbility. For example: - *

- * {@code new - * MultiAbilitySub("SubAbility", Element.LIGHTNING);} - * - * @return a list of sub MultiAbilities - */ - public abstract ArrayList getMultiAbilities(); - -} diff --git a/src/com/projectkorra/projectkorra/ability/api/PassiveAbility.java b/src/com/projectkorra/projectkorra/ability/api/PassiveAbility.java deleted file mode 100644 index 9f96e092..00000000 --- a/src/com/projectkorra/projectkorra/ability/api/PassiveAbility.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.projectkorra.projectkorra.ability.api; - -public interface PassiveAbility { - - /** - * This is a check to see if the passive requires some form of activation, - * such as sneaking, clicking, etc.
- * If false, the passive should not call start! - * - * @return false if this passive should always be on - */ - public boolean isInstantiable(); - - /** - * This is used if the passive should progress - * - * @return false if progress() shouldn't be called; - */ - public boolean isProgressable(); - -} diff --git a/src/com/projectkorra/projectkorra/ability/api/PlantAbility.java b/src/com/projectkorra/projectkorra/ability/api/PlantAbility.java index 905efc3a..4b5d5c89 100644 --- a/src/com/projectkorra/projectkorra/ability/api/PlantAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/PlantAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class PlantAbility extends WaterAbility implements SubAbility { -public abstract class PlantAbility extends WaterAbility implements SubAbility { - - public PlantAbility(final C config, final Player player) { - super(config, player); + public PlantAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return WaterAbility.class; } - - @Override - public Element getElement() { - return Element.PLANT; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/SandAbility.java b/src/com/projectkorra/projectkorra/ability/api/SandAbility.java index f8933d6b..a38bf78a 100644 --- a/src/com/projectkorra/projectkorra/ability/api/SandAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/SandAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class SandAbility extends EarthAbility implements SubAbility { -public abstract class SandAbility extends EarthAbility implements SubAbility { - - public SandAbility(final C config, final Player player) { - super(config, player); + public SandAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return EarthAbility.class; } - - @Override - public Element getElement() { - return Element.SAND; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/SpiritualAbility.java b/src/com/projectkorra/projectkorra/ability/api/SpiritualAbility.java index 4da3d568..2b0adf02 100644 --- a/src/com/projectkorra/projectkorra/ability/api/SpiritualAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/SpiritualAbility.java @@ -1,24 +1,18 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +public abstract class SpiritualAbility extends AirAbility implements SubAbility { -public abstract class SpiritualAbility extends AirAbility implements SubAbility { - - public SpiritualAbility(final C config, final Player player) { - super(config, player); + public SpiritualAbility(final Player player) { + super(player); } @Override public Class getParentAbility() { return AirAbility.class; } - - @Override - public Element getElement() { - return Element.SPIRITUAL; - } - } diff --git a/src/com/projectkorra/projectkorra/ability/api/SubAbility.java b/src/com/projectkorra/projectkorra/ability/api/SubAbility.java index 249a68ac..25f781e6 100644 --- a/src/com/projectkorra/projectkorra/ability/api/SubAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/SubAbility.java @@ -1,5 +1,7 @@ package com.projectkorra.projectkorra.ability.api; +import com.projectkorra.projectkorra.ability.Ability; + public interface SubAbility { /** diff --git a/src/com/projectkorra/projectkorra/ability/api/WaterAbility.java b/src/com/projectkorra/projectkorra/ability/api/WaterAbility.java index 01d1824d..42b75cd9 100644 --- a/src/com/projectkorra/projectkorra/ability/api/WaterAbility.java +++ b/src/com/projectkorra/projectkorra/ability/api/WaterAbility.java @@ -1,21 +1,8 @@ package com.projectkorra.projectkorra.ability.api; -import java.util.HashSet; -import java.util.Set; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Tag; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Levelled; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; @@ -30,16 +17,23 @@ import com.projectkorra.projectkorra.waterbending.Torrent; import com.projectkorra.projectkorra.waterbending.WaterSpout; import com.projectkorra.projectkorra.waterbending.ice.PhaseChange; import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Levelled; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; -public abstract class WaterAbility extends ElementalAbility { +import java.util.HashSet; +import java.util.Set; - public WaterAbility(final C config, final Player player) { - super(config, player); - } +public abstract class WaterAbility extends ElementalAbility { - @Override - public Element getElement() { - return Element.WATER; + public WaterAbility(final Player player) { + super(player); } public Block getIceSourceBlock(final double range) { diff --git a/src/com/projectkorra/projectkorra/ability/util/Collision.java b/src/com/projectkorra/projectkorra/ability/util/Collision.java index e5a0de13..c7f0885d 100644 --- a/src/com/projectkorra/projectkorra/ability/util/Collision.java +++ b/src/com/projectkorra/projectkorra/ability/util/Collision.java @@ -1,9 +1,8 @@ package com.projectkorra.projectkorra.ability.util; +import com.projectkorra.projectkorra.ability.Ability; import org.bukkit.Location; -import com.projectkorra.projectkorra.ability.CoreAbility; - /** * A Collision is used to represent the collision between two CoreAbility * objects. @@ -16,14 +15,14 @@ import com.projectkorra.projectkorra.ability.CoreAbility; */ @SuppressWarnings("rawtypes") public class Collision { - private CoreAbility abilityFirst; - private CoreAbility abilitySecond; + private Ability abilityFirst; + private Ability abilitySecond; private boolean removingFirst; private boolean removingSecond; private Location locationFirst; private Location locationSecond; - public Collision(final CoreAbility abilityFirst, final CoreAbility abilitySecond, final boolean removingFirst, final boolean removingSecond, final Location locationFirst, final Location locationSecond) { + public Collision(final Ability abilityFirst, final Ability abilitySecond, final boolean removingFirst, final boolean removingSecond, final Location locationFirst, final Location locationSecond) { if (abilityFirst == null || abilitySecond == null) { return; } @@ -36,23 +35,23 @@ public class Collision { this.locationSecond = locationSecond; } - public Collision(final CoreAbility abilityFirst, final CoreAbility abilitySecond, final boolean removingFirst, final boolean removingSecond) { + public Collision(final Ability abilityFirst, final Ability abilitySecond, final boolean removingFirst, final boolean removingSecond) { this(abilityFirst, abilitySecond, removingFirst, removingSecond, null, null); } - public CoreAbility getAbilityFirst() { + public Ability getAbilityFirst() { return this.abilityFirst; } - public void setAbilityFirst(final CoreAbility abilityFirst) { + public void setAbilityFirst(final Ability abilityFirst) { this.abilityFirst = abilityFirst; } - public CoreAbility getAbilitySecond() { + public Ability getAbilitySecond() { return this.abilitySecond; } - public void setAbilitySecond(final CoreAbility abilitySecond) { + public void setAbilitySecond(final Ability abilitySecond) { this.abilitySecond = abilitySecond; } diff --git a/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java b/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java index 281980a4..c1decf6d 100644 --- a/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java +++ b/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java @@ -1,19 +1,16 @@ package com.projectkorra.projectkorra.ability.util; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.AbilityManager; +import com.projectkorra.projectkorra.ability.info.PassiveAbilityInfo; +import com.projectkorra.projectkorra.event.AbilityCollisionEvent; +import com.projectkorra.projectkorra.module.ModuleManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.scheduler.BukkitRunnable; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.ability.api.PassiveAbility; -import com.projectkorra.projectkorra.event.AbilityCollisionEvent; +import java.util.*; /** * A CollisionManager is used to monitor possible collisions between all @@ -24,9 +21,9 @@ import com.projectkorra.projectkorra.event.AbilityCollisionEvent; * ProjectKorra.getCollisionInitializer().addCollision(myCoreAbility) * ProjectKorra.getCollisionInitializer().addSmallAbility(myCoreAbility) *

- * For a CoreAbility to collide properly, the {@link CoreAbility#isCollidable()} - * , {@link CoreAbility#getCollisionRadius()}, - * {@link CoreAbility#getLocations()}, and {@link CoreAbility#handleCollision()} + * For a CoreAbility to collide properly, the {@link Ability#isCollidable()} + * , {@link Ability#getCollisionRadius()}, + * {@link Ability#getLocations()}, and {@link Ability#handleCollision()} * should be overridden if necessary. *

* During a Collision the {@link AbilityCollisionEvent} is called, then if not @@ -36,6 +33,8 @@ import com.projectkorra.projectkorra.event.AbilityCollisionEvent; @SuppressWarnings({ "rawtypes", "unchecked" }) public class CollisionManager { + private final AbilityManager abilityManager = ModuleManager.getModule(AbilityManager.class); + /* * If true an ability instance can remove multiple other instances on a * single tick. e.g. 3 Colliding WaterManipulations can all be removed @@ -70,8 +69,8 @@ public class CollisionManager { private void detectCollisions() { int activeInstanceCount = 0; - for (final CoreAbility ability : CoreAbility.getAbilitiesByInstances()) { - if (!(ability instanceof PassiveAbility)) { + for (final Ability ability : this.abilityManager.getAbilities()) { + if (!(ability.getInfo() instanceof PassiveAbilityInfo)) { if (++activeInstanceCount > 1) { break; } @@ -82,21 +81,21 @@ public class CollisionManager { return; } - final HashMap> locationsCache = new HashMap<>(); + final HashMap> locationsCache = new HashMap<>(); for (final Collision collision : this.collisions) { - final Collection instancesFirst = CoreAbility.getAbilities(collision.getAbilityFirst().getClass()); + final Collection instancesFirst = this.abilityManager.getAbilities(collision.getAbilityFirst().getClass()); if (instancesFirst.isEmpty()) { continue; } - final Collection instancesSecond = CoreAbility.getAbilities(collision.getAbilitySecond().getClass()); + final Collection instancesSecond = this.abilityManager.getAbilities(collision.getAbilitySecond().getClass()); if (instancesSecond.isEmpty()) { continue; } - final HashSet alreadyCollided = new HashSet(); + final HashSet alreadyCollided = new HashSet<>(); final double certainNoCollisionDistSquared = Math.pow(this.certainNoCollisionDistance, 2); - for (final CoreAbility abilityFirst : instancesFirst) { + for (final Ability abilityFirst : instancesFirst) { if (abilityFirst.getPlayer() == null || alreadyCollided.contains(abilityFirst) || !abilityFirst.isCollidable()) { continue; } @@ -109,7 +108,7 @@ public class CollisionManager { continue; } - for (final CoreAbility abilitySecond : instancesSecond) { + for (final Ability abilitySecond : instancesSecond) { if (abilitySecond.getPlayer() == null || alreadyCollided.contains(abilitySecond) || !abilitySecond.isCollidable()) { continue; } else if (abilityFirst.getPlayer().equals(abilitySecond.getPlayer())) { diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index 257c63c5..05bf0501 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -1,7 +1,7 @@ package com.projectkorra.projectkorra.command; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.AbilityInfo; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.commands.BindCommandConfig; import com.projectkorra.projectkorra.element.Element; @@ -154,7 +154,7 @@ public class BindCommand extends PKCommand { Set abilitySet = new HashSet<>(); - for (AbilityInfo abilityInfo : this.abilityManager.getAbilities()) { + for (AbilityInfo abilityInfo : this.abilityManager.getAbilityInfo()) { // if (!coreAbil.isHiddenAbility() && bPlayer.canBind(coreAbil) && !(coreAbil instanceof PassiveAbility || coreAbil instanceof ComboAbility) && !abilities.contains(coreAbil.getName())) { if (bendingPlayer.canBind(abilityInfo)) { diff --git a/src/com/projectkorra/projectkorra/player/BendingPlayer.java b/src/com/projectkorra/projectkorra/player/BendingPlayer.java index 4a4dd0f9..a63ffb9d 100644 --- a/src/com/projectkorra/projectkorra/player/BendingPlayer.java +++ b/src/com/projectkorra/projectkorra/player/BendingPlayer.java @@ -2,13 +2,12 @@ package com.projectkorra.projectkorra.player; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.Ability; -import com.projectkorra.projectkorra.ability.AbilityInfo; import com.projectkorra.projectkorra.ability.AbilityManager; import com.projectkorra.projectkorra.ability.PassiveAbilityManager; import com.projectkorra.projectkorra.ability.api.ChiAbility; import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; -import com.projectkorra.projectkorra.ability.loader.AbilityLoader; -import com.projectkorra.projectkorra.ability.loader.AvatarAbilityLoader; +import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.ability.info.AvatarAbilityInfo; import com.projectkorra.projectkorra.cooldown.CooldownManager; import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.ElementManager; @@ -166,10 +165,9 @@ public class BendingPlayer { return false; } - AbilityLoader abilityLoader = abilityInfo.getLoader(); Element element = abilityInfo.getElement(); - if (!hasElement(element) && !(abilityLoader instanceof AvatarAbilityLoader && !((AvatarAbilityLoader) abilityLoader).requireAvatar())) { + if (!hasElement(element) && !(abilityInfo instanceof AvatarAbilityInfo && !((AvatarAbilityInfo) abilityInfo).requireAvatar())) { return false; }