diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoals.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoals.java index 88eac1e2..13b14491 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoals.java +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoals.java @@ -35,6 +35,7 @@ import com.willfp.eco.core.entities.ai.entity.EntityGoalWaterAvoidingRandomFlyin import com.willfp.eco.core.entities.ai.entity.EntityGoalWaterAvoidingRandomStroll; import com.willfp.eco.core.serialization.KeyedDeserializer; import org.bukkit.NamespacedKey; +import org.bukkit.entity.Mob; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -91,10 +92,25 @@ public final class EntityGoals { * @return The deserializer, or null if not found. */ @Nullable - public static KeyedDeserializer> getByKey(@NotNull final NamespacedKey key) { + public static KeyedDeserializer> getByKey(@NotNull final NamespacedKey key) { return BY_KEY.get(key); } + /** + * Get deserializer by key, with a defined type (to prevent cluttering code with unsafe casts). + * + * @param key The key. + * @param clazz The type of target goal. + * @param The type of mob the goal can be applied to. + * @return The deserializer, or null if not found. + */ + @Nullable + @SuppressWarnings({"unchecked", "unused"}) + public static KeyedDeserializer> getByKeyOfType(@NotNull final NamespacedKey key, + @NotNull final Class clazz) { + return (KeyedDeserializer>) BY_KEY.get(key); + } + /** * Register a deserializer for an entity goal. * diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoals.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoals.java index 332733f3..0c9384a3 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoals.java +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoals.java @@ -7,11 +7,12 @@ import com.willfp.eco.core.entities.ai.target.TargetGoalNearestAttackable; import com.willfp.eco.core.entities.ai.target.TargetGoalNearestAttackableWitch; import com.willfp.eco.core.entities.ai.target.TargetGoalNearestHealableRaider; import com.willfp.eco.core.entities.ai.target.TargetGoalNonTameRandom; -import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerTarget; import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerHurtBy; +import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerTarget; import com.willfp.eco.core.entities.ai.target.TargetGoalResetUniversalAnger; import com.willfp.eco.core.serialization.KeyedDeserializer; import org.bukkit.NamespacedKey; +import org.bukkit.entity.Mob; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,10 +46,25 @@ public final class TargetGoals { * @return The deserializer, or null if not found. */ @Nullable - public static KeyedDeserializer> getByKey(@NotNull final NamespacedKey key) { + public static KeyedDeserializer> getByKey(@NotNull final NamespacedKey key) { return BY_KEY.get(key); } + /** + * Get deserializer by key, with a defined type (to prevent cluttering code with unsafe casts). + * + * @param key The key. + * @param clazz The type of target goal. + * @param The type of mob the goal can be applied to. + * @return The deserializer, or null if not found. + */ + @Nullable + @SuppressWarnings({"unchecked", "unused"}) + public static KeyedDeserializer> getByKeyOfType(@NotNull final NamespacedKey key, + @NotNull final Class clazz) { + return (KeyedDeserializer>) BY_KEY.get(key); + } + /** * Register a deserializer for a target goal. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt index 9fadcb5a..7aa7b7f8 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt @@ -29,10 +29,10 @@ import com.willfp.eco.internal.spigot.data.DataYml import com.willfp.eco.internal.spigot.data.EcoKeyRegistry import com.willfp.eco.internal.spigot.data.EcoProfileHandler import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler +import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy -import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import net.kyori.adventure.platform.bukkit.BukkitAudiences import org.bukkit.Location import org.bukkit.NamespacedKey