diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 56e925aaf..bfa40ff5b 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -45,7 +45,6 @@ import net.citizensnpcs.api.trait.trait.MobType; import net.citizensnpcs.api.trait.trait.Spawned; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.Messaging; -import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.npc.ai.CitizensNavigator; import net.citizensnpcs.npc.skin.SkinnableEntity; import net.citizensnpcs.trait.AttributeTrait; @@ -400,7 +399,7 @@ public class CitizensNPC extends AbstractNPC { if (type == EntityType.PLAYER || Util.isHorse(type)) { if (SUPPORT_ATTRIBUTES && !hasTrait(AttributeTrait.class) || !getTrait(AttributeTrait.class) - .hasAttribute(Registry.ATTRIBUTE.get(SpigotUtil.getKey("step_height")))) { + .hasAttribute(Util.getRegistryValue(Registry.ATTRIBUTE, "generic.step_height", "step_height"))) { NMS.setStepHeight(entity, 1); } } diff --git a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java index 2ee1b6d53..43aabbc5b 100644 --- a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java @@ -916,7 +916,7 @@ public class HologramTrait extends Trait { } if (SpigotUtil.getVersion()[1] >= 21 && base.getEntity() instanceof LivingEntity) { AttributeInstance inst = ((LivingEntity) base.getEntity()) - .getAttribute(Registry.ATTRIBUTE.get(SpigotUtil.getKey("scale"))); + .getAttribute(Util.getRegistryValue(Registry.ATTRIBUTE, "generic.scale", "scale")); if (inst != null) { Transformation tf = disp.getTransformation(); tf.getScale().set(inst.getValue()); diff --git a/main/src/main/java/net/citizensnpcs/trait/ScaledMaxHealthTrait.java b/main/src/main/java/net/citizensnpcs/trait/ScaledMaxHealthTrait.java index 2a301be86..e6bb2049a 100644 --- a/main/src/main/java/net/citizensnpcs/trait/ScaledMaxHealthTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/ScaledMaxHealthTrait.java @@ -2,6 +2,7 @@ package net.citizensnpcs.trait; import java.math.BigDecimal; +import net.citizensnpcs.util.Util; import org.bukkit.Registry; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; @@ -12,7 +13,6 @@ import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitEventHandler; import net.citizensnpcs.api.trait.TraitName; -import net.citizensnpcs.api.util.SpigotUtil; @TraitName("scaledhealthtrait") public class ScaledMaxHealthTrait extends Trait { @@ -41,7 +41,7 @@ public class ScaledMaxHealthTrait extends Trait { public void onSpawn() { if (maxHealth != null && npc.getEntity() instanceof LivingEntity) { if (SUPPORTS_ATTRIBUTES) { - ((LivingEntity) npc.getEntity()).getAttribute(Registry.ATTRIBUTE.get(SpigotUtil.getKey("max_health"))) + ((LivingEntity) npc.getEntity()).getAttribute(Util.getRegistryValue(Registry.ATTRIBUTE, "generic.max_health", "max_health")) .setBaseValue(Math.min(MAX_VALUE, maxHealth)); } else { ((LivingEntity) npc.getEntity()).setMaxHealth(maxHealth); diff --git a/main/src/main/java/net/citizensnpcs/trait/versioned/BossBarTrait.java b/main/src/main/java/net/citizensnpcs/trait/versioned/BossBarTrait.java index 50aaeaa83..c2f33134c 100644 --- a/main/src/main/java/net/citizensnpcs/trait/versioned/BossBarTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/versioned/BossBarTrait.java @@ -33,7 +33,6 @@ import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Placeholders; -import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -143,7 +142,7 @@ public class BossBarTrait extends Trait { LivingEntity entity = (LivingEntity) npc.getEntity(); double maxHealth = entity.getMaxHealth(); if (SUPPORT_ATTRIBUTES) { - maxHealth = entity.getAttribute(Registry.ATTRIBUTE.get(SpigotUtil.getKey("max_health"))) + maxHealth = entity.getAttribute(Util.getRegistryValue(Registry.ATTRIBUTE, "generic.max_health", "max_health")) .getValue(); } bar.setProgress(entity.getHealth() / maxHealth); diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index 005f6baae..1f0330368 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -61,7 +61,6 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.BoundingBox; import net.citizensnpcs.api.util.EntityDim; import net.citizensnpcs.api.util.Messaging; -import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.api.util.SpigotUtil.InventoryViewAPI; import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator; import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; @@ -131,7 +130,7 @@ public class NMS { return; if (SUPPORTS_ATTRIBUTABLE && npc.getEntity() instanceof Attributable) { AttributeInstance attribute = ((Attributable) npc.getEntity()) - .getAttribute(Registry.ATTRIBUTE.get(SpigotUtil.getKey("knockback_resistance"))); + .getAttribute(Util.getRegistryValue(Registry.ATTRIBUTE, "generic.knockback_resistance", "knockback_resistance")); if (attribute != null) { strength *= 1 - attribute.getValue(); } diff --git a/main/src/main/java/net/citizensnpcs/util/Util.java b/main/src/main/java/net/citizensnpcs/util/Util.java index 5790b12bd..a6078a101 100644 --- a/main/src/main/java/net/citizensnpcs/util/Util.java +++ b/main/src/main/java/net/citizensnpcs/util/Util.java @@ -18,8 +18,11 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; +import org.bukkit.Keyed; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -252,6 +255,17 @@ public class Util { return new XORShiftRNG(); } + public static T getRegistryValue(Registry registry, String... keyCandidates) { + for (String keyCandidate : keyCandidates) { + final NamespacedKey key = SpigotUtil.getKey(keyCandidate); + final T value = registry.get(key); + if (value != null) { + return value; + } + } + return null; + } + public static String getTeamName(UUID id) { return "CIT-" + id.toString().replace("-", "").substring(0, 12); }