diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index 2510a2f..9a8d756 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -232,7 +232,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EquipmentProperty(packetFactory, "hand", EquipmentSlot.MAIN_HAND)); register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_HAND)); - register(new NameProperty()); + boolean legacyName = ver.isOlderThan(ServerVersion.V_1_9); + boolean optionalComponent = ver.isNewerThanOrEquals(ServerVersion.V_1_13); + register(new NameProperty(legacyName, optionalComponent)); + register(new DinnerboneProperty(legacyName, optionalComponent)); + register(new DummyProperty<>("look", false)); register(new DummyProperty<>("skin", SkinDescriptor.class, false)); @@ -253,6 +257,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBitsetProperty("arms", armorStandIndex, 0x04)); register(new SimpleBitsetProperty("base_plate", armorStandIndex, 0x08, true)); linkProperties("small", "arms", "base_plate"); + } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DinnerboneProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DinnerboneProperty.java new file mode 100644 index 0000000..a729c63 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DinnerboneProperty.java @@ -0,0 +1,33 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; + +import java.util.Map; +import java.util.Optional; + +public class DinnerboneProperty extends EntityPropertyImpl { + private final Object serialized; + private final EntityDataType type; + + public DinnerboneProperty(boolean legacy, boolean optional) { + super("dinnerbone", false, Boolean.class); + Component name = Component.text("Dinnerbone"); + String serialized = legacy ? + AdventureSerializer.getLegacyGsonSerializer().serialize(name) : + AdventureSerializer.getGsonSerializer().serialize(name); + this.serialized = optional ? Optional.of(serialized) : serialized; + this.type = optional ? EntityDataTypes.OPTIONAL_COMPONENT : EntityDataTypes.STRING; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + properties.put(2, new EntityData(2, type, entity.getProperty(this) ? serialized : null)); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NameProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NameProperty.java index 9434aea..ec57fcd 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NameProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NameProperty.java @@ -1,7 +1,5 @@ package lol.pyr.znpcsplus.entity.properties; -import com.github.retrooper.packetevents.PacketEvents; -import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; @@ -15,14 +13,13 @@ import java.util.Optional; public class NameProperty extends EntityPropertyImpl { private final boolean legacy; - private final boolean optionalComponent; + private final boolean optional; - public NameProperty() { + public NameProperty(boolean legacy, boolean optional) { super("name", null, Component.class); - ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); - legacy = version.isOlderThan(ServerVersion.V_1_9); - optionalComponent = version.isNewerThanOrEquals(ServerVersion.V_1_13); + this.legacy = legacy; + this.optional = optional; } @Override @@ -32,7 +29,7 @@ public class NameProperty extends EntityPropertyImpl { String serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) : AdventureSerializer.getGsonSerializer().serialize(value); - if (optionalComponent) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized))); + if (optional) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized))); else properties.put(2, newEntityData(2, EntityDataTypes.STRING, serialized)); }