From 64414c8dbd2ab3eed6bf75ca1e66c4c67b8c5705 Mon Sep 17 00:00:00 2001 From: jayoevans Date: Tue, 29 Oct 2019 16:31:32 +1000 Subject: [PATCH] Add attribute methods to CoreAbility --- .../projectkorra/ability/CoreAbility.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index cdfb4c9e..b0ef664b 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -88,6 +88,7 @@ public abstract class CoreAbility implements Ability { private static final double DEFAULT_COLLISION_RADIUS = 0.3; private static final List ADDON_PLUGINS = new ArrayList<>(); private static final Map, Map> ATTRIBUTE_FIELDS = new HashMap<>(); + private static final Field[] EMPTY_FIELDS = new Field[0]; private static int idCounter; @@ -450,6 +451,26 @@ public abstract class CoreAbility implements Ability { return ADDON_PLUGINS; } + public static Field getAttributeField(Class ability, String attribute) { + Map attributes = ATTRIBUTE_FIELDS.get(ability); + + if (attributes == null) { + return null; + } + + return attributes.get(attribute); + } + + public static Field[] getAttributeFields(Class ability) { + Map attributes = ATTRIBUTE_FIELDS.get(ability); + + if (attributes == null) { + return EMPTY_FIELDS; + } + + return attributes.values().toArray(EMPTY_FIELDS); + } + /** * Returns true if the player has an active CoreAbility instance of type T. *