Added more helpful utility methods

This commit is contained in:
Auxilor
2022-03-03 09:46:14 +00:00
parent 9a2f0e3df8
commit dbf39f3621
3 changed files with 36 additions and 4 deletions

View File

@@ -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<? extends EntityGoal<?>> getByKey(@NotNull final NamespacedKey key) {
public static KeyedDeserializer<? extends EntityGoal<? extends Mob>> 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 <T> The type of mob the goal can be applied to.
* @return The deserializer, or null if not found.
*/
@Nullable
@SuppressWarnings({"unchecked", "unused"})
public static <T extends Mob> KeyedDeserializer<EntityGoal<T>> getByKeyOfType(@NotNull final NamespacedKey key,
@NotNull final Class<T> clazz) {
return (KeyedDeserializer<EntityGoal<T>>) BY_KEY.get(key);
}
/**
* Register a deserializer for an entity goal.
*

View File

@@ -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<? extends TargetGoal<?>> getByKey(@NotNull final NamespacedKey key) {
public static KeyedDeserializer<? extends TargetGoal<? extends Mob>> 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 <T> The type of mob the goal can be applied to.
* @return The deserializer, or null if not found.
*/
@Nullable
@SuppressWarnings({"unchecked", "unused"})
public static <T extends Mob> KeyedDeserializer<TargetGoal<T>> getByKeyOfType(@NotNull final NamespacedKey key,
@NotNull final Class<T> clazz) {
return (KeyedDeserializer<TargetGoal<T>>) BY_KEY.get(key);
}
/**
* Register a deserializer for a target goal.
*

View File

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