diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java b/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java index 65c34a1..1180375 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java @@ -43,6 +43,14 @@ public interface PropertyHolder { */ void setItemProperty(EntityProperty key, ItemStack value); + /** + * Weird fix which is sadly required in order to not decrease performance + * when using item properties, read https://github.com/Pyrbu/ZNPCsPlus/pull/129#issuecomment-1948777764 + * + * @param key Unique key representing a property + */ + ItemStack getItemProperty(EntityProperty key); + /** * Method used to get a set of all of the property keys that this holder has a value for * diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java index 97ef4de..4418152 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java @@ -107,6 +107,11 @@ public class PacketEntity implements PropertyHolder { properties.setItemProperty(key, value); } + @Override + public ItemStack getItemProperty(EntityProperty key) { + return properties.getItemProperty(key); + } + @Override public Set> getAppliedProperties() { return properties.getAppliedProperties(); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java index f2652f0..3b572e5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java @@ -1,6 +1,7 @@ package lol.pyr.znpcsplus.hologram; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; +import io.github.retrooper.packetevents.util.SpigotConversionUtil; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.entity.PacketEntity; @@ -76,6 +77,12 @@ public class HologramLine implements PropertyHolder { throw new UnsupportedOperationException("Can't set properties on a hologram line"); } + @SuppressWarnings("unchecked") + @Override + public ItemStack getItemProperty(EntityProperty key) { + return SpigotConversionUtil.toBukkitItemStack(((EntityProperty) key).getDefaultValue()); + } + @Override public Set> getAppliedProperties() { return properties; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java index fcc563d..7aa8539 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -164,6 +164,12 @@ public class NpcImpl extends Viewable implements Npc { setProperty((EntityPropertyImpl) key, SpigotConversionUtil.fromBukkitItemStack(value)); } + @SuppressWarnings("unchecked") + @Override + public ItemStack getItemProperty(EntityProperty key) { + return SpigotConversionUtil.toBukkitItemStack(getProperty((EntityProperty) key)); + } + public void setProperty(EntityPropertyImpl key, T value) { if (key == null) return; if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key);