Updated ability util classes

This commit is contained in:
jayoevans 2019-10-29 09:38:59 +10:00
parent d44077f99b
commit 9c15e20924
29 changed files with 198 additions and 380 deletions

View file

@ -52,6 +52,7 @@ public abstract class Ability<Info extends AbilityInfo, Config extends AbilityCo
private static int idCounter;
protected final AbilityManager manager = ModuleManager.getModule(AbilityManager.class);
protected final Info info = (Info) this.manager.getAbilityInfo(getClass());
protected final Config config = ConfigManager.getConfig(((Class<Config>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
protected Player player;
@ -101,7 +102,7 @@ public abstract class Ability<Info extends AbilityInfo, Config extends AbilityCo
* @param player the non-null player that created this instance
* @see #start()
*/
public Ability(final Config config, final Player player) {
public Ability(final Player player) {
this();
if (player == null) {
@ -206,6 +207,10 @@ public abstract class Ability<Info extends AbilityInfo, Config extends AbilityCo
public int getId() {
return this.id;
}
public Info getInfo() {
return this.info;
}
public abstract Class<Config> getConfigType();

View file

@ -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<String, AbilityInfo> abilities = new HashMap<>();
private final Map<Class<? extends Ability>, AbilityInfo> abilityInfoMap = new HashMap<>();
private final Set<Ability> playerAbilitySet = new HashSet<>();
private final Map<UUID, Map<Class<? extends Ability>, LinkedList<Ability>>> 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<? extends Ability> abilityClass) throws AbilityException {
try {
return ((Class<? extends AbilityInfo>) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
} catch (Exception e) {
throw new AbilityException(e);
}
}
private AbilityConfig getAbilityConfig(Class<? extends Ability> abilityClass) throws AbilityException {
try {
return ConfigManager.getConfig(((Class<? extends AbilityConfig>) ((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<? extends Ability> abilityClass) {
return this.abilityInfoMap.computeIfAbsent(abilityClass, k ->
{
try {
return ((Class<? extends AbilityInfo>) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
});
}
public List<AbilityInfo> getAbilityInfo() {
return new ArrayList<>(this.abilities.values());
}
public <T extends Ability> LinkedList<T> getAbilities(Class<T> abilityClass) {
LinkedList<T> 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<AbilityInfo> getAbilities() {
return new ArrayList<>(this.abilities.values());
public List<Ability> getAbilities() {
return new ArrayList<>(this.playerAbilitySet);
}
public List<AbilityInfo> getAbilities(Element element) {

View file

@ -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();
}

View file

@ -20,8 +20,8 @@ import com.projectkorra.projectkorra.util.ParticleEffect;
public abstract class AirAbility<Info extends AbilityInfo, C extends AbilityConfig> extends ElementalAbility<Info, C> {
public AirAbility(final C config, final Player player) {
super(config, player);
public AirAbility(final Player player) {
super(player);
}
@Override

View file

@ -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<C extends AbilityConfig> extends ElementalAbility<C> {
public abstract class AvatarAbility<Info extends AbilityInfo, C extends AbilityConfig> extends ElementalAbility<Info, C> {
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<C extends AbilityConfig> 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 <tt>false</tt> for moves that should be
* able to be used without players needing to have the avatar element
*/
public boolean requireAvatar() {
return true;
}
}

View file

@ -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<C extends AbilityConfig> extends WaterAbility<C> implements SubAbility {
public abstract class BloodAbility<Info extends AbilityInfo, C extends AbilityConfig> extends WaterAbility<Info, C> implements SubAbility {
public BloodAbility(final C config, final Player player) {
super(config, player);
public BloodAbility(final Player player) {
super(player);
}
@Override

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends ElementalAbility<Info, C> {
public abstract class ChiAbility<C extends AbilityConfig> extends ElementalAbility<C> {
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<C extends AbilityConfig> extends ElementalAbili
public boolean isExplosiveAbility() {
return false;
}
@Override
public Element getElement() {
return Element.CHI;
}
}

View file

@ -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<AbilityInformation> getCombination();
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends FireAbility<Info, C> implements SubAbility {
public abstract class CombustionAbility<C extends AbilityConfig> extends FireAbility<C> implements SubAbility {
public CombustionAbility(final C config, final Player player) {
super(config, player);
public CombustionAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return FireAbility.class;
}
@Override
public Element getElement() {
return Element.COMBUSTION;
}
}

View file

@ -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<C extends AbilityConfig> extends ElementalAbility<C> {
public abstract class EarthAbility<Info extends AbilityInfo, C extends AbilityConfig> extends ElementalAbility<Info, C> {
private static final HashSet<Block> PREVENT_EARTHBENDING = new HashSet<Block>();
private static final Map<Block, Information> MOVED_EARTH = new ConcurrentHashMap<Block, Information>();
private static final Map<Integer, Information> TEMP_AIR_LOCATIONS = new ConcurrentHashMap<Integer, Information>();
private static final ArrayList<Block> PREVENT_PHYSICS = new ArrayList<Block>();
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<C extends AbilityConfig> 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);
}

View file

@ -42,8 +42,8 @@ public abstract class ElementalAbility<Info extends AbilityInfo, C extends Abili
}
}
public ElementalAbility(final C config, final Player player) {
super(config, player);
public ElementalAbility(Player player) {
super(player);
}
public boolean isTransparent(final Block block) {

View file

@ -1,21 +1,7 @@
package com.projectkorra.projectkorra.ability.api;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
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;
@ -23,13 +9,22 @@ import com.projectkorra.projectkorra.configuration.configs.properties.FireProper
import com.projectkorra.projectkorra.firebending.BlazeArc;
import com.projectkorra.projectkorra.util.Information;
import com.projectkorra.projectkorra.util.ParticleEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public abstract class FireAbility<C extends AbilityConfig> extends ElementalAbility<C> {
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public abstract class FireAbility<Info extends AbilityInfo, C extends AbilityConfig> extends ElementalAbility<Info, C> {
private static final Map<Location, Information> TEMP_FIRE = new ConcurrentHashMap<Location, Information>();
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<C extends AbilityConfig> extends ElementalAbil
return true;
}
@Override
public Element getElement() {
return Element.FIRE;
}
@Override
public void handleCollision(final Collision collision) {
super.handleCollision(collision);

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends AirAbility<Info, C> implements SubAbility {
public abstract class FlightAbility<C extends AbilityConfig> extends AirAbility<C> implements SubAbility {
public FlightAbility(final C config, final Player player) {
super(config, player);
public FlightAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return AirAbility.class;
}
@Override
public Element getElement() {
return Element.FLIGHT;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends WaterAbility<Info, C> implements SubAbility {
public abstract class HealingAbility<C extends AbilityConfig> extends WaterAbility<C> implements SubAbility {
public HealingAbility(final C config, final Player player) {
super(config, player);
public HealingAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return WaterAbility.class;
}
@Override
public Element getElement() {
return Element.HEALING;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends WaterAbility<Info, C> implements SubAbility {
public abstract class IceAbility<C extends AbilityConfig> extends WaterAbility<C> implements SubAbility {
public IceAbility(final C config, final Player player) {
super(config, player);
public IceAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return WaterAbility.class;
}
@Override
public Element getElement() {
return Element.ICE;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends EarthAbility<Info, C> implements SubAbility {
public abstract class LavaAbility<C extends AbilityConfig> extends EarthAbility<C> implements SubAbility {
public LavaAbility(final C config, final Player player) {
super(config, player);
public LavaAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return EarthAbility.class;
}
@Override
public Element getElement() {
return Element.LAVA;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends FireAbility<Info, C> implements SubAbility {
public abstract class LightningAbility<C extends AbilityConfig> extends FireAbility<C> implements SubAbility {
public LightningAbility(final C config, final Player player) {
super(config, player);
public LightningAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return FireAbility.class;
}
@Override
public Element getElement() {
return Element.LIGHTNING;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends EarthAbility<Info, C> implements SubAbility {
public abstract class MetalAbility<C extends AbilityConfig> extends EarthAbility<C> implements SubAbility {
public MetalAbility(final C config, final Player player) {
super(config, player);
public MetalAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return EarthAbility.class;
}
@Override
public Element getElement() {
return Element.METAL;
}
}

View file

@ -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:
* <p>
* {@code new
* MultiAbilitySub("SubAbility", Element.LIGHTNING);}
*
* @return a list of sub MultiAbilities
*/
public abstract ArrayList<MultiAbilityInfoSub> getMultiAbilities();
}

View file

@ -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. <br>
* <b>If false, the passive should not call start!</b>
*
* @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();
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends WaterAbility<Info, C> implements SubAbility {
public abstract class PlantAbility<C extends AbilityConfig> extends WaterAbility<C> implements SubAbility {
public PlantAbility(final C config, final Player player) {
super(config, player);
public PlantAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return WaterAbility.class;
}
@Override
public Element getElement() {
return Element.PLANT;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends EarthAbility<Info, C> implements SubAbility {
public abstract class SandAbility<C extends AbilityConfig> extends EarthAbility<C> implements SubAbility {
public SandAbility(final C config, final Player player) {
super(config, player);
public SandAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return EarthAbility.class;
}
@Override
public Element getElement() {
return Element.SAND;
}
}

View file

@ -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<Info extends AbilityInfo, C extends AbilityConfig> extends AirAbility<Info, C> implements SubAbility {
public abstract class SpiritualAbility<C extends AbilityConfig> extends AirAbility<C> implements SubAbility {
public SpiritualAbility(final C config, final Player player) {
super(config, player);
public SpiritualAbility(final Player player) {
super(player);
}
@Override
public Class<? extends Ability> getParentAbility() {
return AirAbility.class;
}
@Override
public Element getElement() {
return Element.SPIRITUAL;
}
}

View file

@ -1,5 +1,7 @@
package com.projectkorra.projectkorra.ability.api;
import com.projectkorra.projectkorra.ability.Ability;
public interface SubAbility {
/**

View file

@ -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<C extends AbilityConfig> extends ElementalAbility<C> {
import java.util.HashSet;
import java.util.Set;
public WaterAbility(final C config, final Player player) {
super(config, player);
}
public abstract class WaterAbility<Info extends AbilityInfo, C extends AbilityConfig> extends ElementalAbility<Info, C> {
@Override
public Element getElement() {
return Element.WATER;
public WaterAbility(final Player player) {
super(player);
}
public Block getIceSourceBlock(final double range) {

View file

@ -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;
}

View file

@ -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)
* <p>
* 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.
* <p>
* 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<CoreAbility, List<Location>> locationsCache = new HashMap<>();
final HashMap<Ability, List<Location>> locationsCache = new HashMap<>();
for (final Collision collision : this.collisions) {
final Collection<? extends CoreAbility> instancesFirst = CoreAbility.getAbilities(collision.getAbilityFirst().getClass());
final Collection<? extends Ability> instancesFirst = this.abilityManager.getAbilities(collision.getAbilityFirst().getClass());
if (instancesFirst.isEmpty()) {
continue;
}
final Collection<? extends CoreAbility> instancesSecond = CoreAbility.getAbilities(collision.getAbilitySecond().getClass());
final Collection<? extends Ability> instancesSecond = this.abilityManager.getAbilities(collision.getAbilitySecond().getClass());
if (instancesSecond.isEmpty()) {
continue;
}
final HashSet<CoreAbility> alreadyCollided = new HashSet<CoreAbility>();
final HashSet<Ability> 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())) {

View file

@ -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<BindCommandConfig> {
Set<String> 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)) {

View file

@ -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;
}