From acd953e460f5c4d569d3a753beb28030958bdb60 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 10 Jul 2023 01:01:12 +0200 Subject: [PATCH 01/78] move to a more modular property/metadata system --- .../znpcsplus/api/entity/PropertyHolder.java | 3 + .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 48 ++---- .../property/PropertyRemoveCommand.java | 2 +- .../conversion/znpcs/ZNpcImporter.java | 2 +- .../znpcsplus/entity/EntityPropertyImpl.java | 44 ++++-- .../entity/EntityPropertyRegistryImpl.java | 54 +++++-- .../pyr/znpcsplus/entity/PacketEntity.java | 5 - .../znpcsplus/entity/PropertySerializer.java | 5 + .../properties/DummyBooleanProperty.java | 18 +++ .../entity/properties/EffectsProperty.java | 25 +++ .../entity/properties/EquipmentProperty.java | 28 ++++ .../entity/properties/GlowProperty.java | 29 ++++ .../entity/properties/NameProperty.java | 41 +++++ .../pyr/znpcsplus/hologram/HologramImpl.java | 9 +- .../pyr/znpcsplus/hologram/HologramLine.java | 14 +- .../znpcsplus/metadata/MetadataFactory.java | 1 + .../metadata/V1_10MetadataFactory.java | 1 + .../metadata/V1_11MetadataFactory.java | 6 +- .../metadata/V1_12MetadataFactory.java | 1 + .../metadata/V1_13MetadataFactory.java | 1 + .../metadata/V1_14MetadataFactory.java | 1 + .../metadata/V1_15MetadataFactory.java | 1 + .../metadata/V1_16MetadataFactory.java | 1 + .../metadata/V1_17MetadataFactory.java | 1 + .../metadata/V1_19MetadataFactory.java | 2 +- .../metadata/V1_8MetadataFactory.java | 1 + .../metadata/V1_9MetadataFactory.java | 1 + .../java/lol/pyr/znpcsplus/npc/NpcImpl.java | 36 ++--- .../pyr/znpcsplus/npc/NpcRegistryImpl.java | 4 +- .../pyr/znpcsplus/packets/PacketFactory.java | 8 +- .../znpcsplus/packets/V1_10PacketFactory.java | 27 ---- .../znpcsplus/packets/V1_11PacketFactory.java | 27 ---- .../znpcsplus/packets/V1_14PacketFactory.java | 33 ---- .../znpcsplus/packets/V1_16PacketFactory.java | 27 ---- .../znpcsplus/packets/V1_17PacketFactory.java | 19 +-- .../znpcsplus/packets/V1_19PacketFactory.java | 7 +- .../znpcsplus/packets/V1_8PacketFactory.java | 146 ++++++++---------- .../znpcsplus/packets/V1_9PacketFactory.java | 32 ---- .../znpcsplus/storage/yaml/YamlStorage.java | 11 +- 39 files changed, 357 insertions(+), 365 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NameProperty.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_10PacketFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_11PacketFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_14PacketFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_16PacketFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_9PacketFactory.java 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 b3d3b95..178b365 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 @@ -1,7 +1,10 @@ package lol.pyr.znpcsplus.api.entity; +import java.util.Set; + public interface PropertyHolder { T getProperty(EntityProperty key); boolean hasProperty(EntityProperty key); void setProperty(EntityProperty key, T value); + Set> getAppliedProperties(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 2a93cee..52fb321 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -31,9 +31,11 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.interaction.ActionRegistry; import lol.pyr.znpcsplus.interaction.InteractionPacketListener; -import lol.pyr.znpcsplus.metadata.*; import lol.pyr.znpcsplus.npc.*; -import lol.pyr.znpcsplus.packets.*; +import lol.pyr.znpcsplus.packets.PacketFactory; +import lol.pyr.znpcsplus.packets.V1_17PacketFactory; +import lol.pyr.znpcsplus.packets.V1_19PacketFactory; +import lol.pyr.znpcsplus.packets.V1_8PacketFactory; import lol.pyr.znpcsplus.parsers.*; import lol.pyr.znpcsplus.scheduling.FoliaScheduler; import lol.pyr.znpcsplus.scheduling.SpigotScheduler; @@ -128,8 +130,8 @@ public class ZNpcsPlus extends JavaPlugin { ConfigManager configManager = new ConfigManager(getDataFolder()); MojangSkinCache skinCache = new MojangSkinCache(configManager); EntityPropertyRegistryImpl propertyRegistry = new EntityPropertyRegistryImpl(skinCache); - MetadataFactory metadataFactory = setupMetadataFactory(); - PacketFactory packetFactory = setupPacketFactory(scheduler, metadataFactory, propertyRegistry); + PacketFactory packetFactory = setupPacketFactory(scheduler, propertyRegistry); + propertyRegistry.registerTypes(packetFactory); BungeeConnector bungeeConnector = new BungeeConnector(this); ActionRegistry actionRegistry = new ActionRegistry(); @@ -203,7 +205,6 @@ public class ZNpcsPlus extends JavaPlugin { npc.getHologram().addLineComponent(Component.text("Hello, World!", TextColor.color(255, 0, 0))); npc.getHologram().addLineComponent(Component.text("Hello, World!", TextColor.color(0, 255, 0))); npc.getHologram().addLineComponent(Component.text("Hello, World!", TextColor.color(0, 0, 255))); - npc.setProperty(propertyRegistry.getByName("look", Boolean.class), true); i++; } } @@ -216,15 +217,11 @@ public class ZNpcsPlus extends JavaPlugin { PacketEvents.getAPI().terminate(); } - private PacketFactory setupPacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, EntityPropertyRegistryImpl propertyRegistry) { + private PacketFactory setupPacketFactory(TaskScheduler scheduler, EntityPropertyRegistryImpl propertyRegistry) { HashMap> versions = new HashMap<>(); - versions.put(ServerVersion.V_1_8, LazyLoader.of(() -> new V1_8PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); - versions.put(ServerVersion.V_1_9, LazyLoader.of(() -> new V1_9PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); - versions.put(ServerVersion.V_1_10, LazyLoader.of(() -> new V1_10PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); - versions.put(ServerVersion.V_1_14, LazyLoader.of(() -> new V1_14PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); - versions.put(ServerVersion.V_1_16, LazyLoader.of(() -> new V1_16PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); - versions.put(ServerVersion.V_1_17, LazyLoader.of(() -> new V1_17PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); - versions.put(ServerVersion.V_1_19, LazyLoader.of(() -> new V1_19PacketFactory(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer))); + versions.put(ServerVersion.V_1_8, LazyLoader.of(() -> new V1_8PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer))); + versions.put(ServerVersion.V_1_17, LazyLoader.of(() -> new V1_17PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer))); + versions.put(ServerVersion.V_1_19, LazyLoader.of(() -> new V1_19PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer))); ServerVersion version = packetEvents.getServerManager().getVersion(); if (versions.containsKey(version)) return versions.get(version).get(); @@ -236,31 +233,6 @@ public class ZNpcsPlus extends JavaPlugin { throw new RuntimeException("Unsupported version!"); } - private MetadataFactory setupMetadataFactory() { - HashMap> versions = new HashMap<>(); - versions.put(ServerVersion.V_1_8, LazyLoader.of(V1_8MetadataFactory::new)); - versions.put(ServerVersion.V_1_9, LazyLoader.of(V1_9MetadataFactory::new)); - versions.put(ServerVersion.V_1_10, LazyLoader.of(V1_10MetadataFactory::new)); - versions.put(ServerVersion.V_1_11, LazyLoader.of(V1_11MetadataFactory::new)); - versions.put(ServerVersion.V_1_12, LazyLoader.of(V1_12MetadataFactory::new)); - versions.put(ServerVersion.V_1_13, LazyLoader.of(V1_13MetadataFactory::new)); - versions.put(ServerVersion.V_1_14, LazyLoader.of(V1_14MetadataFactory::new)); - versions.put(ServerVersion.V_1_15, LazyLoader.of(V1_15MetadataFactory::new)); - versions.put(ServerVersion.V_1_16, LazyLoader.of(V1_16MetadataFactory::new)); - versions.put(ServerVersion.V_1_17, LazyLoader.of(V1_17MetadataFactory::new)); - versions.put(ServerVersion.V_1_19, LazyLoader.of(V1_19MetadataFactory::new)); - - ServerVersion version = packetEvents.getServerManager().getVersion(); - if (versions.containsKey(version)) return versions.get(version).get(); - for (ServerVersion v : ServerVersion.reversedValues()) { - if (v.isNewerThan(version)) continue; - if (!versions.containsKey(v)) continue; - return versions.get(v).get(); - } - throw new RuntimeException("Unsupported version!"); - } - - private void registerCommands(NpcRegistryImpl npcRegistry, MojangSkinCache skinCache, BukkitAudiences adventure, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, DataImporterRegistry importerRegistry, diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java index 4bf648d..0fc8b23 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java @@ -28,7 +28,7 @@ public class PropertyRemoveCommand implements CommandHandler { NpcImpl npc = entry.getNpc(); EntityPropertyImpl property = context.parse(EntityPropertyImpl.class); if (!npc.hasProperty(property)) context.halt(Component.text("This npc doesn't have the " + property.getName() + " property set", NamedTextColor.RED)); - npc.removeProperty(property); + npc.setProperty(property, null); context.send(Component.text("Removed property " + property.getName() + " from NPC " + entry.getId(), NamedTextColor.GREEN)); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java index 9db8bc6..2e2fbe6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java @@ -100,7 +100,7 @@ public class ZNpcImporter implements DataImporter { ZNpcsLocation oldLoc = model.getLocation(); NpcLocation location = new NpcLocation(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ(), oldLoc.getYaw(), oldLoc.getPitch()); UUID uuid = model.getUuid() == null ? UUID.randomUUID() : model.getUuid(); - NpcImpl npc = new NpcImpl(uuid, configManager, packetFactory, textSerializer, oldLoc.getWorld(), typeRegistry.getByName(type), location); + NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, oldLoc.getWorld(), typeRegistry.getByName(type), location); HologramImpl hologram = npc.getHologram(); hologram.setOffset(model.getHologramHeight()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java index d390c58..3261e2f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java @@ -1,19 +1,24 @@ package lol.pyr.znpcsplus.entity; +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType; import lol.pyr.znpcsplus.api.entity.EntityProperty; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; +import org.bukkit.entity.Player; -public class EntityPropertyImpl implements EntityProperty { +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class EntityPropertyImpl implements EntityProperty { private final String name; private final T defaultValue; private final Class clazz; - private final PropertySerializer serializer; - protected EntityPropertyImpl(String name, T defaultValue, Class clazz, PropertySerializer serializer) { + protected EntityPropertyImpl(String name, T defaultValue, Class clazz) { this.name = name.toLowerCase(); this.defaultValue = defaultValue; this.clazz = clazz; - this.serializer = serializer; } @Override @@ -21,18 +26,6 @@ public class EntityPropertyImpl implements EntityProperty { return name; } - public String serialize(PropertyHolder holder) { - return serialize(holder.getProperty(this)); - } - - public String serialize(T value) { - return serializer.serialize(value); - } - - public T deserialize(String str) { - return serializer.deserialize(str); - } - @Override public T getDefaultValue() { return defaultValue; @@ -41,4 +34,21 @@ public class EntityPropertyImpl implements EntityProperty { public Class getType() { return clazz; } + + protected static EntityData newEntityData(int index, EntityDataType type, V value) { + return new EntityData(index, type, value); + } + + public List makeStandaloneData(T value, Player player, PacketEntity packetEntity, boolean isSpawned) { + Map map = new HashMap<>(); + apply(value, player, packetEntity, isSpawned, map); + return new ArrayList<>(map.values()); + } + + abstract public void apply(T value, Player player, PacketEntity entity, boolean isSpawned, Map properties); + + @SuppressWarnings("unchecked") + public void UNSAFE_update(Object value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + apply((T) value, player, entity, isSpawned, properties); + } } \ No newline at end of file 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 2b7132a..44aa521 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -1,15 +1,13 @@ package lol.pyr.znpcsplus.entity; -import com.github.retrooper.packetevents.protocol.item.ItemStack; +import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; -import lol.pyr.znpcsplus.api.skin.SkinDescriptor; +import lol.pyr.znpcsplus.entity.properties.*; import lol.pyr.znpcsplus.entity.serializers.*; +import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; import lol.pyr.znpcsplus.util.*; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.Color; import org.bukkit.DyeColor; import java.util.Collection; @@ -18,6 +16,20 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; +/** + * 1.8 ... + * 1.9 ... + * 1.10 ... + * 1.11 ... + * 1.12 ... + * 1.13 ... + * 1.14 ... + * 1.15 ... + * 1.16 ... + * 1.17 ... + * 1.18-1.19 ... + * 1.20 ... + */ @SuppressWarnings("unchecked") public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { private final Map, PropertySerializer> serializerMap = new HashMap<>(); @@ -44,7 +56,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerType.class); registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerLevel.class); - + /* registerType("glow", NamedTextColor.class); registerType("fire", false); registerType("invisible", false); @@ -226,6 +238,22 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Slime registerType("slime_size", 0); // TODO + */ + } + + public void registerTypes(PacketFactory packetFactory) { + register(new EquipmentProperty(packetFactory, "helmet", EquipmentSlot.HELMET)); + register(new EquipmentProperty(packetFactory, "chestplate", EquipmentSlot.CHEST_PLATE)); + register(new EquipmentProperty(packetFactory, "leggings", EquipmentSlot.LEGGINGS)); + register(new EquipmentProperty(packetFactory, "boots", EquipmentSlot.BOOTS)); + register(new EquipmentProperty(packetFactory, "hand", EquipmentSlot.MAIN_HAND)); + register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_HAND)); + + register(new NameProperty()); + register(new DummyBooleanProperty("look", false)); + register(new GlowProperty(packetFactory)); + register(new EffectsProperty("fire", 0x01)); + register(new EffectsProperty("invisible", 0x20)); } private void registerSerializer(PropertySerializer serializer) { @@ -236,18 +264,12 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { serializerMap.put(clazz, new EnumPropertySerializer<>(clazz)); } - private void registerType(String name, Class type) { - registerType(name, null, type); + private void register(EntityPropertyImpl property) { + byName.put(property.getName(), property); } - private void registerType(String name, T defaultValue) { - registerType(name, defaultValue, (Class) defaultValue.getClass()); - } - - private void registerType(String name, T defaultValue, Class clazz) { - if (clazz == null) return; - EntityPropertyImpl property = new EntityPropertyImpl<>(name, defaultValue, clazz, (PropertySerializer) serializerMap.get(clazz)); - byName.put(name.toLowerCase(), property); + public PropertySerializer getSerializer(Class type) { + return (PropertySerializer) serializerMap.get(type); } @Override 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 3424f07..d933679 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java @@ -66,11 +66,6 @@ public class PacketEntity { packetFactory.sendAllMetadata(player, this, properties); } - public void remakeTeam(Player player) { - packetFactory.removeTeam(player, this); - packetFactory.createTeam(player, this, properties); - } - private static int reserveEntityID() { if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) { return Reflections.ATOMIC_ENTITY_ID_FIELD.get().incrementAndGet(); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PropertySerializer.java index 73c8182..abd2f39 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PropertySerializer.java @@ -4,4 +4,9 @@ public interface PropertySerializer { String serialize(T property); T deserialize(String property); Class getTypeClass(); + + @SuppressWarnings("unchecked") + default String UNSAFE_serialize(Object property) { + return serialize((T) property); + } } \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java new file mode 100644 index 0000000..105e6ab --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java @@ -0,0 +1,18 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class DummyBooleanProperty extends EntityPropertyImpl { + public DummyBooleanProperty(String name, boolean def) { + super(name, def, Boolean.class); + } + + @Override + public void apply(Boolean value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java new file mode 100644 index 0000000..91171af --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java @@ -0,0 +1,25 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class EffectsProperty extends EntityPropertyImpl { + private final int bitmask; + + public EffectsProperty(String name, int bitmask) { + super(name, false, Boolean.class); + this.bitmask = bitmask; + } + + @Override + public void apply(Boolean enabled, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + EntityData oldData = properties.get(0); + byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); + properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (enabled ? bitmask : 0)))); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java new file mode 100644 index 0000000..25171d8 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java @@ -0,0 +1,28 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.item.ItemStack; +import com.github.retrooper.packetevents.protocol.player.Equipment; +import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.packets.PacketFactory; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class EquipmentProperty extends EntityPropertyImpl { + private final PacketFactory packetFactory; + private final EquipmentSlot slot; + + public EquipmentProperty(PacketFactory packetFactory, String name, EquipmentSlot slot) { + super(name, null, ItemStack.class); + this.packetFactory = packetFactory; + this.slot = slot; + } + + @Override + public void apply(ItemStack value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + packetFactory.sendEquipment(player, entity, new Equipment(slot, value)); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java new file mode 100644 index 0000000..b4221e6 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java @@ -0,0 +1,29 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.packets.PacketFactory; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class GlowProperty extends EntityPropertyImpl { + private final PacketFactory packetFactory; + + public GlowProperty(PacketFactory packetFactory) { + super("glow", null, NamedTextColor.class); + this.packetFactory = packetFactory; + } + + @Override + public void apply(NamedTextColor value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + EntityData oldData = properties.get(0); + byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); + properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (value == null ? 0 : 0x40)))); + if (isSpawned) packetFactory.removeTeam(player, entity); + packetFactory.createTeam(player, entity, value); + } +} 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 new file mode 100644 index 0000000..d4cc7a3 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NameProperty.java @@ -0,0 +1,41 @@ +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; +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 NameProperty extends EntityPropertyImpl { + private final boolean legacy; + private final boolean optionalComponent; + + public NameProperty() { + 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); + } + + @Override + public void apply(Component value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + if (value != null) { + String serialized = legacy ? + AdventureSerializer.getLegacyGsonSerializer().serialize(value) : + AdventureSerializer.getGsonSerializer().serialize(value); + if (optionalComponent) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized))); + else properties.put(2, newEntityData(2, EntityDataTypes.STRING, serialized)); + } + + if (legacy) properties.put(3, newEntityData(3, EntityDataTypes.BYTE, (byte) (value != null ? 1 : 0))); + else properties.put(3, newEntityData(3, EntityDataTypes.BOOLEAN, value != null)); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java index 6a83251..f85301e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java @@ -2,6 +2,7 @@ package lol.pyr.znpcsplus.hologram; import lol.pyr.znpcsplus.api.hologram.Hologram; import lol.pyr.znpcsplus.config.ConfigManager; +import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.util.Viewable; import lol.pyr.znpcsplus.util.NpcLocation; @@ -17,6 +18,7 @@ public class HologramImpl extends Viewable implements Hologram { private final ConfigManager configManager; private final PacketFactory packetFactory; private final LegacyComponentSerializer textSerializer; + private final EntityPropertyRegistryImpl propertyRegistry; private double offset = 0.0; private long refreshDelay = -1; @@ -24,7 +26,8 @@ public class HologramImpl extends Viewable implements Hologram { private NpcLocation location; private final List lines = new ArrayList<>(); - public HologramImpl(ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, NpcLocation location) { + public HologramImpl(EntityPropertyRegistryImpl propertyRegistry, ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, NpcLocation location) { + this.propertyRegistry = propertyRegistry; this.configManager = configManager; this.packetFactory = packetFactory; this.textSerializer = textSerializer; @@ -32,7 +35,7 @@ public class HologramImpl extends Viewable implements Hologram { } public void addLineComponent(Component line) { - HologramLine newLine = new HologramLine(packetFactory, null, line); + HologramLine newLine = new HologramLine(propertyRegistry, packetFactory, null, line); lines.add(newLine); relocateLines(newLine); for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); @@ -66,7 +69,7 @@ public class HologramImpl extends Viewable implements Hologram { } public void insertLineComponent(int index, Component line) { - HologramLine newLine = new HologramLine(packetFactory, null, line); + HologramLine newLine = new HologramLine(propertyRegistry, packetFactory, null, line); lines.add(index, newLine); relocateLines(newLine); for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); 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 883bacb..895df3e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.hologram; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.PropertyHolder; +import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.util.NpcLocation; @@ -10,13 +11,19 @@ import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; public class HologramLine implements PropertyHolder { private Component text; private final PacketEntity armorStand; + private final Set> properties; - public HologramLine(PacketFactory packetFactory, NpcLocation location, Component text) { + public HologramLine(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, Component text) { this.text = text; + this.properties = new HashSet<>(); + this.properties.add(propertyRegistry.getByName("name")); + this.properties.add(propertyRegistry.getByName("invisible")); armorStand = new PacketEntity(packetFactory, this, EntityTypes.ARMOR_STAND, location); } @@ -61,4 +68,9 @@ public class HologramLine implements PropertyHolder { public void setProperty(EntityProperty key, T value) { throw new UnsupportedOperationException("Can't set properties on a hologram"); } + + @Override + public Set> getAppliedProperties() { + return properties; + } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 9dcaae3..4d8619a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -20,6 +20,7 @@ import org.bukkit.DyeColor; * 1.18-1.19 ... * 1.20 ... */ +@Deprecated public interface MetadataFactory { EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean usingItemLegacy); EntityData silent(boolean enabled); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java index 903df8f..8c136c5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java @@ -5,6 +5,7 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.Vector3f; +@Deprecated public class V1_10MetadataFactory extends V1_9MetadataFactory { @Override public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java index c0ba2df..fb68a00 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java @@ -3,12 +3,8 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +@Deprecated public class V1_11MetadataFactory extends V1_10MetadataFactory { - @Override - public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean usingItemLegacy) { - return super.effects(onFire, glowing, invisible, usingElytra, false); - } - @Override public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { return newEntityData(6, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0))); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java index 9616a5e..66660b4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java @@ -6,6 +6,7 @@ import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; import lol.pyr.znpcsplus.entity.ParrotNBTCompound; import lol.pyr.znpcsplus.util.ParrotVariant; +@Deprecated public class V1_12MetadataFactory extends V1_11MetadataFactory { @Override public EntityData shoulderEntityLeft(ParrotVariant variant) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java index 854549c..7d3b266 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java @@ -7,6 +7,7 @@ import net.kyori.adventure.text.Component; import java.util.Optional; +@Deprecated public class V1_13MetadataFactory extends V1_12MetadataFactory { @Override public EntityData name(Component name) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index bd34101..ac7bf09 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -10,6 +10,7 @@ import lol.pyr.znpcsplus.util.ParrotVariant; import lol.pyr.znpcsplus.util.Vector3f; import org.bukkit.DyeColor; +@Deprecated public class V1_14MetadataFactory extends V1_13MetadataFactory { @Override public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java index 0b53db8..93a1461 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java @@ -9,6 +9,7 @@ import lol.pyr.znpcsplus.util.ParrotVariant; import lol.pyr.znpcsplus.util.Vector3f; import org.bukkit.DyeColor; +@Deprecated public class V1_15MetadataFactory extends V1_14MetadataFactory { @Override public EntityData shoulderEntityLeft(ParrotVariant variant) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java index d728fa7..d3862f3 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +@Deprecated public class V1_16MetadataFactory extends V1_15MetadataFactory { @Override public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index 8fe26ef..c76536c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -9,6 +9,7 @@ import lol.pyr.znpcsplus.util.ParrotVariant; import lol.pyr.znpcsplus.util.Vector3f; import org.bukkit.DyeColor; +@Deprecated public class V1_17MetadataFactory extends V1_16MetadataFactory { @Override public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java index 562007d..c39fb4a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java @@ -2,8 +2,8 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import lol.pyr.znpcsplus.util.FrogVariant; +@Deprecated public class V1_19MetadataFactory extends V1_17MetadataFactory { @Override public EntityData frogVariant(int variant) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 4ae8045..7a86c1d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -9,6 +9,7 @@ import lol.pyr.znpcsplus.util.*; import net.kyori.adventure.text.Component; import org.bukkit.DyeColor; +@Deprecated public class V1_8MetadataFactory implements MetadataFactory { @Override public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java index d368509..433d1c8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java @@ -6,6 +6,7 @@ import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; import lol.pyr.znpcsplus.util.CreeperState; import net.kyori.adventure.text.Component; +@Deprecated public class V1_9MetadataFactory extends V1_8MetadataFactory { @Override public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { 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 9bb6b09..cd4407b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -1,9 +1,11 @@ package lol.pyr.znpcsplus.npc; +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.npc.Npc; import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.hologram.HologramImpl; import lol.pyr.znpcsplus.interaction.InteractionAction; @@ -31,18 +33,18 @@ public class NpcImpl extends Viewable implements Npc { private final Map, Object> propertyMap = new HashMap<>(); private final List actions = new ArrayList<>(); - protected NpcImpl(UUID uuid, ConfigManager configManager, LegacyComponentSerializer textSerializer, World world, NpcTypeImpl type, NpcLocation location, PacketFactory packetFactory) { - this(uuid, configManager, packetFactory, textSerializer, world.getName(), type, location); + protected NpcImpl(UUID uuid, EntityPropertyRegistryImpl propertyRegistry, ConfigManager configManager, LegacyComponentSerializer textSerializer, World world, NpcTypeImpl type, NpcLocation location, PacketFactory packetFactory) { + this(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world.getName(), type, location); } - public NpcImpl(UUID uuid, ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, String world, NpcTypeImpl type, NpcLocation location) { + public NpcImpl(UUID uuid, EntityPropertyRegistryImpl propertyRegistry, ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, String world, NpcTypeImpl type, NpcLocation location) { this.packetFactory = packetFactory; this.worldName = world; this.type = type; this.location = location; this.uuid = uuid; entity = new PacketEntity(packetFactory, this, type.getType(), location); - hologram = new HologramImpl(configManager, packetFactory, textSerializer, location.withY(location.getY() + type.getHologramOffset())); + hologram = new HologramImpl(propertyRegistry, configManager, packetFactory, textSerializer, location.withY(location.getY() + type.getHologramOffset())); } @@ -112,12 +114,11 @@ public class NpcImpl extends Viewable implements Npc { hologram.hide(player); } - private void UNSAFE_refreshMeta() { - for (Player viewer : getViewers()) entity.refreshMeta(viewer); - } - - private void UNSAFE_remakeTeam() { - for (Player viewer : getViewers()) entity.remakeTeam(viewer); + private void UNSAFE_refreshProperty(EntityPropertyImpl property) { + for (Player viewer : getViewers()) { + List data = property.makeStandaloneData(property.getDefaultValue(), viewer, entity, true); + if (data.size() > 0) packetFactory.sendMetadata(viewer, entity, data); + } } @SuppressWarnings("unchecked") @@ -135,10 +136,9 @@ public class NpcImpl extends Viewable implements Npc { } public void setProperty(EntityPropertyImpl key, T value) { - if (value == null || value.equals(key.getDefaultValue())) removeProperty(key); + if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key); else propertyMap.put(key, value); - UNSAFE_refreshMeta(); - if (key.getName().equalsIgnoreCase("glow")) UNSAFE_remakeTeam(); + UNSAFE_refreshProperty(key); } @SuppressWarnings("unchecked") @@ -146,14 +146,8 @@ public class NpcImpl extends Viewable implements Npc { setProperty((EntityPropertyImpl) property, (T) value); } - public void removeProperty(EntityPropertyImpl key) { - propertyMap.remove(key); - UNSAFE_refreshMeta(); - if (key.getName().equalsIgnoreCase("glow")) UNSAFE_remakeTeam(); - else if (key.getName().equalsIgnoreCase("dinnerbone")) respawn(); - } - - public Set> getAppliedProperties() { + @Override + public Set> getAppliedProperties() { return Collections.unmodifiableSet(propertyMap.keySet()); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java index 062f4ad..914695a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java @@ -22,6 +22,7 @@ public class NpcRegistryImpl implements NpcRegistry { private final PacketFactory packetFactory; private final ConfigManager configManager; private final LegacyComponentSerializer textSerializer; + private final EntityPropertyRegistryImpl propertyRegistry; private final List npcList = new ArrayList<>(); private final Map npcIdLookupMap = new HashMap<>(); @@ -29,6 +30,7 @@ public class NpcRegistryImpl implements NpcRegistry { public NpcRegistryImpl(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, TaskScheduler scheduler, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { this.textSerializer = textSerializer; + this.propertyRegistry = propertyRegistry; storage = configManager.getConfig().storageType().create(configManager, plugin, packetFactory, actionRegistry, typeRegistry, propertyRegistry, textSerializer); this.packetFactory = packetFactory; this.configManager = configManager; @@ -134,7 +136,7 @@ public class NpcRegistryImpl implements NpcRegistry { public NpcEntryImpl create(String id, World world, NpcTypeImpl type, NpcLocation location) { id = id.toLowerCase(); if (npcIdLookupMap.containsKey(id)) throw new IllegalArgumentException("An npc with the id " + id + " already exists!"); - NpcImpl npc = new NpcImpl(UUID.randomUUID(), configManager, textSerializer, world, type, location, packetFactory); + NpcImpl npc = new NpcImpl(UUID.randomUUID(), propertyRegistry, configManager, textSerializer, world, type, location, packetFactory); NpcEntryImpl entry = new NpcEntryImpl(id, npc); register(entry); return entry; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java index a7ae861..87df253 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java @@ -1,12 +1,13 @@ package lol.pyr.znpcsplus.packets; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.player.Equipment; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.entity.PacketEntity; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.entity.Player; import java.util.List; -import java.util.Map; import java.util.concurrent.CompletableFuture; public interface PacketFactory { @@ -16,10 +17,9 @@ public interface PacketFactory { void teleportEntity(Player player, PacketEntity entity); CompletableFuture addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties); void removeTabPlayer(Player player, PacketEntity entity); - void createTeam(Player player, PacketEntity entity, PropertyHolder properties); + void createTeam(Player player, PacketEntity entity, NamedTextColor glowColor); void removeTeam(Player player, PacketEntity entity); - Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties); void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties); + void sendEquipment(Player player, PacketEntity entity, Equipment equipment); void sendMetadata(Player player, PacketEntity entity, List data); - void sendEquipment(Player player, PacketEntity entity, PropertyHolder properties); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_10PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_10PacketFactory.java deleted file mode 100644 index bd3fe90..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_10PacketFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package lol.pyr.znpcsplus.packets; - -import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.Map; - -public class V1_10PacketFactory extends V1_9PacketFactory { - public V1_10PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); - } - - @Override - public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - Map data = super.generateMetadata(player, entity, properties); - add(data, metadataFactory.noGravity()); - return data; - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_11PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_11PacketFactory.java deleted file mode 100644 index de725ff..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_11PacketFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package lol.pyr.znpcsplus.packets; - -import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.Map; - -public class V1_11PacketFactory extends V1_10PacketFactory { - public V1_11PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); - } - - @Override - public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - Map data = super.generateMetadata(player, entity, properties); - add(data, metadataFactory.usingItem(properties.getProperty(propertyRegistry.getByName("using_item", Boolean.class)), false, false)); - return data; - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_14PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_14PacketFactory.java deleted file mode 100644 index 7e80157..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_14PacketFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -package lol.pyr.znpcsplus.packets; - -import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import lol.pyr.znpcsplus.util.NpcPose; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.Map; - -public class V1_14PacketFactory extends V1_11PacketFactory { - public V1_14PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); - } - - @Override - public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - Map data = super.generateMetadata(player, entity, properties); - add(data, metadataFactory.pose(adaptNpcPose(properties.getProperty(propertyRegistry.getByName("pose", NpcPose.class))))); - return data; - } - - protected EntityPose adaptNpcPose(NpcPose pose) { - return EntityPose.valueOf(pose.name()); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_16PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_16PacketFactory.java deleted file mode 100644 index 3681218..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_16PacketFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package lol.pyr.znpcsplus.packets; - -import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.protocol.player.Equipment; -import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.List; - -public class V1_16PacketFactory extends V1_14PacketFactory { - public V1_16PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); - } - - @Override - public void sendEquipment(Player player, PacketEntity entity, PropertyHolder properties) { - List equipments = generateEquipments(properties); - if (equipments.size() > 0) sendPacket(player, new WrapperPlayServerEntityEquipment(entity.getEntityId(), equipments)); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java index 81aed5e..d86755a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java @@ -1,25 +1,23 @@ package lol.pyr.znpcsplus.packets; import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.util.NpcLocation; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import java.util.Map; import java.util.Optional; -public class V1_17PacketFactory extends V1_16PacketFactory { - public V1_17PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); +public class V1_17PacketFactory extends V1_8PacketFactory { + public V1_17PacketFactory(TaskScheduler scheduler, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + super(scheduler, packetEvents, propertyRegistry, textSerializer); } @Override @@ -28,13 +26,6 @@ public class V1_17PacketFactory extends V1_16PacketFactory { sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d()))); sendAllMetadata(player, entity, properties); - createTeam(player, entity, properties); - } - - @Override - public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - Map data = super.generateMetadata(player, entity, properties); - add(data, metadataFactory.shaking(properties.getProperty(propertyRegistry.getByName("shaking", Boolean.class)))); - return data; + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_19PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_19PacketFactory.java index e078ebc..d7a552b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_19PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_19PacketFactory.java @@ -7,10 +7,9 @@ import com.github.retrooper.packetevents.protocol.player.GameMode; import com.github.retrooper.packetevents.protocol.player.UserProfile; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate; +import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.metadata.MetadataFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -22,8 +21,8 @@ import java.util.concurrent.CompletableFuture; public class V1_19PacketFactory extends V1_17PacketFactory { private final boolean oldTabPackets; - public V1_19PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); + public V1_19PacketFactory(TaskScheduler scheduler, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + super(scheduler, packetEvents, propertyRegistry, textSerializer); oldTabPackets = packetEvents.getServerManager().getVersion().isOlderThanOrEquals(ServerVersion.V_1_19_2); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index 2db3255..2437955 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -1,29 +1,28 @@ package lol.pyr.znpcsplus.packets; -import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; -import com.github.retrooper.packetevents.protocol.item.ItemStack; -import com.github.retrooper.packetevents.protocol.player.*; +import com.github.retrooper.packetevents.protocol.player.ClientVersion; +import com.github.retrooper.packetevents.protocol.player.Equipment; +import com.github.retrooper.packetevents.protocol.player.GameMode; +import com.github.retrooper.packetevents.protocol.player.UserProfile; import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.wrapper.PacketWrapper; import com.github.retrooper.packetevents.wrapper.play.server.*; +import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.api.skin.SkinDescriptor; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.skin.BaseSkinDescriptor; -import lol.pyr.znpcsplus.util.*; +import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.Color; -import org.bukkit.DyeColor; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -32,14 +31,12 @@ import java.util.concurrent.CompletableFuture; public class V1_8PacketFactory implements PacketFactory { protected final TaskScheduler scheduler; - protected final MetadataFactory metadataFactory; protected final PacketEventsAPI packetEvents; protected final EntityPropertyRegistryImpl propertyRegistry; protected final LegacyComponentSerializer textSerializer; - public V1_8PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + public V1_8PacketFactory(TaskScheduler scheduler, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { this.scheduler = scheduler; - this.metadataFactory = metadataFactory; this.packetEvents = packetEvents; this.propertyRegistry = propertyRegistry; this.textSerializer = textSerializer; @@ -48,7 +45,7 @@ public class V1_8PacketFactory implements PacketFactory { @Override public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) { addTabPlayer(player, entity, properties).thenAccept(ignored -> { - createTeam(player, entity, properties); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); NpcLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), entity.getUuid(), npcLocationToVector(location), location.getYaw(), location.getPitch(), Collections.emptyList())); @@ -69,7 +66,7 @@ public class V1_8PacketFactory implements PacketFactory { new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); sendAllMetadata(player, entity, properties); - createTeam(player, entity, properties); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); } protected Vector3d npcLocationToVector(NpcLocation location) { @@ -111,12 +108,12 @@ public class V1_8PacketFactory implements PacketFactory { } @Override - public void createTeam(Player player, PacketEntity entity, PropertyHolder properties) { + public void createTeam(Player player, PacketEntity entity, NamedTextColor glowColor) { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.CREATE, new WrapperPlayServerTeams.ScoreBoardTeamInfo( Component.empty(), Component.empty(), Component.empty(), WrapperPlayServerTeams.NameTagVisibility.NEVER, WrapperPlayServerTeams.CollisionRule.NEVER, - properties.hasProperty(propertyRegistry.getByName("glow")) ? properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class)) : NamedTextColor.WHITE, + glowColor == null ? NamedTextColor.WHITE : glowColor, WrapperPlayServerTeams.OptionData.NONE ))); sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null, @@ -128,21 +125,20 @@ public class V1_8PacketFactory implements PacketFactory { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.REMOVE, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null)); } - @Override - public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - HashMap data = new HashMap<>(); - add(data, metadataFactory.effects( + /* + List data = new ArrayList<>(); + data.add(metadataFactory.effects( properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)), false, properties.getProperty(propertyRegistry.getByName("invisible", Boolean.class)), false, properties.getProperty(propertyRegistry.getByName("using_item", Boolean.class)) )); - add(data, metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class)))); - add(data, metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", Color.class)).asRGB())); - add(data, metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class)))); + data.add(metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class)))); + data.add(metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", Color.class)).asRGB())); + data.add(metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class)))); if (entity.getType().equals(EntityTypes.PLAYER)) { - add(data, metadataFactory.skinLayers( + data.add(metadataFactory.skinLayers( properties.getProperty(propertyRegistry.getByName("skin_cape", Boolean.class)), properties.getProperty(propertyRegistry.getByName("skin_jacket", Boolean.class)), properties.getProperty(propertyRegistry.getByName("skin_left_sleeve", Boolean.class)), @@ -151,60 +147,60 @@ public class V1_8PacketFactory implements PacketFactory { properties.getProperty(propertyRegistry.getByName("skin_right_leg", Boolean.class)), properties.getProperty(propertyRegistry.getByName("skin_hat", Boolean.class)) )); - add(data, metadataFactory.shoulderEntityLeft(properties.getProperty(propertyRegistry.getByName("shoulder_entity_left", ParrotVariant.class)))); - add(data, metadataFactory.shoulderEntityRight(properties.getProperty(propertyRegistry.getByName("shoulder_entity_right", ParrotVariant.class)))); + data.add(metadataFactory.shoulderEntityLeft(properties.getProperty(propertyRegistry.getByName("shoulder_entity_left", ParrotVariant.class)))); + data.add(metadataFactory.shoulderEntityRight(properties.getProperty(propertyRegistry.getByName("shoulder_entity_right", ParrotVariant.class)))); } else if (entity.getType().equals(EntityTypes.ARMOR_STAND)) { - add(data, metadataFactory.armorStandProperties( + data.add(metadataFactory.armorStandProperties( properties.getProperty(propertyRegistry.getByName("small", Boolean.class)), properties.getProperty(propertyRegistry.getByName("arms", Boolean.class)), !properties.getProperty(propertyRegistry.getByName("base_plate", Boolean.class)) )); - add(data, metadataFactory.armorStandHeadRotation(properties.getProperty(propertyRegistry.getByName("head_rotation", Vector3f.class)))); - add(data, metadataFactory.armorStandBodyRotation(properties.getProperty(propertyRegistry.getByName("body_rotation", Vector3f.class)))); - add(data, metadataFactory.armorStandLeftArmRotation(properties.getProperty(propertyRegistry.getByName("left_arm_rotation", Vector3f.class)))); - add(data, metadataFactory.armorStandRightArmRotation(properties.getProperty(propertyRegistry.getByName("right_arm_rotation", Vector3f.class)))); - add(data, metadataFactory.armorStandLeftLegRotation(properties.getProperty(propertyRegistry.getByName("left_leg_rotation", Vector3f.class)))); - add(data, metadataFactory.armorStandRightLegRotation(properties.getProperty(propertyRegistry.getByName("right_leg_rotation", Vector3f.class)))); + data.add(metadataFactory.armorStandHeadRotation(properties.getProperty(propertyRegistry.getByName("head_rotation", Vector3f.class)))); + data.add(metadataFactory.armorStandBodyRotation(properties.getProperty(propertyRegistry.getByName("body_rotation", Vector3f.class)))); + data.add(metadataFactory.armorStandLeftArmRotation(properties.getProperty(propertyRegistry.getByName("left_arm_rotation", Vector3f.class)))); + data.add(metadataFactory.armorStandRightArmRotation(properties.getProperty(propertyRegistry.getByName("right_arm_rotation", Vector3f.class)))); + data.add(metadataFactory.armorStandLeftLegRotation(properties.getProperty(propertyRegistry.getByName("left_leg_rotation", Vector3f.class)))); + data.add(metadataFactory.armorStandRightLegRotation(properties.getProperty(propertyRegistry.getByName("right_leg_rotation", Vector3f.class)))); } else if (entity.getType().equals(EntityTypes.AXOLOTL)) { - add(data, metadataFactory.axolotlVariant(properties.getProperty(propertyRegistry.getByName("axolotl_variant", Integer.class)))); - add(data, metadataFactory.playingDead(properties.getProperty(propertyRegistry.getByName("playing_dead", Boolean.class)))); + data.add(metadataFactory.axolotlVariant(properties.getProperty(propertyRegistry.getByName("axolotl_variant", Integer.class)))); + data.add(metadataFactory.playingDead(properties.getProperty(propertyRegistry.getByName("playing_dead", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.BAT)) { - add(data, metadataFactory.batHanging(properties.getProperty(propertyRegistry.getByName("hanging", Boolean.class)))); + data.add(metadataFactory.batHanging(properties.getProperty(propertyRegistry.getByName("hanging", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.BEE)) { - add(data, metadataFactory.beeAngry(properties.getProperty(propertyRegistry.getByName("angry", Boolean.class)))); - add(data, metadataFactory.beeHasNectar(properties.getProperty(propertyRegistry.getByName("has_nectar", Boolean.class)))); + data.add(metadataFactory.beeAngry(properties.getProperty(propertyRegistry.getByName("angry", Boolean.class)))); + data.add(metadataFactory.beeHasNectar(properties.getProperty(propertyRegistry.getByName("has_nectar", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.BLAZE)) { - add(data, metadataFactory.blazeOnFire(properties.getProperty(propertyRegistry.getByName("blaze_on_fire", Boolean.class)))); + data.add(metadataFactory.blazeOnFire(properties.getProperty(propertyRegistry.getByName("blaze_on_fire", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.CAT)) { - add(data, metadataFactory.catVariant(properties.getProperty(propertyRegistry.getByName("cat_variant", CatVariant.class)))); - add(data, metadataFactory.catLying(properties.getProperty(propertyRegistry.getByName("cat_lying", Boolean.class)))); - add(data, metadataFactory.catCollarColor(properties.getProperty(propertyRegistry.getByName("cat_collar_color", DyeColor.class)))); - add(data, metadataFactory.catTamed(properties.hasProperty(propertyRegistry.getByName("cat_collar_color", DyeColor.class)))); + data.add(metadataFactory.catVariant(properties.getProperty(propertyRegistry.getByName("cat_variant", CatVariant.class)))); + data.add(metadataFactory.catLying(properties.getProperty(propertyRegistry.getByName("cat_lying", Boolean.class)))); + data.add(metadataFactory.catCollarColor(properties.getProperty(propertyRegistry.getByName("cat_collar_color", DyeColor.class)))); + data.add(metadataFactory.catTamed(properties.hasProperty(propertyRegistry.getByName("cat_collar_color", DyeColor.class)))); } else if (entity.getType().equals(EntityTypes.CREEPER)) { - add(data, metadataFactory.creeperState(properties.getProperty(propertyRegistry.getByName("creeper_state", CreeperState.class)))); - add(data, metadataFactory.creeperCharged(properties.getProperty(propertyRegistry.getByName("creeper_charged", Boolean.class)))); + data.add(metadataFactory.creeperState(properties.getProperty(propertyRegistry.getByName("creeper_state", CreeperState.class)))); + data.add(metadataFactory.creeperCharged(properties.getProperty(propertyRegistry.getByName("creeper_charged", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.ENDERMAN)) { - add(data, metadataFactory.endermanHeldBlock( + data.add(metadataFactory.endermanHeldBlock( properties.getProperty(propertyRegistry.getByName("enderman_held_block", BlockState.class)).getGlobalId()) ); - add(data, metadataFactory.endermanScreaming(properties.getProperty(propertyRegistry.getByName("enderman_screaming", Boolean.class)))); - add(data, metadataFactory.endermanStaring(properties.getProperty(propertyRegistry.getByName("enderman_staring", Boolean.class)))); + data.add(metadataFactory.endermanScreaming(properties.getProperty(propertyRegistry.getByName("enderman_screaming", Boolean.class)))); + data.add(metadataFactory.endermanStaring(properties.getProperty(propertyRegistry.getByName("enderman_staring", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.EVOKER)) { - add(data, metadataFactory.evokerSpell(properties.getProperty(propertyRegistry.getByName("evoker_spell", SpellType.class)).ordinal())); + data.add(metadataFactory.evokerSpell(properties.getProperty(propertyRegistry.getByName("evoker_spell", SpellType.class)).ordinal())); } else if (entity.getType().equals(EntityTypes.FOX)) { // Not sure if this should be in here or in 1.14 PacketFactory - add(data, metadataFactory.foxVariant(properties.getProperty(propertyRegistry.getByName("fox_variant", FoxVariant.class)).ordinal())); - add(data, metadataFactory.foxProperties( + data.add(metadataFactory.foxVariant(properties.getProperty(propertyRegistry.getByName("fox_variant", FoxVariant.class)).ordinal())); + data.add(metadataFactory.foxProperties( properties.getProperty(propertyRegistry.getByName("fox_sitting", Boolean.class)), properties.getProperty(propertyRegistry.getByName("fox_crouching", Boolean.class)), properties.getProperty(propertyRegistry.getByName("fox_sleeping", Boolean.class)), @@ -212,20 +208,20 @@ public class V1_8PacketFactory implements PacketFactory { )); } else if (entity.getType().equals(EntityTypes.FROG)) { - add(data, metadataFactory.frogVariant(properties.getProperty(propertyRegistry.getByName("frog_variant", FrogVariant.class)).ordinal())); + data.add(metadataFactory.frogVariant(properties.getProperty(propertyRegistry.getByName("frog_variant", FrogVariant.class)).ordinal())); } else if (entity.getType().equals(EntityTypes.GHAST)) { - add(data, metadataFactory.ghastAttacking(properties.getProperty(propertyRegistry.getByName("attacking", Boolean.class)))); + data.add(metadataFactory.ghastAttacking(properties.getProperty(propertyRegistry.getByName("attacking", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.GOAT)) { - add(data, metadataFactory.goatHasLeftHorn(properties.getProperty(propertyRegistry.getByName("has_left_horn", Boolean.class)))); - add(data, metadataFactory.goatHasRightHorn(properties.getProperty(propertyRegistry.getByName("has_right_horn", Boolean.class)))); + data.add(metadataFactory.goatHasLeftHorn(properties.getProperty(propertyRegistry.getByName("has_left_horn", Boolean.class)))); + data.add(metadataFactory.goatHasRightHorn(properties.getProperty(propertyRegistry.getByName("has_right_horn", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.GUARDIAN)) { // TODO } else if (entity.getType().equals(EntityTypes.HOGLIN)) { - add(data, metadataFactory.hoglinImmuneToZombification(properties.getProperty(propertyRegistry.getByName("immune_to_zombification", Boolean.class)))); + data.add(metadataFactory.hoglinImmuneToZombification(properties.getProperty(propertyRegistry.getByName("immune_to_zombification", Boolean.class)))); } else if (entity.getType().equals(EntityTypes.VILLAGER)) { VillagerProfession profession = properties.getProperty(propertyRegistry.getByName("villager_profession", VillagerProfession.class)); @@ -233,7 +229,7 @@ public class V1_8PacketFactory implements PacketFactory { if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_14)) { professionId = profession.getLegacyId(); } - add(data, metadataFactory.villagerData( + data.add(metadataFactory.villagerData( properties.getProperty(propertyRegistry.getByName("villager_type", VillagerType.class)).ordinal(), professionId, properties.getProperty(propertyRegistry.getByName("villager_level", VillagerLevel.class)).ordinal() + 1 @@ -241,47 +237,31 @@ public class V1_8PacketFactory implements PacketFactory { } if (properties.getProperty(propertyRegistry.getByName("dinnerbone", Boolean.class))) { - add(data, metadataFactory.name(Component.text("Dinnerbone"))); + data.add(metadataFactory.name(Component.text("Dinnerbone"))); } else if (properties.hasProperty(propertyRegistry.getByName("name"))) { - add(data, metadataFactory.name(PapiUtil.set(textSerializer, player, properties.getProperty(propertyRegistry.getByName("name", Component.class))))); - add(data, metadataFactory.nameShown()); + data.add(metadataFactory.name(PapiUtil.set(textSerializer, player, properties.getProperty(propertyRegistry.getByName("name", Component.class))))); + data.add(metadataFactory.nameShown()); } return data; - } + */ @Override public void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - sendMetadata(player, entity, new ArrayList<>(generateMetadata(player, entity, properties).values())); - sendEquipment(player, entity, properties); + Map datas = new HashMap<>(); + for (EntityProperty property : properties.getAppliedProperties()) + ((EntityPropertyImpl) property).UNSAFE_update(properties.getProperty(property), player, entity, false, datas); + sendMetadata(player, entity, new ArrayList<>(datas.values())); } @Override public void sendMetadata(Player player, PacketEntity entity, List data) { - packetEvents.getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), data)); + sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), data)); } @Override - public void sendEquipment(Player player, PacketEntity entity, PropertyHolder properties) { - for (Equipment equipment : generateEquipments(properties)) - sendPacket(player, new WrapperPlayServerEntityEquipment(entity.getEntityId(), Collections.singletonList(equipment))); - } - - protected List generateEquipments(PropertyHolder properties) { - HashMap equipmentSlotMap = new HashMap<>(); - equipmentSlotMap.put("helmet", EquipmentSlot.HELMET); - equipmentSlotMap.put("chestplate", EquipmentSlot.CHEST_PLATE); - equipmentSlotMap.put("leggings", EquipmentSlot.LEGGINGS); - equipmentSlotMap.put("boots", EquipmentSlot.BOOTS); - equipmentSlotMap.put("hand", EquipmentSlot.MAIN_HAND); - equipmentSlotMap.put("offhand", EquipmentSlot.OFF_HAND); - List equipements = new ArrayList<>(); - - for (Map.Entry entry : equipmentSlotMap.entrySet()) { - if (!properties.hasProperty(propertyRegistry.getByName(entry.getKey()))) continue; - equipements.add(new Equipment(entry.getValue(), properties.getProperty(propertyRegistry.getByName(entry.getKey(), ItemStack.class)))); - } - return equipements; + public void sendEquipment(Player player, PacketEntity entity, Equipment equipment) { + sendPacket(player, new WrapperPlayServerEntityEquipment(entity.getEntityId(), Collections.singletonList(equipment))); } protected void sendPacket(Player player, PacketWrapper packet) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_9PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_9PacketFactory.java deleted file mode 100644 index d7c914b..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_9PacketFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -package lol.pyr.znpcsplus.packets; - -import com.github.retrooper.packetevents.PacketEventsAPI; -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.Map; - -public class V1_9PacketFactory extends V1_8PacketFactory { - public V1_9PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { - super(scheduler, metadataFactory, packetEvents, propertyRegistry, textSerializer); - } - - @Override - public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { - Map data = super.generateMetadata(player, entity, properties); - add(data, metadataFactory.effects(properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)), - properties.hasProperty(propertyRegistry.getByName("glow", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("invisible", Boolean.class)), - false, - properties.getProperty(propertyRegistry.getByName("using_item", Boolean.class)) - )); - return data; - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 27e8186..ef1407b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -1,8 +1,10 @@ package lol.pyr.znpcsplus.storage.yaml; +import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; +import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.hologram.HologramImpl; import lol.pyr.znpcsplus.hologram.HologramLine; import lol.pyr.znpcsplus.interaction.ActionRegistry; @@ -52,7 +54,7 @@ public class YamlStorage implements NpcStorage { for (File file : files) if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) { YamlConfiguration config = YamlConfiguration.loadConfiguration(file); UUID uuid = config.contains("uuid") ? UUID.fromString(config.getString("uuid")) : UUID.randomUUID(); - NpcImpl npc = new NpcImpl(uuid, configManager, packetFactory, textSerializer, config.getString("world"), + NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, config.getString("world"), typeRegistry.getByName(config.getString("type")), deserializeLocation(config.getConfigurationSection("location"))); if (config.isBoolean("enabled")) npc.setEnabled(config.getBoolean("enabled")); @@ -65,7 +67,7 @@ public class YamlStorage implements NpcStorage { Bukkit.getLogger().log(Level.WARNING, "Unknown property '" + key + "' for npc '" + config.getString("id") + "'. skipping ..."); continue; } - npc.UNSAFE_setProperty(property, property.deserialize(properties.getString(key))); + npc.UNSAFE_setProperty(property, propertyRegistry.getSerializer(property.getType()).deserialize(properties.getString(key))); } } HologramImpl hologram = npc.getHologram(); @@ -101,8 +103,9 @@ public class YamlStorage implements NpcStorage { config.set("location", serializeLocation(npc.getLocation())); config.set("type", npc.getType().getName()); - for (EntityPropertyImpl property : npc.getAppliedProperties()) { - config.set("properties." + property.getName(), property.serialize(npc)); + for (EntityProperty property : npc.getAppliedProperties()) { + PropertySerializer serializer = propertyRegistry.getSerializer(((EntityPropertyImpl) property).getType()); + config.set("properties." + property.getName(), serializer.UNSAFE_serialize(npc.getProperty(property))); } HologramImpl hologram = npc.getHologram(); From 3411a504e0528dd835da02d0fe056f114227a5a8 Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Mon, 10 Jul 2023 18:55:32 +0530 Subject: [PATCH 02/78] fixed value in standalone metadata packet sending --- plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cd4407b..533378f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -116,7 +116,7 @@ public class NpcImpl extends Viewable implements Npc { private void UNSAFE_refreshProperty(EntityPropertyImpl property) { for (Player viewer : getViewers()) { - List data = property.makeStandaloneData(property.getDefaultValue(), viewer, entity, true); + List data = property.makeStandaloneData(getProperty(property), viewer, entity, true); if (data.size() > 0) packetFactory.sendMetadata(viewer, entity, data); } } From 29c3c4b22bb5b8103ec173f281a071509599b2bf Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Mon, 10 Jul 2023 18:56:57 +0530 Subject: [PATCH 03/78] fixed null properties when adding, fixes tab complete --- .../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index dec2956..96e71bf 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -67,7 +67,10 @@ public class NpcTypeImpl implements NpcType { } public Builder addProperties(String... names) { - for (String name : names) allowedProperties.add(propertyRegistry.getByName(name)); + for (String name : names) { + if (propertyRegistry.getByName(name) != null) continue; + allowedProperties.add(propertyRegistry.getByName(name)); + } return this; } @@ -77,21 +80,14 @@ public class NpcTypeImpl implements NpcType { } public NpcTypeImpl build() { - allowedProperties.add(propertyRegistry.getByName("fire")); - allowedProperties.add(propertyRegistry.getByName("invisible")); - allowedProperties.add(propertyRegistry.getByName("silent")); - allowedProperties.add(propertyRegistry.getByName("look")); - allowedProperties.add(propertyRegistry.getByName("skin_cape")); - allowedProperties.add(propertyRegistry.getByName("using_item")); - allowedProperties.add(propertyRegistry.getByName("potion_color")); - allowedProperties.add(propertyRegistry.getByName("potion_ambient")); - allowedProperties.add(propertyRegistry.getByName("dinnerbone")); + addProperties("fire", "invisible", "silent", "look", "skin_cape", + "using_item", "potion_color", "potion_ambient", "dinnerbone"); if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) - allowedProperties.add(propertyRegistry.getByName("glow")); + addProperties("glow"); if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) - allowedProperties.add(propertyRegistry.getByName("pose")); + addProperties("pose"); if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_17)) - allowedProperties.add(propertyRegistry.getByName("shaking")); + addProperties("shaking"); return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties)); } } From 0596f59304257a28c720d5aa2d9ea3c544aff6ed Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Mon, 10 Jul 2023 19:02:06 +0530 Subject: [PATCH 04/78] Added duplicate property name check, just in case --- .../lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 2 ++ 1 file changed, 2 insertions(+) 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 44aa521..f0b6baa 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -265,6 +265,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { } private void register(EntityPropertyImpl property) { + if (byName.containsKey(property.getName())) + throw new IllegalArgumentException("Duplicate property name: " + property.getName()); byName.put(property.getName(), property); } From 2ff5322093114f0b4cb4d5e5c4b4b69de4e9bfe9 Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Mon, 10 Jul 2023 19:15:52 +0530 Subject: [PATCH 05/78] fixed fix for null properties, lol --- plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 96e71bf..547f978 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -68,7 +68,7 @@ public class NpcTypeImpl implements NpcType { public Builder addProperties(String... names) { for (String name : names) { - if (propertyRegistry.getByName(name) != null) continue; + if (propertyRegistry.getByName(name) == null) continue; allowedProperties.add(propertyRegistry.getByName(name)); } return this; From 9c7166df4bd9c7efb55c40267c0f1d6e73b136c4 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Wed, 12 Jul 2023 20:41:43 +0200 Subject: [PATCH 06/78] extract spigot api as a common dependency so the versions always match --- api/build.gradle | 4 ---- build.gradle | 4 ++++ plugin/build.gradle | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 1804836..f7aa8ea 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -3,10 +3,6 @@ plugins { id "maven-publish" } -dependencies { - compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" -} - publishing { publications { mavenJava(MavenPublication) { diff --git a/build.gradle b/build.gradle index aa4ee20..4785db9 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,10 @@ subprojects { toolchain.languageVersion.set(JavaLanguageVersion.of(8)) } + dependencies { + compileOnly "org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT" + } + repositories { mavenCentral() maven { diff --git a/plugin/build.gradle b/plugin/build.gradle index f02091b..bf80167 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -16,8 +16,6 @@ processResources { } dependencies { - compileOnly "org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT" - compileOnly "me.clip:placeholderapi:2.11.3" // Placeholder support implementation "com.google.code.gson:gson:2.10.1" // JSON parsing implementation "org.bstats:bstats-bukkit:3.0.2" // Plugin stats From 4f1e43b4fa350628c83a8a53a4a9b10e17b73873 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Wed, 12 Jul 2023 20:51:09 +0200 Subject: [PATCH 07/78] add warning message for missing properties --- .../src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 547f978..5b3a4e1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -9,6 +9,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import java.util.*; +import java.util.logging.Logger; import java.util.stream.Collectors; public class NpcTypeImpl implements NpcType { @@ -41,6 +42,8 @@ public class NpcTypeImpl implements NpcType { } protected static final class Builder { + private final static Logger logger = Logger.getLogger("NpcTypeBuilder"); + private final EntityPropertyRegistryImpl propertyRegistry; private final String name; private final EntityType type; @@ -68,7 +71,10 @@ public class NpcTypeImpl implements NpcType { public Builder addProperties(String... names) { for (String name : names) { - if (propertyRegistry.getByName(name) == null) continue; + if (propertyRegistry.getByName(name) == null) { + logger.warning("Tried to register the non-existent \"" + name + "\" property to the \"" + this.name + "\" npc type"); + continue; + } allowedProperties.add(propertyRegistry.getByName(name)); } return this; From 5ad9ef823a561aeab75a3f4fce8ed4fff554f65d Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Wed, 12 Jul 2023 21:09:37 +0200 Subject: [PATCH 08/78] make build function more readable --- .../main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 5b3a4e1..03104ea 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -86,14 +86,12 @@ public class NpcTypeImpl implements NpcType { } public NpcTypeImpl build() { + ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); addProperties("fire", "invisible", "silent", "look", "skin_cape", "using_item", "potion_color", "potion_ambient", "dinnerbone"); - if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) - addProperties("glow"); - if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) - addProperties("pose"); - if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_17)) - addProperties("shaking"); + if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); + if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) addProperties("pose"); + if (version.isNewerThanOrEquals(ServerVersion.V_1_17)) addProperties("shaking"); return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties)); } } From ea6812b27e26b4921b5292e1cff66fcf530dcc43 Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:49:39 +0530 Subject: [PATCH 09/78] removed skin_cape from common properties --- plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 03104ea..4d406c0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -87,7 +87,7 @@ public class NpcTypeImpl implements NpcType { public NpcTypeImpl build() { ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); - addProperties("fire", "invisible", "silent", "look", "skin_cape", + addProperties("fire", "invisible", "silent", "look", "using_item", "potion_color", "potion_ambient", "dinnerbone"); if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) addProperties("pose"); From 902b90212204ef511a05b08a678fb4b5cdcae7b5 Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Fri, 21 Jul 2023 15:51:32 +0530 Subject: [PATCH 10/78] Added url skin type --- .../api/skin/SkinDescriptorFactory.java | 5 +++ .../pyr/znpcsplus/commands/SkinCommand.java | 35 ++++++++++++---- .../entity/EntityPropertyRegistryImpl.java | 1 + .../entity/properties/SkinProperty.java | 20 +++++++++ .../skin/SkinDescriptorFactoryImpl.java | 13 ++++++ .../znpcsplus/skin/cache/MojangSkinCache.java | 42 +++++++++++++++++-- .../skin/descriptor/PrefetchedDescriptor.java | 5 +++ 7 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java b/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java index ba67e88..bc6954a 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java @@ -1,8 +1,13 @@ package lol.pyr.znpcsplus.api.skin; +import java.net.MalformedURLException; +import java.net.URL; + public interface SkinDescriptorFactory { SkinDescriptor createMirrorDescriptor(); SkinDescriptor createRefreshingDescriptor(String playerName); SkinDescriptor createStaticDescriptor(String playerName); SkinDescriptor createStaticDescriptor(String texture, String signature); + SkinDescriptor createUrlDescriptor(String url) throws MalformedURLException; + SkinDescriptor createUrlDescriptor(URL url); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java index abe40fd..69a81e7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java @@ -17,6 +17,8 @@ import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Collections; import java.util.List; @@ -44,9 +46,7 @@ public class SkinCommand implements CommandHandler { npc.setProperty(propertyRegistry.getByName("skin", SkinDescriptor.class), new MirrorDescriptor(skinCache)); npc.respawn(); context.halt(Component.text("The NPC's skin will now mirror the player that it's being displayed to", NamedTextColor.GREEN)); - } - - if (type.equalsIgnoreCase("static")) { + } else if (type.equalsIgnoreCase("static")) { context.ensureArgsNotEmpty(); String name = context.dumpAllArgs(); context.send(Component.text("Fetching skin \"" + name + "\"...", NamedTextColor.GREEN)); @@ -57,25 +57,42 @@ public class SkinCommand implements CommandHandler { } npc.setProperty(propertyRegistry.getByName("skin", SkinDescriptor.class), skin); npc.respawn(); - context.send(Component.text("The NPC's skin has been set to \"" + name + "\"")); + context.send(Component.text("The NPC's skin has been set to \"" + name + "\"", NamedTextColor.GREEN)); }); return; - } - - if (type.equalsIgnoreCase("dynamic")) { + } else if (type.equalsIgnoreCase("dynamic")) { context.ensureArgsNotEmpty(); String name = context.dumpAllArgs(); npc.setProperty(propertyRegistry.getByName("skin", SkinDescriptor.class), new FetchingDescriptor(skinCache, name)); npc.respawn(); context.halt(Component.text("The NPC's skin will now be resolved per-player from \"" + name + "\"")); + } else if (type.equalsIgnoreCase("url")) { + context.ensureArgsNotEmpty(); + String urlString = context.dumpAllArgs(); + try { + URL url = new URL(urlString); + context.send(Component.text("Fetching skin from url \"" + urlString + "\"...", NamedTextColor.GREEN)); + PrefetchedDescriptor.fromUrl(skinCache, url).thenAccept(skin -> { + if (skin.getSkin() == null) { + context.send(Component.text("Failed to fetch skin, are you sure the url is valid?", NamedTextColor.RED)); + return; + } + npc.setProperty(propertyRegistry.getByName("skin", SkinDescriptor.class), skin); + npc.respawn(); + context.send(Component.text("The NPC's skin has been set.", NamedTextColor.GREEN)); + }); + } catch (MalformedURLException e) { + context.send(Component.text("Invalid url!", NamedTextColor.RED)); + } + return; } - context.send(Component.text("Unknown skin type! Please use one of the following: mirror, static, dynamic")); + context.send(Component.text("Unknown skin type! Please use one of the following: mirror, static, dynamic, url")); } @Override public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); - if (context.argSize() == 2) return context.suggestLiteral("mirror", "static", "dynamic"); + if (context.argSize() == 2) return context.suggestLiteral("mirror", "static", "dynamic", "url"); if (context.matchSuggestion("*", "static")) return context.suggestPlayers(); return Collections.emptyList(); } 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 f0b6baa..d6b5ada 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -254,6 +254,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new GlowProperty(packetFactory)); register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("invisible", 0x20)); + register(new SkinProperty()); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java new file mode 100644 index 0000000..b0d7579 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java @@ -0,0 +1,20 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import lol.pyr.znpcsplus.api.skin.SkinDescriptor; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class SkinProperty extends EntityPropertyImpl { + public SkinProperty() { + super("skin", null, SkinDescriptor.class); + } + + @Override + public void apply(SkinDescriptor value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java index ca52520..8fc2b73 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java @@ -7,6 +7,9 @@ import lol.pyr.znpcsplus.skin.descriptor.FetchingDescriptor; import lol.pyr.znpcsplus.skin.descriptor.MirrorDescriptor; import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor; +import java.net.MalformedURLException; +import java.net.URL; + public class SkinDescriptorFactoryImpl implements SkinDescriptorFactory { private final MojangSkinCache skinCache; private final MirrorDescriptor mirrorDescriptor; @@ -35,4 +38,14 @@ public class SkinDescriptorFactoryImpl implements SkinDescriptorFactory { public SkinDescriptor createStaticDescriptor(String texture, String signature) { return new PrefetchedDescriptor(new Skin(texture, signature)); } + + @Override + public SkinDescriptor createUrlDescriptor(String url) throws MalformedURLException { + return createUrlDescriptor(new URL(url)); + } + + @Override + public SkinDescriptor createUrlDescriptor(URL url) { + return PrefetchedDescriptor.fromUrl(skinCache, url).join(); + } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java index 8df8bcc..31a3b6a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java @@ -8,9 +8,7 @@ import lol.pyr.znpcsplus.skin.Skin; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; +import java.io.*; import java.lang.reflect.InvocationTargetException; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -69,6 +67,44 @@ public class MojangSkinCache { }); } + public CompletableFuture fetchByUrl(URL url) { + + return CompletableFuture.supplyAsync(() -> { + URL apiUrl = parseUrl("https://api.mineskin.org/generate/url"); + HttpURLConnection connection = null; + try { + connection = (HttpURLConnection) apiUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setDoOutput(true); + OutputStream outStream = connection.getOutputStream(); + DataOutputStream out = new DataOutputStream(outStream); + out.writeBytes("{\"variant\":\"classic\",\"url\":\"" + url.toString() + "\"}"); // TODO: configurable variant (slim, classic) default: classic + out.flush(); + out.close(); + outStream.close(); + + try (Reader reader = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)) { + JsonObject obj = JsonParser.parseReader(reader).getAsJsonObject(); + if (obj.has("error")) return null; + if (!obj.has("data")) return null; + JsonObject texture = obj.get("data").getAsJsonObject().get("texture").getAsJsonObject(); + return new Skin(texture.get("value").getAsString(), texture.get("signature").getAsString()); + } + + } catch (IOException exception) { + if (!configManager.getConfig().disableSkinFetcherWarnings()) { + logger.warning("Failed to get skin from url:"); + exception.printStackTrace(); + } + } finally { + if (connection != null) connection.disconnect(); + } + return null; + }); + } + public boolean isNameFullyCached(String s) { String name = s.toLowerCase(); if (!idCache.containsKey(name)) return false; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java index 767757d..f6cc66a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java @@ -7,6 +7,7 @@ import lol.pyr.znpcsplus.skin.Skin; import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; import org.bukkit.entity.Player; +import java.net.URL; import java.util.concurrent.CompletableFuture; public class PrefetchedDescriptor implements BaseSkinDescriptor, SkinDescriptor { @@ -20,6 +21,10 @@ public class PrefetchedDescriptor implements BaseSkinDescriptor, SkinDescriptor return CompletableFuture.supplyAsync(() -> new PrefetchedDescriptor(cache.fetchByName(name).join())); } + public static CompletableFuture fromUrl(MojangSkinCache cache, URL url) { + return CompletableFuture.supplyAsync(() -> new PrefetchedDescriptor(cache.fetchByUrl(url).join())); + } + @Override public CompletableFuture fetch(Player player) { return CompletableFuture.completedFuture(skin); From 6e1d089cc77422b5e9e2d25b4005c316c6503bdf Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Sat, 22 Jul 2023 22:11:05 +0530 Subject: [PATCH 11/78] Added skin variant option when using url --- .../znpcsplus/api/skin/SkinDescriptorFactory.java | 5 ++--- .../java/lol/pyr/znpcsplus/commands/SkinCommand.java | 10 +++++++++- .../znpcsplus/skin/SkinDescriptorFactoryImpl.java | 12 ++++++++---- .../pyr/znpcsplus/skin/cache/MojangSkinCache.java | 4 ++-- .../skin/descriptor/PrefetchedDescriptor.java | 4 ++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java b/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java index bc6954a..086aa0c 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/skin/SkinDescriptorFactory.java @@ -1,6 +1,5 @@ package lol.pyr.znpcsplus.api.skin; -import java.net.MalformedURLException; import java.net.URL; public interface SkinDescriptorFactory { @@ -8,6 +7,6 @@ public interface SkinDescriptorFactory { SkinDescriptor createRefreshingDescriptor(String playerName); SkinDescriptor createStaticDescriptor(String playerName); SkinDescriptor createStaticDescriptor(String texture, String signature); - SkinDescriptor createUrlDescriptor(String url) throws MalformedURLException; - SkinDescriptor createUrlDescriptor(URL url); + SkinDescriptor createUrlDescriptor(String url, String variant); + SkinDescriptor createUrlDescriptor(URL url, String variant); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java index 69a81e7..dc9832f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SkinCommand.java @@ -68,11 +68,16 @@ public class SkinCommand implements CommandHandler { context.halt(Component.text("The NPC's skin will now be resolved per-player from \"" + name + "\"")); } else if (type.equalsIgnoreCase("url")) { context.ensureArgsNotEmpty(); + String variant = context.popString().toLowerCase(); + if (!variant.equalsIgnoreCase("slim") && !variant.equalsIgnoreCase("classic")) { + context.send(Component.text("Invalid skin variant! Please use one of the following: slim, classic", NamedTextColor.RED)); + return; + } String urlString = context.dumpAllArgs(); try { URL url = new URL(urlString); context.send(Component.text("Fetching skin from url \"" + urlString + "\"...", NamedTextColor.GREEN)); - PrefetchedDescriptor.fromUrl(skinCache, url).thenAccept(skin -> { + PrefetchedDescriptor.fromUrl(skinCache, url , variant).thenAccept(skin -> { if (skin.getSkin() == null) { context.send(Component.text("Failed to fetch skin, are you sure the url is valid?", NamedTextColor.RED)); return; @@ -94,6 +99,9 @@ public class SkinCommand implements CommandHandler { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); if (context.argSize() == 2) return context.suggestLiteral("mirror", "static", "dynamic", "url"); if (context.matchSuggestion("*", "static")) return context.suggestPlayers(); + if (context.argSize() == 3 && context.matchSuggestion("*", "url")) { + return context.suggestLiteral("slim", "classic"); + } return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java index 8fc2b73..b6656ed 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/SkinDescriptorFactoryImpl.java @@ -40,12 +40,16 @@ public class SkinDescriptorFactoryImpl implements SkinDescriptorFactory { } @Override - public SkinDescriptor createUrlDescriptor(String url) throws MalformedURLException { - return createUrlDescriptor(new URL(url)); + public SkinDescriptor createUrlDescriptor(String url, String variant) { + try { + return createUrlDescriptor(new URL(url), variant); + } catch (MalformedURLException e) { + return null; + } } @Override - public SkinDescriptor createUrlDescriptor(URL url) { - return PrefetchedDescriptor.fromUrl(skinCache, url).join(); + public SkinDescriptor createUrlDescriptor(URL url, String variant) { + return PrefetchedDescriptor.fromUrl(skinCache, url, variant).join(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java index 31a3b6a..70bf62f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java @@ -67,7 +67,7 @@ public class MojangSkinCache { }); } - public CompletableFuture fetchByUrl(URL url) { + public CompletableFuture fetchByUrl(URL url, String variant) { return CompletableFuture.supplyAsync(() -> { URL apiUrl = parseUrl("https://api.mineskin.org/generate/url"); @@ -80,7 +80,7 @@ public class MojangSkinCache { connection.setDoOutput(true); OutputStream outStream = connection.getOutputStream(); DataOutputStream out = new DataOutputStream(outStream); - out.writeBytes("{\"variant\":\"classic\",\"url\":\"" + url.toString() + "\"}"); // TODO: configurable variant (slim, classic) default: classic + out.writeBytes("{\"variant\":\"" + variant + "\",\"url\":\"" + url.toString() + "\"}"); // TODO: configurable variant (slim, classic) default: classic out.flush(); out.close(); outStream.close(); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java index f6cc66a..3e177dd 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/descriptor/PrefetchedDescriptor.java @@ -21,8 +21,8 @@ public class PrefetchedDescriptor implements BaseSkinDescriptor, SkinDescriptor return CompletableFuture.supplyAsync(() -> new PrefetchedDescriptor(cache.fetchByName(name).join())); } - public static CompletableFuture fromUrl(MojangSkinCache cache, URL url) { - return CompletableFuture.supplyAsync(() -> new PrefetchedDescriptor(cache.fetchByUrl(url).join())); + public static CompletableFuture fromUrl(MojangSkinCache cache, URL url, String variant) { + return CompletableFuture.supplyAsync(() -> new PrefetchedDescriptor(cache.fetchByUrl(url, variant).join())); } @Override From 993cd10b7a13d8c6f4d747b11dd1863ea282665e Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 24 Jul 2023 02:02:19 +0200 Subject: [PATCH 12/78] make a single generic class for dummy properties --- .../entity/EntityPropertyRegistryImpl.java | 5 ++-- .../properties/DummyBooleanProperty.java | 18 --------------- .../entity/properties/DummyProperty.java | 23 +++++++++++++++++++ .../entity/properties/SkinProperty.java | 20 ---------------- 4 files changed, 26 insertions(+), 40 deletions(-) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java 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 d6b5ada..026bea6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.entity; import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.api.skin.SkinDescriptor; import lol.pyr.znpcsplus.entity.properties.*; import lol.pyr.znpcsplus.entity.serializers.*; import lol.pyr.znpcsplus.packets.PacketFactory; @@ -250,11 +251,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_HAND)); register(new NameProperty()); - register(new DummyBooleanProperty("look", false)); + register(new DummyProperty<>("look", false)); register(new GlowProperty(packetFactory)); register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("invisible", 0x20)); - register(new SkinProperty()); + register(new DummyProperty<>("skin", SkinDescriptor.class)); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java deleted file mode 100644 index 105e6ab..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyBooleanProperty.java +++ /dev/null @@ -1,18 +0,0 @@ -package lol.pyr.znpcsplus.entity.properties; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import lol.pyr.znpcsplus.entity.EntityPropertyImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class DummyBooleanProperty extends EntityPropertyImpl { - public DummyBooleanProperty(String name, boolean def) { - super(name, def, Boolean.class); - } - - @Override - public void apply(Boolean value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java new file mode 100644 index 0000000..e92897c --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java @@ -0,0 +1,23 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class DummyProperty extends EntityPropertyImpl { + @SuppressWarnings("unchecked") + public DummyProperty(String name, T defaultValue) { + super(name, defaultValue, (Class) defaultValue.getClass()); + } + + public DummyProperty(String name, Class clazz) { + super(name, null, clazz); + } + + @Override + public void apply(T value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java deleted file mode 100644 index b0d7579..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SkinProperty.java +++ /dev/null @@ -1,20 +0,0 @@ -package lol.pyr.znpcsplus.entity.properties; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import lol.pyr.znpcsplus.api.skin.SkinDescriptor; -import lol.pyr.znpcsplus.entity.EntityPropertyImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class SkinProperty extends EntityPropertyImpl { - public SkinProperty() { - super("skin", null, SkinDescriptor.class); - } - - @Override - public void apply(SkinDescriptor value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { - - } -} From 792b962e492f976a39d8ca49d58d0fc400978a3e Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 24 Jul 2023 02:04:56 +0200 Subject: [PATCH 13/78] rename method to what it actually does --- .../main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java | 2 +- .../main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java index 3261e2f..ffe4f48 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java @@ -48,7 +48,7 @@ public abstract class EntityPropertyImpl implements EntityProperty { abstract public void apply(T value, Player player, PacketEntity entity, boolean isSpawned, Map properties); @SuppressWarnings("unchecked") - public void UNSAFE_update(Object value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + public void UNSAFE_apply(Object value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { apply((T) value, player, entity, isSpawned, properties); } } \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index 2437955..f416195 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -250,7 +250,7 @@ public class V1_8PacketFactory implements PacketFactory { public void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties) { Map datas = new HashMap<>(); for (EntityProperty property : properties.getAppliedProperties()) - ((EntityPropertyImpl) property).UNSAFE_update(properties.getProperty(property), player, entity, false, datas); + ((EntityPropertyImpl) property).UNSAFE_apply(properties.getProperty(property), player, entity, false, datas); sendMetadata(player, entity, new ArrayList<>(datas.values())); } From c8abf4f3fbf9e456ebb67228557162ab5ea78e9a Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 24 Jul 2023 02:33:29 +0200 Subject: [PATCH 14/78] fix some properties removing others when being applied standalone --- .../znpcsplus/entity/EntityPropertyImpl.java | 17 ++++++------- .../entity/EntityPropertyRegistryImpl.java | 22 +++++++++++++---- .../pyr/znpcsplus/entity/PacketEntity.java | 24 ++++++++++++++++++- .../entity/properties/DummyProperty.java | 2 +- .../entity/properties/EffectsProperty.java | 4 ++-- .../entity/properties/EquipmentProperty.java | 4 ++-- .../entity/properties/GlowProperty.java | 3 ++- .../entity/properties/NameProperty.java | 3 ++- .../java/lol/pyr/znpcsplus/npc/NpcImpl.java | 2 +- .../znpcsplus/packets/V1_8PacketFactory.java | 3 +-- 10 files changed, 60 insertions(+), 24 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java index ffe4f48..9842fbb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java @@ -14,6 +14,7 @@ public abstract class EntityPropertyImpl implements EntityProperty { private final String name; private final T defaultValue; private final Class clazz; + private final List> dependencies = new ArrayList<>(); protected EntityPropertyImpl(String name, T defaultValue, Class clazz) { this.name = name.toLowerCase(); @@ -35,20 +36,20 @@ public abstract class EntityPropertyImpl implements EntityProperty { return clazz; } + public void addDependency(EntityPropertyImpl property) { + dependencies.add(property); + } + protected static EntityData newEntityData(int index, EntityDataType type, V value) { return new EntityData(index, type, value); } - public List makeStandaloneData(T value, Player player, PacketEntity packetEntity, boolean isSpawned) { + public List applyStandalone(Player player, PacketEntity packetEntity, boolean isSpawned) { Map map = new HashMap<>(); - apply(value, player, packetEntity, isSpawned, map); + apply(player, packetEntity, isSpawned, map); + for (EntityPropertyImpl property : dependencies) property.apply(player, packetEntity, isSpawned, map); return new ArrayList<>(map.values()); } - abstract public void apply(T value, Player player, PacketEntity entity, boolean isSpawned, Map properties); - - @SuppressWarnings("unchecked") - public void UNSAFE_apply(Object value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { - apply((T) value, player, entity, isSpawned, properties); - } + abstract public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties); } \ No newline at end of file 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 026bea6..b8a33f5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -11,10 +11,7 @@ import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; import lol.pyr.znpcsplus.util.*; import org.bukkit.DyeColor; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -252,10 +249,12 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new NameProperty()); register(new DummyProperty<>("look", false)); + register(new DummyProperty<>("skin", SkinDescriptor.class)); + register(new GlowProperty(packetFactory)); register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("invisible", 0x20)); - register(new DummyProperty<>("skin", SkinDescriptor.class)); + linkProperties("glow", "fire", "invisible"); } private void registerSerializer(PropertySerializer serializer) { @@ -272,6 +271,19 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { byName.put(property.getName(), property); } + private void linkProperties(String... names) { + linkProperties(Arrays.stream(names) + .map(this::getByName) + .collect(Collectors.toSet())); + } + + private void linkProperties(Collection> properties) { + for (EntityPropertyImpl property : properties) for (EntityPropertyImpl dependency : properties) { + if (property.equals(dependency)) continue; + property.addDependency(dependency); + } + } + public PropertySerializer getSerializer(Class type) { return (PropertySerializer) serializerMap.get(type); } 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 d933679..aef8b03 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java @@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.reflection.Reflections; @@ -11,9 +12,10 @@ import lol.pyr.znpcsplus.util.NpcLocation; import org.bukkit.entity.Player; import java.util.Collection; +import java.util.Set; import java.util.UUID; -public class PacketEntity { +public class PacketEntity implements PropertyHolder { private final PacketFactory packetFactory; private final PropertyHolder properties; @@ -75,4 +77,24 @@ public class PacketEntity { return id; } } + + @Override + public T getProperty(EntityProperty key) { + return properties.getProperty(key); + } + + @Override + public boolean hasProperty(EntityProperty key) { + return properties.hasProperty(key); + } + + @Override + public void setProperty(EntityProperty key, T value) { + properties.setProperty(key, value); + } + + @Override + public Set> getAppliedProperties() { + return properties.getAppliedProperties(); + } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java index e92897c..9e1306e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java @@ -18,6 +18,6 @@ public class DummyProperty extends EntityPropertyImpl { } @Override - public void apply(T value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java index 91171af..e031ad7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java @@ -17,9 +17,9 @@ public class EffectsProperty extends EntityPropertyImpl { } @Override - public void apply(Boolean enabled, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { EntityData oldData = properties.get(0); byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); - properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (enabled ? bitmask : 0)))); + properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (entity.getProperty(this) ? bitmask : 0)))); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java index 25171d8..c0219a7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EquipmentProperty.java @@ -22,7 +22,7 @@ public class EquipmentProperty extends EntityPropertyImpl { } @Override - public void apply(ItemStack value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { - packetFactory.sendEquipment(player, entity, new Equipment(slot, value)); + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + packetFactory.sendEquipment(player, entity, new Equipment(slot, entity.getProperty(this))); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java index b4221e6..13931d8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java @@ -19,7 +19,8 @@ public class GlowProperty extends EntityPropertyImpl { } @Override - public void apply(NamedTextColor value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + NamedTextColor value = entity.getProperty(this); EntityData oldData = properties.get(0); byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (value == null ? 0 : 0x40)))); 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 d4cc7a3..9434aea 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 @@ -26,7 +26,8 @@ public class NameProperty extends EntityPropertyImpl { } @Override - public void apply(Component value, Player player, PacketEntity entity, boolean isSpawned, Map properties) { + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + Component value = entity.getProperty(this); if (value != null) { String serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) : 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 77316d5..619083f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -122,7 +122,7 @@ public class NpcImpl extends Viewable implements Npc { private void UNSAFE_refreshProperty(EntityPropertyImpl property) { for (Player viewer : getViewers()) { - List data = property.makeStandaloneData(getProperty(property), viewer, entity, true); + List data = property.applyStandalone(viewer, entity, true); if (data.size() > 0) packetFactory.sendMetadata(viewer, entity, data); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index f416195..cbbc35b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -249,8 +249,7 @@ public class V1_8PacketFactory implements PacketFactory { @Override public void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties) { Map datas = new HashMap<>(); - for (EntityProperty property : properties.getAppliedProperties()) - ((EntityPropertyImpl) property).UNSAFE_apply(properties.getProperty(property), player, entity, false, datas); + for (EntityProperty property : properties.getAppliedProperties()) ((EntityPropertyImpl) property).apply(player, entity, false, datas); sendMetadata(player, entity, new ArrayList<>(datas.values())); } From 32b588807a4e6eef9767ec93684bd762e7d41cbd Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 24 Jul 2023 02:51:40 +0200 Subject: [PATCH 15/78] make interaction detection also treat holograms as part of the npc (fixes #76) --- .../main/java/lol/pyr/znpcsplus/hologram/HologramLine.java | 4 ++++ .../src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) 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 895df3e..df76abd 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java @@ -51,6 +51,10 @@ public class HologramLine implements PropertyHolder { armorStand.setLocation(location, viewers); } + public int getEntityId() { + return armorStand.getEntityId(); + } + @SuppressWarnings("unchecked") @Override public T getProperty(EntityProperty key) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java index 914695a..6de6b1e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java @@ -103,7 +103,9 @@ public class NpcRegistryImpl implements NpcRegistry { } public NpcEntryImpl getByEntityId(int id) { - return npcList.stream().filter(entry -> entry.getNpc().getEntity().getEntityId() == id).findFirst().orElse(null); + return npcList.stream().filter(entry -> entry.getNpc().getEntity().getEntityId() == id || + entry.getNpc().getHologram().getLines().stream().anyMatch(line -> line.getEntityId() == id)) // Also match the holograms of npcs + .findFirst().orElse(null); } public Collection getAllIds() { From 52f083583b69d4e4dc5f80c277ab98bc97a16a52 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Tue, 25 Jul 2023 03:14:41 +0200 Subject: [PATCH 16/78] update viewers list before showing the npc to prevent the show/hide methods from being called multiple times by the processor task when the method needs extra time to grab skins which causes some problems including multiple teams being created resulting in client warnings/kicks on BungeeCord --- plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java index 8bd8f56..2670ae4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java @@ -27,14 +27,14 @@ public abstract class Viewable { public void show(Player player) { if (viewers.contains(player)) return; - UNSAFE_show(player); viewers.add(player); + UNSAFE_show(player); } public void hide(Player player) { if (!viewers.contains(player)) return; - UNSAFE_hide(player); viewers.remove(player); + UNSAFE_hide(player); } public boolean isShown(Player player) { From 769eed2f463f8d520750b00b415eec40a585f6b4 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Thu, 27 Jul 2023 19:21:46 +0530 Subject: [PATCH 17/78] fixed skin property showing in property remove command --- .../pyr/znpcsplus/api/entity/EntityProperty.java | 1 + .../commands/property/PropertyRemoveCommand.java | 3 ++- .../pyr/znpcsplus/entity/EntityPropertyImpl.java | 10 ++++++++++ .../entity/EntityPropertyRegistryImpl.java | 2 +- .../znpcsplus/entity/properties/DummyProperty.java | 14 ++++++++++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java b/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java index 7ae66cb..69db24e 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java @@ -3,4 +3,5 @@ package lol.pyr.znpcsplus.api.entity; public interface EntityProperty { T getDefaultValue(); String getName(); + boolean isPlayerModifiable(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java index 0fc8b23..b517d74 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java @@ -28,6 +28,7 @@ public class PropertyRemoveCommand implements CommandHandler { NpcImpl npc = entry.getNpc(); EntityPropertyImpl property = context.parse(EntityPropertyImpl.class); if (!npc.hasProperty(property)) context.halt(Component.text("This npc doesn't have the " + property.getName() + " property set", NamedTextColor.RED)); + if (!property.isPlayerModifiable()) context.halt(Component.text("This property is not modifiable by players", NamedTextColor.RED)); npc.setProperty(property, null); context.send(Component.text("Removed property " + property.getName() + " from NPC " + entry.getId(), NamedTextColor.GREEN)); } @@ -36,7 +37,7 @@ public class PropertyRemoveCommand implements CommandHandler { public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(0, NpcEntryImpl.class) - .getNpc().getAppliedProperties().stream().map(EntityProperty::getName)); + .getNpc().getAppliedProperties().stream().filter(EntityProperty::isPlayerModifiable).map(EntityProperty::getName)); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java index 9842fbb..53b4392 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java @@ -15,6 +15,7 @@ public abstract class EntityPropertyImpl implements EntityProperty { private final T defaultValue; private final Class clazz; private final List> dependencies = new ArrayList<>(); + private boolean playerModifiable = true; protected EntityPropertyImpl(String name, T defaultValue, Class clazz) { this.name = name.toLowerCase(); @@ -32,6 +33,15 @@ public abstract class EntityPropertyImpl implements EntityProperty { return defaultValue; } + @Override + public boolean isPlayerModifiable() { + return playerModifiable; + } + + public void setPlayerModifiable(boolean playerModifiable) { + this.playerModifiable = playerModifiable; + } + public Class getType() { return clazz; } 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 b8a33f5..bea8614 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -249,7 +249,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new NameProperty()); register(new DummyProperty<>("look", false)); - register(new DummyProperty<>("skin", SkinDescriptor.class)); + register(new DummyProperty<>("skin", SkinDescriptor.class, false)); register(new GlowProperty(packetFactory)); register(new EffectsProperty("fire", 0x01)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java index 9e1306e..eba69a5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java @@ -8,13 +8,23 @@ import org.bukkit.entity.Player; import java.util.Map; public class DummyProperty extends EntityPropertyImpl { - @SuppressWarnings("unchecked") public DummyProperty(String name, T defaultValue) { - super(name, defaultValue, (Class) defaultValue.getClass()); + this(name, defaultValue, true); } public DummyProperty(String name, Class clazz) { + this(name, clazz, true); + } + + @SuppressWarnings("unchecked") + public DummyProperty(String name, T defaultValue, boolean playerModifiable) { + super(name, defaultValue, (Class) defaultValue.getClass()); + setPlayerModifiable(playerModifiable); + } + + public DummyProperty(String name, Class clazz, boolean playerModifiable) { super(name, null, clazz); + setPlayerModifiable(playerModifiable); } @Override From ca8aa4ba1619f089c6fddd8ded45fa4e9c84b374 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 1 Aug 2023 19:46:29 +0530 Subject: [PATCH 18/78] Implemented citizen importer --- .../conversion/DataImporterRegistry.java | 5 +- .../conversion/citizens/CitizensImporter.java | 56 ++++++++++++++++++- .../citizens/model/CitizensTrait.java | 19 +++++++ .../model/CitizensTraitsRegistry.java | 31 ++++++++++ .../citizens/model/SectionCitizensTrait.java | 19 +++++++ .../citizens/model/StringCitizensTrait.java | 18 ++++++ .../citizens/model/traits/LocationTrait.java | 25 +++++++++ .../citizens/model/traits/LookTrait.java | 22 ++++++++ .../citizens/model/traits/MirrorTrait.java | 27 +++++++++ .../model/traits/ProfessionTrait.java | 28 ++++++++++ .../model/traits/SkinLayersTrait.java | 38 +++++++++++++ .../citizens/model/traits/SkinTrait.java | 27 +++++++++ .../citizens/model/traits/TypeTrait.java | 31 ++++++++++ .../citizens/model/traits/VillagerTrait.java | 39 +++++++++++++ .../java/lol/pyr/znpcsplus/npc/NpcImpl.java | 1 + 15 files changed, 382 insertions(+), 4 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTraitsRegistry.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/SectionCitizensTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/StringCitizensTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LocationTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LookTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/MirrorTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/ProfessionTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinLayersTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/TypeTrait.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/VillagerTrait.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java index 5a286ae..55d1012 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java @@ -1,6 +1,7 @@ package lol.pyr.znpcsplus.conversion; import lol.pyr.znpcsplus.config.ConfigManager; +import lol.pyr.znpcsplus.conversion.citizens.CitizensImporter; import lol.pyr.znpcsplus.conversion.znpcs.ZNpcImporter; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; @@ -30,8 +31,8 @@ public class DataImporterRegistry { packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "ServersNPC/data.json")))); register("znpcsplus_legacy", LazyLoader.of(() -> new ZNpcImporter(configManager, adventure, bungeeConnector, taskScheduler, packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "ZNPCsPlusLegacy/data.json")))); - /* register("citizens", LazyLoader.of(() -> new CitizensImporter(configManager, adventure, bungeeConnector, taskScheduler, - packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "Citizens/saves.yml")))); */ + register("citizens", LazyLoader.of(() -> new CitizensImporter(configManager, adventure, bungeeConnector, taskScheduler, + packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "Citizens/saves.yml")))); } private void register(String id, LazyLoader loader) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java index 3005864..7f72d67 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java @@ -1,21 +1,30 @@ package lol.pyr.znpcsplus.conversion.citizens; +import lol.pyr.znpcsplus.api.NpcApiProvider; import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.conversion.DataImporter; +import lol.pyr.znpcsplus.conversion.citizens.model.CitizensTrait; +import lol.pyr.znpcsplus.conversion.citizens.model.CitizensTraitsRegistry; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; import lol.pyr.znpcsplus.util.BungeeConnector; +import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.UUID; @SuppressWarnings("FieldCanBeLocal") public class CitizensImporter implements DataImporter { @@ -29,6 +38,7 @@ public class CitizensImporter implements DataImporter { private final EntityPropertyRegistryImpl propertyRegistry; private final MojangSkinCache skinCache; private final File dataFile; + private final CitizensTraitsRegistry traitsRegistry; public CitizensImporter(ConfigManager configManager, BukkitAudiences adventure, BungeeConnector bungeeConnector, TaskScheduler taskScheduler, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, @@ -44,13 +54,55 @@ public class CitizensImporter implements DataImporter { this.propertyRegistry = propertyRegistry; this.skinCache = skinCache; this.dataFile = dataFile; + this.traitsRegistry = new CitizensTraitsRegistry(typeRegistry, propertyRegistry, skinCache); } @Override public Collection importData() { YamlConfiguration config = YamlConfiguration.loadConfiguration(dataFile); - // TODO - return Collections.emptyList(); + ConfigurationSection npcsSection = config.getConfigurationSection("npc"); + // use guard clause to avoid nested if statements + if (npcsSection == null) { + return Collections.emptyList(); + } + ArrayList entries = new ArrayList<>(); + npcsSection.getKeys(false).forEach(key -> { + ConfigurationSection npcSection = npcsSection.getConfigurationSection(key); + if (npcSection == null) { + return; + } + String name = npcSection.getString("name", "Citizens NPC"); + UUID uuid; + try { + uuid = UUID.fromString(npcSection.getString("uuid")); + } catch (IllegalArgumentException e) { + uuid = UUID.randomUUID(); + } + String world = npcSection.getString("traits.location.world"); + if (world == null) { + world = Bukkit.getWorlds().get(0).getName(); + } + NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world, typeRegistry.getByName("armor_stand"), new NpcLocation(0, 0, 0, 0, 0)); + npc.getHologram().addLineComponent(textSerializer.deserialize(name)); + ConfigurationSection traits = npcSection.getConfigurationSection("traits"); + if (traits != null) { + for (String traitName : traits.getKeys(false)) { + Object trait = traits.get(traitName); + CitizensTrait citizensTrait = traitsRegistry.getByName(traitName); + if (citizensTrait != null) { + npc = citizensTrait.apply(npc, trait); + } + } + } + String id = key.toLowerCase(); + while (NpcApiProvider.get().getNpcRegistry().getById(id) != null) { + id += "_"; + } + NpcEntryImpl entry = new NpcEntryImpl(id, npc); + entry.enableEverything(); + entries.add(entry); + }); + return entries; } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTrait.java new file mode 100644 index 0000000..0811589 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTrait.java @@ -0,0 +1,19 @@ +package lol.pyr.znpcsplus.conversion.citizens.model; + +import lol.pyr.znpcsplus.npc.NpcImpl; +import org.jetbrains.annotations.NotNull; + +public abstract class CitizensTrait { + private final String identifier; + + public CitizensTrait(String identifier) { + this.identifier = identifier; + } + + public String getIdentifier() { + return identifier; + } + + public abstract @NotNull NpcImpl apply(NpcImpl npc, Object value); + +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTraitsRegistry.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTraitsRegistry.java new file mode 100644 index 0000000..ba3ba89 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/CitizensTraitsRegistry.java @@ -0,0 +1,31 @@ +package lol.pyr.znpcsplus.conversion.citizens.model; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.api.npc.NpcTypeRegistry; +import lol.pyr.znpcsplus.conversion.citizens.model.traits.*; +import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; + +import java.util.HashMap; + +public class CitizensTraitsRegistry { + private final HashMap traitMap = new HashMap<>(); + + public CitizensTraitsRegistry(NpcTypeRegistry typeRegistry, EntityPropertyRegistry propertyRegistry, MojangSkinCache skinCache) { + register(new LocationTrait()); + register(new TypeTrait(typeRegistry)); + register(new ProfessionTrait(propertyRegistry)); + register(new VillagerTrait(propertyRegistry)); + register(new SkinTrait(propertyRegistry)); + register(new MirrorTrait(propertyRegistry, skinCache)); + register(new SkinLayersTrait(propertyRegistry)); + register(new LookTrait(propertyRegistry)); + } + + public CitizensTrait getByName(String name) { + return traitMap.get(name); + } + + public void register(CitizensTrait trait) { + traitMap.put(trait.getIdentifier(), trait); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/SectionCitizensTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/SectionCitizensTrait.java new file mode 100644 index 0000000..123eca5 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/SectionCitizensTrait.java @@ -0,0 +1,19 @@ +package lol.pyr.znpcsplus.conversion.citizens.model; + +import lol.pyr.znpcsplus.npc.NpcImpl; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +public abstract class SectionCitizensTrait extends CitizensTrait { + public SectionCitizensTrait(String identifier) { + super(identifier); + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, Object value) { + if (!(value instanceof ConfigurationSection)) return npc; + return apply(npc, (ConfigurationSection) value); + } + + public abstract @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section); +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/StringCitizensTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/StringCitizensTrait.java new file mode 100644 index 0000000..58199a4 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/StringCitizensTrait.java @@ -0,0 +1,18 @@ +package lol.pyr.znpcsplus.conversion.citizens.model; + +import lol.pyr.znpcsplus.npc.NpcImpl; +import org.jetbrains.annotations.NotNull; + +public abstract class StringCitizensTrait extends CitizensTrait { + public StringCitizensTrait(String identifier) { + super(identifier); + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, Object value) { + if (!(value instanceof String)) return npc; + return apply(npc, (String) value); + } + + public abstract @NotNull NpcImpl apply(NpcImpl npc, String string); +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LocationTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LocationTrait.java new file mode 100644 index 0000000..c56793c --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LocationTrait.java @@ -0,0 +1,25 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.util.NpcLocation; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +public class LocationTrait extends SectionCitizensTrait { + public LocationTrait() { + super("location"); + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section) { + double x = Double.parseDouble(section.getString("x")); + double y = Double.parseDouble(section.getString("y")); + double z = Double.parseDouble(section.getString("z")); + float yaw = Float.parseFloat(section.getString("yaw")); + float pitch = Float.parseFloat(section.getString("pitch")); + NpcLocation location = new NpcLocation(x, y, z, yaw, pitch); + npc.setLocation(location); + return npc; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LookTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LookTrait.java new file mode 100644 index 0000000..0854124 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/LookTrait.java @@ -0,0 +1,22 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +public class LookTrait extends SectionCitizensTrait { + private final EntityPropertyRegistry registry; + + public LookTrait(EntityPropertyRegistry registry) { + super("lookclose"); + this.registry = registry; + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section) { + if (section.getBoolean("enabled")) npc.setProperty(registry.getByName("look", Boolean.class), true); + return npc; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/MirrorTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/MirrorTrait.java new file mode 100644 index 0000000..19360bf --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/MirrorTrait.java @@ -0,0 +1,27 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.api.skin.SkinDescriptor; +import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; +import lol.pyr.znpcsplus.skin.descriptor.MirrorDescriptor; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +public class MirrorTrait extends SectionCitizensTrait { + private final EntityPropertyRegistry registry; + private final MojangSkinCache skinCache; + + public MirrorTrait(EntityPropertyRegistry registry, MojangSkinCache skinCache) { + super("mirrortrait"); + this.registry = registry; + this.skinCache = skinCache; + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section) { + if (section.getBoolean("enabled")) npc.setProperty(registry.getByName("skin", SkinDescriptor.class), new MirrorDescriptor(skinCache)); + return npc; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/ProfessionTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/ProfessionTrait.java new file mode 100644 index 0000000..551d9a8 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/ProfessionTrait.java @@ -0,0 +1,28 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.conversion.citizens.model.StringCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.util.VillagerProfession; +import org.jetbrains.annotations.NotNull; + +public class ProfessionTrait extends StringCitizensTrait { + private final EntityPropertyRegistry registry; + + public ProfessionTrait(EntityPropertyRegistry registry) { + super("profession"); + this.registry = registry; + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, String string) { + VillagerProfession profession; + try { + profession = VillagerProfession.valueOf(string.toUpperCase()); + } catch (IllegalArgumentException ignored) { + profession = VillagerProfession.NONE; + } + npc.setProperty(registry.getByName("villager_profession", VillagerProfession.class), profession); + return npc; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinLayersTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinLayersTrait.java new file mode 100644 index 0000000..f2d7ed0 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinLayersTrait.java @@ -0,0 +1,38 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +public class SkinLayersTrait extends SectionCitizensTrait { + private final EntityPropertyRegistry registry; + private final Map skinLayers; + + public SkinLayersTrait(EntityPropertyRegistry registry) { + super("skinlayers"); + this.registry = registry; + this.skinLayers = new HashMap<>(); + this.skinLayers.put("cape", "skin_cape"); + this.skinLayers.put("hat", "skin_hat"); + this.skinLayers.put("jacket", "skin_jacket"); + this.skinLayers.put("left_sleeve", "skin_left_sleeve"); + this.skinLayers.put("left_pants", "skin_left_leg"); + this.skinLayers.put("right_sleeve", "skin_right_sleeve"); + this.skinLayers.put("right_pants", "skin_right_leg"); + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section) { + for (Map.Entry entry : this.skinLayers.entrySet()) { + String key = entry.getKey(); + String property = entry.getValue(); + if (section.contains(key)) npc.setProperty(registry.getByName(property, Boolean.class), section.getBoolean(key)); + } + return npc; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinTrait.java new file mode 100644 index 0000000..439c9ff --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/SkinTrait.java @@ -0,0 +1,27 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.api.skin.SkinDescriptor; +import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.skin.Skin; +import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +public class SkinTrait extends SectionCitizensTrait { + private final EntityPropertyRegistry registry; + + public SkinTrait(EntityPropertyRegistry registry) { + super("skintrait"); + this.registry = registry; + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section) { + String texture = section.getString("textureRaw"); + String signature = section.getString("signature"); + if (texture != null && signature != null) npc.setProperty(registry.getByName("skin", SkinDescriptor.class), new PrefetchedDescriptor(new Skin(texture, signature))); + return npc; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/TypeTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/TypeTrait.java new file mode 100644 index 0000000..6af1d85 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/TypeTrait.java @@ -0,0 +1,31 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.npc.NpcTypeRegistry; +import lol.pyr.znpcsplus.conversion.citizens.model.StringCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcTypeImpl; +import org.jetbrains.annotations.NotNull; + +public class TypeTrait extends StringCitizensTrait { + private final NpcTypeRegistry registry; + + public TypeTrait(NpcTypeRegistry registry) { + super("type"); + this.registry = registry; + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, String string) { + NpcTypeImpl type = warpNpcType(string); + if (type == null) return npc; + npc.setType(type); + return npc; + } + + private NpcTypeImpl warpNpcType(String name) { + name = name.toLowerCase(); +// if (name.equals("player")) name = "human"; +// else if (name.equals("zombievillager")) name = "zombie_villager"; + return (NpcTypeImpl) registry.getByName(name); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/VillagerTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/VillagerTrait.java new file mode 100644 index 0000000..4998f78 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/VillagerTrait.java @@ -0,0 +1,39 @@ +package lol.pyr.znpcsplus.conversion.citizens.model.traits; + +import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.util.VillagerLevel; +import lol.pyr.znpcsplus.util.VillagerType; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +public class VillagerTrait extends SectionCitizensTrait { + private final EntityPropertyRegistry registry; + + public VillagerTrait(EntityPropertyRegistry registry) { + super("villagertrait"); + this.registry = registry; + } + + @Override + public @NotNull NpcImpl apply(NpcImpl npc, ConfigurationSection section) { + int level = section.getInt("level"); + String type = section.getString("type", "plains"); + VillagerLevel villagerLevel; + try { + villagerLevel = VillagerLevel.values()[level]; + } catch (ArrayIndexOutOfBoundsException ignored) { + villagerLevel = VillagerLevel.STONE; + } + VillagerType villagerType; + try { + villagerType = VillagerType.valueOf(type.toUpperCase()); + } catch (IllegalArgumentException ignored) { + villagerType = VillagerType.PLAINS; + } + npc.setProperty(registry.getByName("villager_level", VillagerLevel.class), villagerLevel); + npc.setProperty(registry.getByName("villager_type", VillagerType.class), villagerType); + return npc; + } +} 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 619083f..573aea4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -142,6 +142,7 @@ public class NpcImpl extends Viewable implements Npc { } public void setProperty(EntityPropertyImpl key, T value) { + if (key == null) return; if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key); else propertyMap.put(key, value); UNSAFE_refreshProperty(key); From 3040cbc0bbf8686a5b17178058422f41ff1ab742 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 1 Aug 2023 19:48:24 +0530 Subject: [PATCH 19/78] remove comment. oops --- .../lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java index 7f72d67..39b3deb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java @@ -61,7 +61,6 @@ public class CitizensImporter implements DataImporter { public Collection importData() { YamlConfiguration config = YamlConfiguration.loadConfiguration(dataFile); ConfigurationSection npcsSection = config.getConfigurationSection("npc"); - // use guard clause to avoid nested if statements if (npcsSection == null) { return Collections.emptyList(); } From 6eff7a3b6c85481741b6a7a432a63b2fca6478c4 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 5 Aug 2023 00:28:55 +0200 Subject: [PATCH 20/78] remove already implemented properties from the comment --- .../znpcsplus/entity/EntityPropertyRegistryImpl.java | 12 ------------ 1 file changed, 12 deletions(-) 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 bea8614..8d7d76f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -55,23 +55,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerLevel.class); /* - registerType("glow", NamedTextColor.class); - registerType("fire", false); - registerType("invisible", false); registerType("silent", false); - registerType("skin", SkinDescriptor.class); registerType("name", Component.class); registerType("look", false); registerType("dinnerbone", false); - // TODO: make all of these bukkit itemstack classes so api users wont have to add packetevents as a dependency - registerType("helmet", ItemStack.class); - registerType("chestplate", ItemStack.class); - registerType("leggings", ItemStack.class); - registerType("boots", ItemStack.class); - registerType("hand", ItemStack.class); - registerType("offhand", ItemStack.class); - registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation registerType("potion_color", Color.BLACK); registerType("potion_ambient", false); From fed7b7085a1ac3f47f487fc245f970390677e694 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sat, 5 Aug 2023 09:31:00 +0530 Subject: [PATCH 21/78] Added hologram items --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 16 ++- .../commands/hologram/HoloAddCommand.java | 14 ++- .../commands/hologram/HoloAddItemCommand.java | 39 ++++++ .../commands/hologram/HoloInfoCommand.java | 7 +- .../commands/hologram/HoloInsertCommand.java | 14 ++- .../hologram/HoloInsertItemCommand.java | 45 +++++++ .../commands/hologram/HoloSetCommand.java | 10 +- .../commands/hologram/HoloSetItemCommand.java | 48 ++++++++ .../conversion/citizens/CitizensImporter.java | 2 +- .../conversion/znpcs/ZNpcImporter.java | 2 +- .../entity/EntityPropertyRegistryImpl.java | 1 + .../entity/properties/HoloItemProperty.java | 24 ++++ .../pyr/znpcsplus/hologram/HologramImpl.java | 88 +++++++++++--- .../pyr/znpcsplus/hologram/HologramItem.java | 111 ++++++++++++++++++ .../pyr/znpcsplus/hologram/HologramLine.java | 47 ++++---- .../pyr/znpcsplus/hologram/HologramText.java | 30 +++++ .../znpcsplus/storage/yaml/YamlStorage.java | 8 +- 17 files changed, 431 insertions(+), 75 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddItemCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertItemCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetItemCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 52fb321..7524491 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -202,9 +202,9 @@ public class ZNpcsPlus extends JavaPlugin { NpcEntryImpl entry = npcRegistry.create("debug_npc_" + i, world, type, new NpcLocation(i * 3, 200, 0, 0, 0)); entry.setProcessed(true); NpcImpl npc = entry.getNpc(); - npc.getHologram().addLineComponent(Component.text("Hello, World!", TextColor.color(255, 0, 0))); - npc.getHologram().addLineComponent(Component.text("Hello, World!", TextColor.color(0, 255, 0))); - npc.getHologram().addLineComponent(Component.text("Hello, World!", TextColor.color(0, 0, 255))); + npc.getHologram().addTextLineComponent(Component.text("Hello, World!", TextColor.color(255, 0, 0))); + npc.getHologram().addTextLineComponent(Component.text("Hello, World!", TextColor.color(0, 255, 0))); + npc.getHologram().addTextLineComponent(Component.text("Hello, World!", TextColor.color(0, 0, 255))); i++; } } @@ -214,6 +214,7 @@ public class ZNpcsPlus extends JavaPlugin { public void onDisable() { NpcApiProvider.unregister(); for (Runnable runnable : shutdownTasks) runnable.run(); + shutdownTasks.clear(); PacketEvents.getAPI().terminate(); } @@ -283,11 +284,14 @@ public class ZNpcsPlus extends JavaPlugin { .addSubcommand("reload", new LoadAllCommand(npcRegistry)) .addSubcommand("import", new ImportCommand(npcRegistry, importerRegistry))) .addSubcommand("holo", new MultiCommand(loadHelpMessage("holo")) - .addSubcommand("add", new HoloAddCommand(npcRegistry, textSerializer)) + .addSubcommand("add", new HoloAddCommand(npcRegistry)) + .addSubcommand("additem", new HoloAddItemCommand(npcRegistry)) .addSubcommand("delete", new HoloDeleteCommand(npcRegistry)) .addSubcommand("info", new HoloInfoCommand(npcRegistry)) - .addSubcommand("insert", new HoloInsertCommand(npcRegistry, textSerializer)) - .addSubcommand("set", new HoloSetCommand(npcRegistry, textSerializer)) + .addSubcommand("insert", new HoloInsertCommand(npcRegistry)) + .addSubcommand("insertitem", new HoloInsertItemCommand(npcRegistry)) + .addSubcommand("set", new HoloSetCommand(npcRegistry)) + .addSubcommand("setitem", new HoloSetItemCommand(npcRegistry)) .addSubcommand("offset", new HoloOffsetCommand(npcRegistry)) .addSubcommand("refreshdelay", new HoloRefreshDelayCommand(npcRegistry))) .addSubcommand("action", new MultiCommand(loadHelpMessage("action")) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java index cf4ed32..f739d18 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java @@ -4,22 +4,20 @@ import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.hologram.HologramImpl; +import lol.pyr.znpcsplus.hologram.HologramItem; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Collections; import java.util.List; public class HoloAddCommand implements CommandHandler { private final NpcRegistryImpl registry; - private final LegacyComponentSerializer textSerializer; - public HoloAddCommand(NpcRegistryImpl registry, LegacyComponentSerializer textSerializer) { + public HoloAddCommand(NpcRegistryImpl registry) { this.registry = registry; - this.textSerializer = textSerializer; } @Override @@ -27,7 +25,13 @@ public class HoloAddCommand implements CommandHandler { context.setUsage(context.getLabel() + " holo add "); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); context.ensureArgsNotEmpty(); - hologram.addLineComponent(textSerializer.deserialize(context.dumpAllArgs())); + String in = context.dumpAllArgs(); + if (in.toLowerCase().startsWith("item:")) { + if (!HologramItem.ensureValidItemInput(in.substring(5))) { + context.halt(Component.text("The item input is invalid!", NamedTextColor.RED)); + } + } + hologram.addLine(in); context.send(Component.text("NPC line added!", NamedTextColor.GREEN)); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddItemCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddItemCommand.java new file mode 100644 index 0000000..cb23a56 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddItemCommand.java @@ -0,0 +1,39 @@ +package lol.pyr.znpcsplus.commands.hologram; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.command.CommandHandler; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.hologram.HologramImpl; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +public class HoloAddItemCommand implements CommandHandler { + private final NpcRegistryImpl registry; + + public HoloAddItemCommand(NpcRegistryImpl registry) { + this.registry = registry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " holo additem "); + Player player = context.ensureSenderIsPlayer(); + org.bukkit.inventory.ItemStack itemStack = player.getInventory().getItemInHand(); + if (itemStack == null) context.halt(Component.text("You must be holding an item!", NamedTextColor.RED)); + HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); + hologram.addItemLineStack(itemStack); + context.send(Component.text("NPC item line added!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(registry.getModifiableIds()); + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInfoCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInfoCommand.java index f9e2c5e..20c5a6c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInfoCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInfoCommand.java @@ -4,7 +4,6 @@ import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.hologram.HologramImpl; -import lol.pyr.znpcsplus.hologram.HologramLine; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import net.kyori.adventure.text.Component; @@ -26,7 +25,11 @@ public class HoloInfoCommand implements CommandHandler { NpcEntryImpl entry = context.parse(NpcEntryImpl.class); HologramImpl hologram = entry.getNpc().getHologram(); Component component = Component.text("NPC Hologram Info of ID " + entry.getId() + ":", NamedTextColor.GREEN).appendNewline(); - for (HologramLine line : hologram.getLines()) component = component.append(line.getText()).appendNewline(); + for (int i = 0; i < hologram.getLines().size(); i++) { + component = component.append(Component.text(i + ") ", NamedTextColor.GREEN)) + .append(Component.text(hologram.getLine(i), NamedTextColor.WHITE)) + .appendNewline(); + } context.send(component); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java index 7429410..8bb8471 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java @@ -4,11 +4,11 @@ import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.hologram.HologramImpl; +import lol.pyr.znpcsplus.hologram.HologramItem; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Collections; import java.util.List; @@ -16,11 +16,9 @@ import java.util.stream.Stream; public class HoloInsertCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; - private final LegacyComponentSerializer componentSerializer; - public HoloInsertCommand(NpcRegistryImpl npcRegistry, LegacyComponentSerializer componentSerializer) { + public HoloInsertCommand(NpcRegistryImpl npcRegistry) { this.npcRegistry = npcRegistry; - this.componentSerializer = componentSerializer; } @Override @@ -30,7 +28,13 @@ public class HoloInsertCommand implements CommandHandler { int line = context.parse(Integer.class); if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); context.ensureArgsNotEmpty(); - hologram.insertLineComponent(line, componentSerializer.deserialize(context.dumpAllArgs())); + String in = context.dumpAllArgs(); + if (in.toLowerCase().startsWith("item:")) { + if (!HologramItem.ensureValidItemInput(in.substring(5))) { + context.halt(Component.text("The item input is invalid!", NamedTextColor.RED)); + } + } + hologram.insertLine(line, in); context.send(Component.text("NPC line inserted!", NamedTextColor.GREEN)); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertItemCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertItemCommand.java new file mode 100644 index 0000000..68273e4 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertItemCommand.java @@ -0,0 +1,45 @@ +package lol.pyr.znpcsplus.commands.hologram; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.command.CommandHandler; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.hologram.HologramImpl; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +public class HoloInsertItemCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; + + public HoloInsertItemCommand(NpcRegistryImpl npcRegistry) { + this.npcRegistry = npcRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " holo insertitem "); + HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); + int line = context.parse(Integer.class); + if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); + Player player = context.ensureSenderIsPlayer(); + org.bukkit.inventory.ItemStack itemStack = player.getInventory().getItemInHand(); + if (itemStack == null) context.halt(Component.text("You must be holding an item!", NamedTextColor.RED)); + hologram.insertItemLineStack(line, itemStack); + context.send(Component.text("NPC item line inserted!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) + .limit(context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram().getLines().size()) + .map(String::valueOf)); + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java index df3678a..7b106b0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java @@ -8,7 +8,6 @@ import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Collections; import java.util.List; @@ -16,11 +15,9 @@ import java.util.stream.Stream; public class HoloSetCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; - private final LegacyComponentSerializer componentSerializer; - public HoloSetCommand(NpcRegistryImpl npcRegistry, LegacyComponentSerializer componentSerializer) { + public HoloSetCommand(NpcRegistryImpl npcRegistry) { this.npcRegistry = npcRegistry; - this.componentSerializer = componentSerializer; } @Override @@ -31,7 +28,7 @@ public class HoloSetCommand implements CommandHandler { if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); context.ensureArgsNotEmpty(); hologram.removeLine(line); - hologram.insertLineComponent(line, componentSerializer.deserialize(context.dumpAllArgs())); + hologram.insertLine(line, context.dumpAllArgs()); context.send(Component.text("NPC line set!", NamedTextColor.GREEN)); } @@ -42,8 +39,7 @@ public class HoloSetCommand implements CommandHandler { HologramImpl hologram = context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram(); if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) .limit(hologram.getLines().size()).map(String::valueOf)); - if (context.argSize() == 3) return context.suggestLiteral(componentSerializer.serialize( - hologram.getLineComponent(context.suggestionParse(1, Integer.class)))); + if (context.argSize() == 3) return context.suggestLiteral(hologram.getLine(context.suggestionParse(1, Integer.class))); } return Collections.emptyList(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetItemCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetItemCommand.java new file mode 100644 index 0000000..1e623ab --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetItemCommand.java @@ -0,0 +1,48 @@ +package lol.pyr.znpcsplus.commands.hologram; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.command.CommandHandler; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.hologram.HologramImpl; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +public class HoloSetItemCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; + + public HoloSetItemCommand(NpcRegistryImpl npcRegistry) { + this.npcRegistry = npcRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " holo setitem "); + HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); + int line = context.parse(Integer.class); + if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); + Player player = context.ensureSenderIsPlayer(); + org.bukkit.inventory.ItemStack itemStack = player.getInventory().getItemInHand(); + if (itemStack == null) context.halt(Component.text("You must be holding an item!", NamedTextColor.RED)); + hologram.removeLine(line); + hologram.insertItemLineStack(line, itemStack); + context.send(Component.text("NPC item line set!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + if (context.argSize() >= 2) { + HologramImpl hologram = context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram(); + if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) + .limit(hologram.getLines().size()).map(String::valueOf)); + } + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java index 39b3deb..2a17d34 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java @@ -82,7 +82,7 @@ public class CitizensImporter implements DataImporter { world = Bukkit.getWorlds().get(0).getName(); } NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world, typeRegistry.getByName("armor_stand"), new NpcLocation(0, 0, 0, 0, 0)); - npc.getHologram().addLineComponent(textSerializer.deserialize(name)); + npc.getHologram().addTextLineComponent(textSerializer.deserialize(name)); ConfigurationSection traits = npcSection.getConfigurationSection("traits"); if (traits != null) { for (String traitName : traits.getKeys(false)) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java index d652d64..6c17b35 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java @@ -106,7 +106,7 @@ public class ZNpcImporter implements DataImporter { hologram.setOffset(model.getHologramHeight()); for (String raw : model.getHologramLines()) { Component line = textSerializer.deserialize(raw); - hologram.addLineComponent(line); + hologram.addTextLineComponent(line); } for (ZNpcsAction action : model.getClickActions()) { 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 bea8614..b2e2e99 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -254,6 +254,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new GlowProperty(packetFactory)); register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("invisible", 0x20)); + register(new HoloItemProperty()); linkProperties("glow", "fire", "invisible"); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java new file mode 100644 index 0000000..cb590c5 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java @@ -0,0 +1,24 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.protocol.item.ItemStack; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class HoloItemProperty extends EntityPropertyImpl { + + public HoloItemProperty() { + super("holo_item", null, ItemStack.class); + setPlayerModifiable(false); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + properties.put(8, newEntityData(8, EntityDataTypes.ITEMSTACK, entity.getProperty(this))); + properties.put(5, newEntityData(5, EntityDataTypes.BOOLEAN, true)); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java index f85301e..89ed907 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java @@ -1,11 +1,13 @@ package lol.pyr.znpcsplus.hologram; +import com.github.retrooper.packetevents.protocol.item.ItemStack; +import io.github.retrooper.packetevents.util.SpigotConversionUtil; import lol.pyr.znpcsplus.api.hologram.Hologram; import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; -import lol.pyr.znpcsplus.util.Viewable; import lol.pyr.znpcsplus.util.NpcLocation; +import lol.pyr.znpcsplus.util.Viewable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; @@ -24,7 +26,7 @@ public class HologramImpl extends Viewable implements Hologram { private long refreshDelay = -1; private long lastRefresh = System.currentTimeMillis(); private NpcLocation location; - private final List lines = new ArrayList<>(); + private final List> lines = new ArrayList<>(); public HologramImpl(EntityPropertyRegistryImpl propertyRegistry, ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, NpcLocation location) { this.propertyRegistry = propertyRegistry; @@ -34,32 +36,59 @@ public class HologramImpl extends Viewable implements Hologram { this.location = location; } - public void addLineComponent(Component line) { - HologramLine newLine = new HologramLine(propertyRegistry, packetFactory, null, line); + public void addTextLineComponent(Component line) { + HologramText newLine = new HologramText(propertyRegistry, packetFactory, null, line); + lines.add(newLine); + relocateLines(newLine); + for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); + } + + public void addTextLine(String line) { + addTextLineComponent(textSerializer.deserialize(line)); + } + + public void addItemLineStack(org.bukkit.inventory.ItemStack item) { + addItemLinePEStack(SpigotConversionUtil.fromBukkitItemStack(item)); + } + + public void addItemLine(String serializedItem) { + addItemLinePEStack(HologramItem.deserialize(serializedItem)); + } + + public void addItemLinePEStack(ItemStack item) { + HologramItem newLine = new HologramItem(propertyRegistry, packetFactory, null, item); lines.add(newLine); relocateLines(newLine); for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); } public void addLine(String line) { - addLineComponent(textSerializer.deserialize(line)); + if (line.toLowerCase().startsWith("item:")) { + addItemLine(line.substring(5)); + } else { + addTextLine(line); + } } - public Component getLineComponent(int index) { - return lines.get(index).getText(); + public Component getLineTextComponent(int index) { + return ((HologramText) lines.get(index)).getValue(); } public String getLine(int index) { - return textSerializer.serialize(getLineComponent(index)); + if (lines.get(index) instanceof HologramItem) { + return ((HologramItem) lines.get(index)).serialize(); + } else { + return textSerializer.serialize(getLineTextComponent(index)); + } } public void removeLine(int index) { - HologramLine line = lines.remove(index); + HologramLine line = lines.remove(index); for (Player viewer : getViewers()) line.hide(viewer); relocateLines(); } - public List getLines() { + public List> getLines() { return Collections.unmodifiableList(lines); } @@ -68,25 +97,48 @@ public class HologramImpl extends Viewable implements Hologram { lines.clear(); } - public void insertLineComponent(int index, Component line) { - HologramLine newLine = new HologramLine(propertyRegistry, packetFactory, null, line); + public void insertTextLineComponent(int index, Component line) { + HologramText newLine = new HologramText(propertyRegistry, packetFactory, null, line); lines.add(index, newLine); relocateLines(newLine); for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); } + public void insertTextLine(int index, String line) { + insertTextLineComponent(index, textSerializer.deserialize(line)); + } + + public void insertItemLineStack(int index, org.bukkit.inventory.ItemStack item) { + insertItemLinePEStack(index, SpigotConversionUtil.fromBukkitItemStack(item)); + } + + public void insertItemLinePEStack(int index, ItemStack item) { + HologramItem newLine = new HologramItem(propertyRegistry, packetFactory, null, item); + lines.add(index, newLine); + relocateLines(newLine); + for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); + } + + public void insertItemLine(int index, String item) { + insertItemLinePEStack(index, HologramItem.deserialize(item)); + } + public void insertLine(int index, String line) { - insertLineComponent(index, textSerializer.deserialize(line)); + if (line.toLowerCase().startsWith("item:")) { + insertItemLine(index, line.substring(5)); + } else { + insertTextLine(index, line); + } } @Override protected void UNSAFE_show(Player player) { - for (HologramLine line : lines) line.show(player); + for (HologramLine line : lines) line.show(player); } @Override protected void UNSAFE_hide(Player player) { - for (HologramLine line : lines) line.hide(player); + for (HologramLine line : lines) line.hide(player); } public long getRefreshDelay() { @@ -103,7 +155,7 @@ public class HologramImpl extends Viewable implements Hologram { public void refresh() { lastRefresh = System.currentTimeMillis(); - for (HologramLine line : lines) for (Player viewer : getViewers()) line.refreshMeta(viewer); + for (HologramLine line : lines) for (Player viewer : getViewers()) line.refreshMeta(viewer); } public void setLocation(NpcLocation location) { @@ -115,10 +167,10 @@ public class HologramImpl extends Viewable implements Hologram { relocateLines(null); } - private void relocateLines(HologramLine newLine) { + private void relocateLines(HologramLine newLine) { final double lineSpacing = configManager.getConfig().lineSpacing(); double height = location.getY() + (lines.size() - 1) * lineSpacing + getOffset(); - for (HologramLine line : lines) { + for (HologramLine line : lines) { line.setLocation(location.withY(height), line == newLine ? Collections.emptySet() : getViewers()); height -= lineSpacing; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java new file mode 100644 index 0000000..c25e434 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java @@ -0,0 +1,111 @@ +package lol.pyr.znpcsplus.hologram; + +import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import com.github.retrooper.packetevents.protocol.item.ItemStack; +import com.github.retrooper.packetevents.protocol.item.type.ItemType; +import com.github.retrooper.packetevents.protocol.item.type.ItemTypes; +import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; +import com.github.retrooper.packetevents.protocol.nbt.NBTInt; +import com.github.retrooper.packetevents.protocol.nbt.NBTNumber; +import com.github.retrooper.packetevents.protocol.nbt.codec.NBTCodec; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; +import lol.pyr.znpcsplus.api.entity.EntityProperty; +import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; +import lol.pyr.znpcsplus.packets.PacketFactory; +import lol.pyr.znpcsplus.util.NpcLocation; +import org.bukkit.entity.Player; + +import java.util.Collection; + +public class HologramItem extends HologramLine { + public HologramItem(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, ItemStack item) { + super(item, packetFactory, EntityTypes.ITEM, location); + addProperty(propertyRegistry.getByName("holo_item")); + } + + @SuppressWarnings("unchecked") + @Override + public T getProperty(EntityProperty key) { + if (key.getName().equalsIgnoreCase("holo_item")) return (T) getValue(); + return super.getProperty(key); + } + + @Override + public void setLocation(NpcLocation location, Collection viewers) { + super.setLocation(location.withY(location.getY() + 2.05), viewers); + } + + public static boolean ensureValidItemInput(String in) { + if (in == null || in.isEmpty()) { + return false; + } + + int indexOfNbt = in.indexOf("{"); + if (indexOfNbt != -1) { + String typeName = in.substring(0, indexOfNbt); + ItemType type = ItemTypes.getByName("minecraft:" + typeName.toLowerCase()); + if (type == null) { + return false; + } + String nbtString = in.substring(indexOfNbt); + return ensureValidNbt(nbtString); + } else { + ItemType type = ItemTypes.getByName("minecraft:" + in.toLowerCase()); + return type != null; + } + } + + private static boolean ensureValidNbt(String nbtString) { + JsonElement nbtJson; + try { + nbtJson = JsonParser.parseString(nbtString); + } catch (JsonSyntaxException e) { + return false; + } + try { + NBTCodec.jsonToNBT(nbtJson); + } catch (Exception ignored) { + return false; + } + return true; + } + + public static ItemStack deserialize(String serializedItem) { + int indexOfNbt = serializedItem.indexOf("{"); + String typeName = serializedItem; + int amount = 1; + NBTCompound nbt = new NBTCompound(); + if (indexOfNbt != -1) { + typeName = serializedItem.substring(0, indexOfNbt); + String nbtString = serializedItem.substring(indexOfNbt); + JsonElement nbtJson = null; + try { + nbtJson = JsonParser.parseString(nbtString); + } catch (Exception ignored) { + } + if (nbtJson != null) { + nbt = (NBTCompound) NBTCodec.jsonToNBT(nbtJson); + NBTNumber nbtAmount = nbt.getNumberTagOrNull("Count"); + if (nbtAmount != null) { + nbt.removeTag("Count"); + amount = nbtAmount.getAsInt(); + if (amount <= 0) amount = 1; + if (amount > 127) amount = 127; + } + } + } + ItemType type = ItemTypes.getByName("minecraft:" + typeName.toLowerCase()); + if (type == null) type = ItemTypes.STONE; + return ItemStack.builder().type(type).amount(amount).nbt(nbt).build(); + } + + public String serialize() { + NBTCompound nbt = getValue().getNBT(); + if (nbt == null) nbt = new NBTCompound(); + if (getValue().getAmount() > 1) nbt.setTag("Count", new NBTInt(getValue().getAmount())); + if (nbt.isEmpty()) return "item:" + getValue().getType().getName().toString().replace("minecraft:", ""); + return "item:" + getValue().getType().getName().toString().replace("minecraft:", "") + NBTCodec.nbtToJson(nbt, true); + } +} 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 df76abd..9bb695f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java @@ -1,76 +1,73 @@ package lol.pyr.znpcsplus.hologram; -import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import com.github.retrooper.packetevents.protocol.entity.type.EntityType; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.PropertyHolder; -import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.util.NpcLocation; -import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.Collection; import java.util.HashSet; import java.util.Set; -public class HologramLine implements PropertyHolder { - private Component text; - private final PacketEntity armorStand; +public class HologramLine implements PropertyHolder { + private M value; + private final PacketEntity entity; private final Set> properties; - public HologramLine(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, Component text) { - this.text = text; + public HologramLine(M value, PacketFactory packetFactory, EntityType type, NpcLocation location) { + this.value = value; + this.entity = new PacketEntity(packetFactory, this, type, location); this.properties = new HashSet<>(); - this.properties.add(propertyRegistry.getByName("name")); - this.properties.add(propertyRegistry.getByName("invisible")); - armorStand = new PacketEntity(packetFactory, this, EntityTypes.ARMOR_STAND, location); } - public Component getText() { - return text; + public M getValue() { + return value; } - public void setText(Component text) { - this.text = text; + public void setValue(M value) { + this.value = value; } public void refreshMeta(Player player) { - armorStand.refreshMeta(player); + entity.refreshMeta(player); } protected void show(Player player) { - armorStand.spawn(player); + entity.spawn(player); } protected void hide(Player player) { - armorStand.despawn(player); + entity.despawn(player); } public void setLocation(NpcLocation location, Collection viewers) { - armorStand.setLocation(location, viewers); + entity.setLocation(location, viewers); } public int getEntityId() { - return armorStand.getEntityId(); + return entity.getEntityId(); + } + + public void addProperty(EntityProperty property) { + properties.add(property); } - @SuppressWarnings("unchecked") @Override public T getProperty(EntityProperty key) { - if (key.getName().equalsIgnoreCase("invisible")) return (T) Boolean.TRUE; - if (key.getName().equalsIgnoreCase("name")) return (T) text; return key.getDefaultValue(); } @Override public boolean hasProperty(EntityProperty key) { - return key.getName().equalsIgnoreCase("name") || key.getName().equalsIgnoreCase("invisible"); + return properties.contains(key); } @Override public void setProperty(EntityProperty key, T value) { - throw new UnsupportedOperationException("Can't set properties on a hologram"); + throw new UnsupportedOperationException("Can't set properties on a hologram line"); } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java new file mode 100644 index 0000000..2c66aef --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java @@ -0,0 +1,30 @@ +package lol.pyr.znpcsplus.hologram; + +import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import lol.pyr.znpcsplus.api.entity.EntityProperty; +import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; +import lol.pyr.znpcsplus.packets.PacketFactory; +import lol.pyr.znpcsplus.util.NpcLocation; +import net.kyori.adventure.text.Component; + +public class HologramText extends HologramLine { + + public HologramText(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, Component text) { + super(text, packetFactory, EntityTypes.ARMOR_STAND, location); + addProperty(propertyRegistry.getByName("name")); + addProperty(propertyRegistry.getByName("invisible")); + } + + @SuppressWarnings("unchecked") + @Override + public T getProperty(EntityProperty key) { + if (key.getName().equalsIgnoreCase("invisible")) return (T) Boolean.TRUE; + if (key.getName().equalsIgnoreCase("name")) return (T) getValue(); + return super.getProperty(key); + } + + @Override + public boolean hasProperty(EntityProperty key) { + return key.getName().equalsIgnoreCase("name") || key.getName().equalsIgnoreCase("invisible"); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index ef1407b..9f0ef66 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -6,7 +6,6 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.hologram.HologramImpl; -import lol.pyr.znpcsplus.hologram.HologramLine; import lol.pyr.znpcsplus.interaction.ActionRegistry; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcImpl; @@ -14,7 +13,6 @@ import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.storage.NpcStorage; import lol.pyr.znpcsplus.util.NpcLocation; -import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; @@ -73,7 +71,7 @@ public class YamlStorage implements NpcStorage { HologramImpl hologram = npc.getHologram(); hologram.setOffset(config.getDouble("hologram.offset", 0.0)); hologram.setRefreshDelay(config.getLong("hologram.refresh-delay", -1)); - for (String line : config.getStringList("hologram.lines")) hologram.addLineComponent(MiniMessage.miniMessage().deserialize(line)); + for (String line : config.getStringList("hologram.lines")) hologram.addLine(line); for (String s : config.getStringList("actions")) npc.addAction(actionRegistry.deserialize(s)); NpcEntryImpl entry = new NpcEntryImpl(config.getString("id"), npc); @@ -112,8 +110,8 @@ public class YamlStorage implements NpcStorage { if (hologram.getOffset() != 0.0) config.set("hologram.offset", hologram.getOffset()); if (hologram.getRefreshDelay() != -1) config.set("hologram.refresh-delay", hologram.getRefreshDelay()); List lines = new ArrayList<>(npc.getHologram().getLines().size()); - for (HologramLine line : hologram.getLines()) { - lines.add(MiniMessage.miniMessage().serialize(line.getText())); + for (int i = 0; i < hologram.getLines().size(); i++) { + lines.add(hologram.getLine(i)); } config.set("hologram.lines", lines); config.set("actions", npc.getActions().stream() From f3d5e3f3a86e507c3812c581cfa9c4619242f8ad Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 5 Aug 2023 20:49:48 +0200 Subject: [PATCH 22/78] implement silent property (untested) --- .../entity/EntityPropertyRegistryImpl.java | 9 ++++--- .../properties/SimpleBooleanProperty.java | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java 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 8d7d76f..b707c49 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -1,5 +1,7 @@ package lol.pyr.znpcsplus.entity; +import com.github.retrooper.packetevents.PacketEvents; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; @@ -55,9 +57,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerLevel.class); /* - registerType("silent", false); - registerType("name", Component.class); - registerType("look", false); registerType("dinnerbone", false); registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -228,6 +227,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { } public void registerTypes(PacketFactory packetFactory) { + ServerVersion ver = PacketEvents.getAPI().getServerManager().getVersion(); + register(new EquipmentProperty(packetFactory, "helmet", EquipmentSlot.HELMET)); register(new EquipmentProperty(packetFactory, "chestplate", EquipmentSlot.CHEST_PLATE)); register(new EquipmentProperty(packetFactory, "leggings", EquipmentSlot.LEGGINGS)); @@ -243,6 +244,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("invisible", 0x20)); linkProperties("glow", "fire", "invisible"); + + register(new SimpleBooleanProperty("silent", 4, false, ver.isOlderThan(ServerVersion.V_1_9))); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java new file mode 100644 index 0000000..763b0a9 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java @@ -0,0 +1,26 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class SimpleBooleanProperty extends EntityPropertyImpl { + private final int index; + private final boolean legacy; + + public SimpleBooleanProperty(String name, int index, boolean defaultValue, boolean legacy) { + super(name, defaultValue, Boolean.class); + this.index = index; + this.legacy = legacy; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + if (legacy) properties.put(index, new EntityData(index, EntityDataTypes.BYTE, (entity.getProperty(this) ? 1 : 0))); + else properties.put(index, new EntityData(index, EntityDataTypes.BOOLEAN, entity.getProperty(this))); + } +} From c11093c39267cc75516ea73e753f4653504cb889 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 5 Aug 2023 21:50:07 +0200 Subject: [PATCH 23/78] implement armor stand properties --- .../entity/EntityPropertyRegistryImpl.java | 15 ++++++-- .../entity/properties/EffectsProperty.java | 25 ------------- .../properties/SimpleBitsetProperty.java | 35 +++++++++++++++++++ 3 files changed, 48 insertions(+), 27 deletions(-) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java 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 b707c49..3fbe883 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -241,11 +241,22 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new DummyProperty<>("skin", SkinDescriptor.class, false)); register(new GlowProperty(packetFactory)); - register(new EffectsProperty("fire", 0x01)); - register(new EffectsProperty("invisible", 0x20)); + register(new SimpleBitsetProperty("fire", 0, 0x01)); + register(new SimpleBitsetProperty("invisible", 0, 0x20)); linkProperties("glow", "fire", "invisible"); register(new SimpleBooleanProperty("silent", 4, false, ver.isOlderThan(ServerVersion.V_1_9))); + + int armorStandIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandIndex = 11; + else armorStandIndex = 10; + register(new SimpleBitsetProperty("small", armorStandIndex, 0x01)); + 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/EffectsProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java deleted file mode 100644 index e031ad7..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EffectsProperty.java +++ /dev/null @@ -1,25 +0,0 @@ -package lol.pyr.znpcsplus.entity.properties; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import lol.pyr.znpcsplus.entity.EntityPropertyImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class EffectsProperty extends EntityPropertyImpl { - private final int bitmask; - - public EffectsProperty(String name, int bitmask) { - super(name, false, Boolean.class); - this.bitmask = bitmask; - } - - @Override - public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - EntityData oldData = properties.get(0); - byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); - properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (entity.getProperty(this) ? bitmask : 0)))); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java new file mode 100644 index 0000000..e533992 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java @@ -0,0 +1,35 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class SimpleBitsetProperty extends EntityPropertyImpl { + private final int index; + private final int bitmask; + private final boolean inverted; + + public SimpleBitsetProperty(String name, int index, int bitmask, boolean inverted) { + super(name, !inverted, Boolean.class); + this.index = index; + this.bitmask = bitmask; + this.inverted = inverted; + } + + public SimpleBitsetProperty(String name, int index, int bitmask) { + this(name, index, bitmask, false); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + EntityData oldData = properties.get(index); + byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); + boolean enabled = entity.getProperty(this); + if (inverted) enabled = !enabled; + properties.put(index, newEntityData(index, EntityDataTypes.BYTE, (byte) (oldValue | (enabled ? bitmask : 0)))); + } +} From b50c5b5e5db042f61529880939e30b677663d6ca Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 5 Aug 2023 23:04:16 +0200 Subject: [PATCH 24/78] remove useless comment --- .../znpcsplus/packets/V1_8PacketFactory.java | 121 ------------------ 1 file changed, 121 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index cbbc35b..b0ec7de 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -125,127 +125,6 @@ public class V1_8PacketFactory implements PacketFactory { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.REMOVE, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null)); } - /* - List data = new ArrayList<>(); - data.add(metadataFactory.effects( - properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)), - false, - properties.getProperty(propertyRegistry.getByName("invisible", Boolean.class)), - false, - properties.getProperty(propertyRegistry.getByName("using_item", Boolean.class)) - )); - data.add(metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class)))); - data.add(metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", Color.class)).asRGB())); - data.add(metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class)))); - if (entity.getType().equals(EntityTypes.PLAYER)) { - data.add(metadataFactory.skinLayers( - properties.getProperty(propertyRegistry.getByName("skin_cape", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_jacket", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_left_sleeve", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_right_sleeve", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_left_leg", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_right_leg", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_hat", Boolean.class)) - )); - data.add(metadataFactory.shoulderEntityLeft(properties.getProperty(propertyRegistry.getByName("shoulder_entity_left", ParrotVariant.class)))); - data.add(metadataFactory.shoulderEntityRight(properties.getProperty(propertyRegistry.getByName("shoulder_entity_right", ParrotVariant.class)))); - } - else if (entity.getType().equals(EntityTypes.ARMOR_STAND)) { - data.add(metadataFactory.armorStandProperties( - properties.getProperty(propertyRegistry.getByName("small", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("arms", Boolean.class)), - !properties.getProperty(propertyRegistry.getByName("base_plate", Boolean.class)) - )); - data.add(metadataFactory.armorStandHeadRotation(properties.getProperty(propertyRegistry.getByName("head_rotation", Vector3f.class)))); - data.add(metadataFactory.armorStandBodyRotation(properties.getProperty(propertyRegistry.getByName("body_rotation", Vector3f.class)))); - data.add(metadataFactory.armorStandLeftArmRotation(properties.getProperty(propertyRegistry.getByName("left_arm_rotation", Vector3f.class)))); - data.add(metadataFactory.armorStandRightArmRotation(properties.getProperty(propertyRegistry.getByName("right_arm_rotation", Vector3f.class)))); - data.add(metadataFactory.armorStandLeftLegRotation(properties.getProperty(propertyRegistry.getByName("left_leg_rotation", Vector3f.class)))); - data.add(metadataFactory.armorStandRightLegRotation(properties.getProperty(propertyRegistry.getByName("right_leg_rotation", Vector3f.class)))); - } - else if (entity.getType().equals(EntityTypes.AXOLOTL)) { - data.add(metadataFactory.axolotlVariant(properties.getProperty(propertyRegistry.getByName("axolotl_variant", Integer.class)))); - data.add(metadataFactory.playingDead(properties.getProperty(propertyRegistry.getByName("playing_dead", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.BAT)) { - data.add(metadataFactory.batHanging(properties.getProperty(propertyRegistry.getByName("hanging", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.BEE)) { - data.add(metadataFactory.beeAngry(properties.getProperty(propertyRegistry.getByName("angry", Boolean.class)))); - data.add(metadataFactory.beeHasNectar(properties.getProperty(propertyRegistry.getByName("has_nectar", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.BLAZE)) { - data.add(metadataFactory.blazeOnFire(properties.getProperty(propertyRegistry.getByName("blaze_on_fire", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.CAT)) { - data.add(metadataFactory.catVariant(properties.getProperty(propertyRegistry.getByName("cat_variant", CatVariant.class)))); - data.add(metadataFactory.catLying(properties.getProperty(propertyRegistry.getByName("cat_lying", Boolean.class)))); - data.add(metadataFactory.catCollarColor(properties.getProperty(propertyRegistry.getByName("cat_collar_color", DyeColor.class)))); - data.add(metadataFactory.catTamed(properties.hasProperty(propertyRegistry.getByName("cat_collar_color", DyeColor.class)))); - } - else if (entity.getType().equals(EntityTypes.CREEPER)) { - data.add(metadataFactory.creeperState(properties.getProperty(propertyRegistry.getByName("creeper_state", CreeperState.class)))); - data.add(metadataFactory.creeperCharged(properties.getProperty(propertyRegistry.getByName("creeper_charged", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.ENDERMAN)) { - data.add(metadataFactory.endermanHeldBlock( - properties.getProperty(propertyRegistry.getByName("enderman_held_block", BlockState.class)).getGlobalId()) - ); - data.add(metadataFactory.endermanScreaming(properties.getProperty(propertyRegistry.getByName("enderman_screaming", Boolean.class)))); - data.add(metadataFactory.endermanStaring(properties.getProperty(propertyRegistry.getByName("enderman_staring", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.EVOKER)) { - data.add(metadataFactory.evokerSpell(properties.getProperty(propertyRegistry.getByName("evoker_spell", SpellType.class)).ordinal())); - } - else if (entity.getType().equals(EntityTypes.FOX)) { - // Not sure if this should be in here or in 1.14 PacketFactory - data.add(metadataFactory.foxVariant(properties.getProperty(propertyRegistry.getByName("fox_variant", FoxVariant.class)).ordinal())); - data.add(metadataFactory.foxProperties( - properties.getProperty(propertyRegistry.getByName("fox_sitting", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("fox_crouching", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("fox_sleeping", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("fox_faceplanted", Boolean.class)) - )); - } - else if (entity.getType().equals(EntityTypes.FROG)) { - data.add(metadataFactory.frogVariant(properties.getProperty(propertyRegistry.getByName("frog_variant", FrogVariant.class)).ordinal())); - } - else if (entity.getType().equals(EntityTypes.GHAST)) { - data.add(metadataFactory.ghastAttacking(properties.getProperty(propertyRegistry.getByName("attacking", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.GOAT)) { - data.add(metadataFactory.goatHasLeftHorn(properties.getProperty(propertyRegistry.getByName("has_left_horn", Boolean.class)))); - data.add(metadataFactory.goatHasRightHorn(properties.getProperty(propertyRegistry.getByName("has_right_horn", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.GUARDIAN)) { - // TODO - } - else if (entity.getType().equals(EntityTypes.HOGLIN)) { - data.add(metadataFactory.hoglinImmuneToZombification(properties.getProperty(propertyRegistry.getByName("immune_to_zombification", Boolean.class)))); - } - else if (entity.getType().equals(EntityTypes.VILLAGER)) { - VillagerProfession profession = properties.getProperty(propertyRegistry.getByName("villager_profession", VillagerProfession.class)); - int professionId = profession.ordinal(); - if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_14)) { - professionId = profession.getLegacyId(); - } - data.add(metadataFactory.villagerData( - properties.getProperty(propertyRegistry.getByName("villager_type", VillagerType.class)).ordinal(), - professionId, - properties.getProperty(propertyRegistry.getByName("villager_level", VillagerLevel.class)).ordinal() + 1 - )); - } - - if (properties.getProperty(propertyRegistry.getByName("dinnerbone", Boolean.class))) { - data.add(metadataFactory.name(Component.text("Dinnerbone"))); - } - else if (properties.hasProperty(propertyRegistry.getByName("name"))) { - data.add(metadataFactory.name(PapiUtil.set(textSerializer, player, properties.getProperty(propertyRegistry.getByName("name", Component.class))))); - data.add(metadataFactory.nameShown()); - } - return data; - */ - @Override public void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties) { Map datas = new HashMap<>(); From 342c0dab7987378b9aa79f6ad09efa32e905a7dc Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 5 Aug 2023 23:04:26 +0200 Subject: [PATCH 25/78] fix the inversion --- .../pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java index e533992..113f336 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java @@ -14,7 +14,7 @@ public class SimpleBitsetProperty extends EntityPropertyImpl { private final boolean inverted; public SimpleBitsetProperty(String name, int index, int bitmask, boolean inverted) { - super(name, !inverted, Boolean.class); + super(name, inverted, Boolean.class); this.index = index; this.bitmask = bitmask; this.inverted = inverted; From 0002de3d9c4f2c29050f533f4cab4deaa2b2af63 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 5 Aug 2023 23:21:14 +0200 Subject: [PATCH 26/78] remove already implemented from comment --- .../lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 4 ---- 1 file changed, 4 deletions(-) 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 3fbe883..2510a2f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -82,10 +82,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("show_base", true); // TODO // Armor Stand - registerType("small", false); - registerType("arms", false); - registerType("base_plate", true); - registerType("head_rotation", Vector3f.zero()); registerType("body_rotation", Vector3f.zero()); registerType("left_arm_rotation", new Vector3f(-10, 0, -10)); From fb95965ae63c345a1132a9c298536a62ab832884 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 13:59:43 +0200 Subject: [PATCH 27/78] remove todo comment --- .../java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java b/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java index 70bf62f..74f4ada 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/skin/cache/MojangSkinCache.java @@ -68,7 +68,6 @@ public class MojangSkinCache { } public CompletableFuture fetchByUrl(URL url, String variant) { - return CompletableFuture.supplyAsync(() -> { URL apiUrl = parseUrl("https://api.mineskin.org/generate/url"); HttpURLConnection connection = null; @@ -80,7 +79,7 @@ public class MojangSkinCache { connection.setDoOutput(true); OutputStream outStream = connection.getOutputStream(); DataOutputStream out = new DataOutputStream(outStream); - out.writeBytes("{\"variant\":\"" + variant + "\",\"url\":\"" + url.toString() + "\"}"); // TODO: configurable variant (slim, classic) default: classic + out.writeBytes("{\"variant\":\"" + variant + "\",\"url\":\"" + url.toString() + "\"}"); out.flush(); out.close(); outStream.close(); From 1dfb5ae5418c0edf109d347e90d045b6a31b9d38 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 14:32:27 +0200 Subject: [PATCH 28/78] implement dinnerbone property --- .../entity/EntityPropertyRegistryImpl.java | 7 +++- .../entity/properties/DinnerboneProperty.java | 33 +++++++++++++++++++ .../entity/properties/NameProperty.java | 13 +++----- 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DinnerboneProperty.java 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)); } From 70e1e2d0a255be15622559f7b171db87eef45db4 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 14:50:37 +0200 Subject: [PATCH 29/78] implement skin layer properties --- .../entity/EntityPropertyRegistryImpl.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) 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 9a8d756..b62db66 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -57,8 +57,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerLevel.class); /* - registerType("dinnerbone", false); - registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation registerType("potion_color", Color.BLACK); registerType("potion_ambient", false); @@ -67,13 +65,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("pose", NpcPose.STANDING); // Player - registerType("skin_cape", true); - registerType("skin_jacket", true); - registerType("skin_left_sleeve", true); - registerType("skin_right_sleeve", true); - registerType("skin_left_leg", true); - registerType("skin_right_leg", true); - registerType("skin_hat", true); registerType("shoulder_entity_left", ParrotVariant.NONE); registerType("shoulder_entity_right", ParrotVariant.NONE); @@ -247,7 +238,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBooleanProperty("silent", 4, false, ver.isOlderThan(ServerVersion.V_1_9))); - int armorStandIndex; + final int armorStandIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandIndex = 15; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandIndex = 14; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandIndex = 13; @@ -258,6 +249,23 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBitsetProperty("base_plate", armorStandIndex, 0x08, true)); linkProperties("small", "arms", "base_plate"); + final int skinLayersIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) skinLayersIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_16)) skinLayersIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) skinLayersIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) skinLayersIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) skinLayersIndex = 12; + else skinLayersIndex = 10; + register(new SimpleBitsetProperty("skin_cape", skinLayersIndex, 0x01)); + register(new SimpleBitsetProperty("skin_jacket", skinLayersIndex, 0x02)); + register(new SimpleBitsetProperty("skin_left_sleeve", skinLayersIndex, 0x04)); + register(new SimpleBitsetProperty("skin_right_sleeve", skinLayersIndex, 0x08)); + register(new SimpleBitsetProperty("skin_left_leg", skinLayersIndex, 0x10)); + register(new SimpleBitsetProperty("skin_right_leg", skinLayersIndex, 0x20)); + register(new SimpleBitsetProperty("skin_hat", skinLayersIndex, 0x40)); + + linkProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat"); + } private void registerSerializer(PropertySerializer serializer) { From a4fc36345452b7fc57b08fcc1b81bf954c985b62 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 15:17:59 +0200 Subject: [PATCH 30/78] implement armor stand rotation properties --- .../entity/EntityPropertyRegistryImpl.java | 21 ++++++++++------ .../entity/properties/RotationProperty.java | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/RotationProperty.java 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 b62db66..ff582ba 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -72,14 +72,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("beam_target", null); // TODO: Make a block pos class for this registerType("show_base", true); // TODO - // Armor Stand - registerType("head_rotation", Vector3f.zero()); - registerType("body_rotation", Vector3f.zero()); - registerType("left_arm_rotation", new Vector3f(-10, 0, -10)); - registerType("right_arm_rotation", new Vector3f(-15, 0, 10)); - registerType("left_leg_rotation", new Vector3f(-1 , 0, -1)); - registerType("right_leg_rotation", new Vector3f(1, 0, 1)); - // Axolotl registerType("axolotl_variant", 0); registerType("playing_dead", false); // TODO fix disabling @@ -266,6 +258,19 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat"); + int armorStandRotationIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandRotationIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandRotationIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandRotationIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandRotationIndex = 12; + else armorStandRotationIndex = 11; + register(new RotationProperty("head_rotation", armorStandRotationIndex++, Vector3f.zero())); + register(new RotationProperty("body_rotation", armorStandRotationIndex++, Vector3f.zero())); + register(new RotationProperty("left_arm_rotation", armorStandRotationIndex++, new Vector3f(-10, 0, -10))); + register(new RotationProperty("right_arm_rotation", armorStandRotationIndex++, new Vector3f(-15, 0, 10))); + register(new RotationProperty("left_leg_rotation", armorStandRotationIndex++, new Vector3f(-1, 0, -1))); + register(new RotationProperty("right_leg_rotation", armorStandRotationIndex, new Vector3f(1, 0, 1))); + } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/RotationProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/RotationProperty.java new file mode 100644 index 0000000..412197d --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/RotationProperty.java @@ -0,0 +1,25 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.util.Vector3f; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class RotationProperty extends EntityPropertyImpl { + private final int index; + + public RotationProperty(String name, int index, Vector3f defaultValue) { + super(name, defaultValue, Vector3f.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + Vector3f vec = entity.getProperty(this); + properties.put(index, newEntityData(index, EntityDataTypes.ROTATION, new com.github.retrooper.packetevents.util.Vector3f(vec.getX(), vec.getY(), vec.getZ()))); + } +} From 923926b0b4256d2d28b41702f3751db3a3840ab3 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 15:18:26 +0200 Subject: [PATCH 31/78] delete already reimplemented properties from the deprecated meta factories --- .../znpcsplus/metadata/MetadataFactory.java | 21 ++----- .../metadata/V1_10MetadataFactory.java | 40 ------------ .../metadata/V1_13MetadataFactory.java | 8 --- .../metadata/V1_14MetadataFactory.java | 40 ------------ .../metadata/V1_15MetadataFactory.java | 36 ----------- .../metadata/V1_16MetadataFactory.java | 4 -- .../metadata/V1_17MetadataFactory.java | 45 -------------- .../metadata/V1_8MetadataFactory.java | 61 ------------------- .../metadata/V1_9MetadataFactory.java | 32 ---------- 9 files changed, 4 insertions(+), 283 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 4d8619a..bb6857d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -2,8 +2,9 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; -import lol.pyr.znpcsplus.util.*; -import net.kyori.adventure.text.Component; +import lol.pyr.znpcsplus.util.CatVariant; +import lol.pyr.znpcsplus.util.CreeperState; +import lol.pyr.znpcsplus.util.ParrotVariant; import org.bukkit.DyeColor; /** @@ -22,10 +23,7 @@ import org.bukkit.DyeColor; */ @Deprecated public interface MetadataFactory { - EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean usingItemLegacy); - EntityData silent(boolean enabled); - EntityData name(Component name); - EntityData nameShown(); + EntityData noGravity(); EntityData pose(EntityPose pose); EntityData shaking(boolean enabled); @@ -33,20 +31,9 @@ public interface MetadataFactory { EntityData potionColor(int color); EntityData potionAmbient(boolean ambient); - // Player - EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat); EntityData shoulderEntityLeft(ParrotVariant variant); EntityData shoulderEntityRight(ParrotVariant variant); - // Armor Stand - EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate); - EntityData armorStandHeadRotation(Vector3f headRotation); - EntityData armorStandBodyRotation(Vector3f bodyRotation); - EntityData armorStandLeftArmRotation(Vector3f leftArmRotation); - EntityData armorStandRightArmRotation(Vector3f rightArmRotation); - EntityData armorStandLeftLegRotation(Vector3f leftLegRotation); - EntityData armorStandRightLegRotation(Vector3f rightLegRotation); - // Axolotl EntityData axolotlVariant(int variant); EntityData playingDead(boolean playingDead); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java index 8c136c5..e6af8b5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java @@ -3,14 +3,9 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import lol.pyr.znpcsplus.util.CreeperState; -import lol.pyr.znpcsplus.util.Vector3f; @Deprecated public class V1_10MetadataFactory extends V1_9MetadataFactory { - @Override - public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return createSkinLayers(13, cape, jacket, leftSleeve, rightSleeve, leftLeg, rightLeg, hat); - } @Override public EntityData noGravity() { @@ -27,41 +22,6 @@ public class V1_10MetadataFactory extends V1_9MetadataFactory { return newEntityData(9, EntityDataTypes.BOOLEAN, ambient); } - @Override - public EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate) { - return newEntityData(11, EntityDataTypes.BYTE, (byte) ((small ? 0x01 : 0) | (arms ? 0x04 : 0) | (noBasePlate ? 0x08 : 0))); - } - - @Override - public EntityData armorStandHeadRotation(Vector3f headRotation) { - return createRotations(12, headRotation); - } - - @Override - public EntityData armorStandBodyRotation(Vector3f bodyRotation) { - return createRotations(13, bodyRotation); - } - - @Override - public EntityData armorStandLeftArmRotation(Vector3f leftArmRotation) { - return createRotations(14, leftArmRotation); - } - - @Override - public EntityData armorStandRightArmRotation(Vector3f rightArmRotation) { - return createRotations(15, rightArmRotation); - } - - @Override - public EntityData armorStandLeftLegRotation(Vector3f leftLegRotation) { - return createRotations(16, leftLegRotation); - } - - @Override - public EntityData armorStandRightLegRotation(Vector3f rightLegRotation) { - return createRotations(17, rightLegRotation); - } - @Override public EntityData batHanging(boolean hanging) { return newEntityData(12, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java index 7d3b266..6f127a6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java @@ -2,17 +2,9 @@ package lol.pyr.znpcsplus.metadata; 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; -import net.kyori.adventure.text.Component; - -import java.util.Optional; @Deprecated public class V1_13MetadataFactory extends V1_12MetadataFactory { - @Override - public EntityData name(Component name) { - return newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(AdventureSerializer.getGsonSerializer().serialize(name))); - } @Override public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index ac7bf09..b2626b5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -7,15 +7,10 @@ import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import lol.pyr.znpcsplus.util.Vector3f; import org.bukkit.DyeColor; @Deprecated public class V1_14MetadataFactory extends V1_13MetadataFactory { - @Override - public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return createSkinLayers(15, cape, jacket, leftSleeve, rightSleeve, leftLeg, rightLeg, hat); - } @Override public EntityData pose(EntityPose pose) { @@ -47,41 +42,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory { return createShoulderEntityRight(18, variant); } - @Override - public EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate) { - return newEntityData(13, EntityDataTypes.BYTE, (byte) ((small ? 0x01 : 0) | (arms ? 0x04 : 0) | (noBasePlate ? 0x08 : 0))); - } - - @Override - public EntityData armorStandHeadRotation(Vector3f headRotation) { - return createRotations(14, headRotation); - } - - @Override - public EntityData armorStandBodyRotation(Vector3f bodyRotation) { - return createRotations(15, bodyRotation); - } - - @Override - public EntityData armorStandLeftArmRotation(Vector3f leftArmRotation) { - return createRotations(16, leftArmRotation); - } - - @Override - public EntityData armorStandRightArmRotation(Vector3f rightArmRotation) { - return createRotations(17, rightArmRotation); - } - - @Override - public EntityData armorStandLeftLegRotation(Vector3f leftLegRotation) { - return createRotations(18, leftLegRotation); - } - - @Override - public EntityData armorStandRightLegRotation(Vector3f rightLegRotation) { - return createRotations(19, rightLegRotation); - } - @Override public EntityData batHanging(boolean hanging) { return newEntityData(14, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java index 93a1461..3cb5264 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java @@ -6,7 +6,6 @@ import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import lol.pyr.znpcsplus.util.Vector3f; import org.bukkit.DyeColor; @Deprecated @@ -21,41 +20,6 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory { return createShoulderEntityRight(19, variant); } - @Override - public EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate) { - return newEntityData(14, EntityDataTypes.BYTE, (byte) ((small ? 0x01 : 0) | (arms ? 0x04 : 0) | (!noBasePlate ? 0x08 : 0))); - } - - @Override - public EntityData armorStandHeadRotation(Vector3f headRotation) { - return createRotations(15, headRotation); - } - - @Override - public EntityData armorStandBodyRotation(Vector3f bodyRotation) { - return createRotations(16, bodyRotation); - } - - @Override - public EntityData armorStandLeftArmRotation(Vector3f leftArmRotation) { - return createRotations(17, leftArmRotation); - } - - @Override - public EntityData armorStandRightArmRotation(Vector3f rightArmRotation) { - return createRotations(18, rightArmRotation); - } - - @Override - public EntityData armorStandLeftLegRotation(Vector3f leftLegRotation) { - return createRotations(19, leftLegRotation); - } - - @Override - public EntityData armorStandRightLegRotation(Vector3f rightLegRotation) { - return createRotations(20, rightLegRotation); - } - @Override public EntityData batHanging(boolean hanging) { return newEntityData(15, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java index d3862f3..924efb7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java @@ -5,10 +5,6 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; @Deprecated public class V1_16MetadataFactory extends V1_15MetadataFactory { - @Override - public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return createSkinLayers(16, cape, jacket, leftSleeve, rightSleeve, leftLeg, rightLeg, hat); - } @Override public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index c76536c..4ba29b7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -6,20 +6,10 @@ import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import lol.pyr.znpcsplus.util.Vector3f; import org.bukkit.DyeColor; @Deprecated public class V1_17MetadataFactory extends V1_16MetadataFactory { - @Override - public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return createSkinLayers(17, cape, jacket, leftSleeve, rightSleeve, leftLeg, rightLeg, hat); - } - - @Override - public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean usingItemLegacy) { - return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0) | (usingElytra ? 0x80 : 0))); - } @Override public EntityData shaking(boolean enabled) { @@ -51,41 +41,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return createShoulderEntityRight(20, variant); } - @Override - public EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate) { - return newEntityData(15, EntityDataTypes.BYTE, (byte) ((small ? 0x01 : 0) | (arms ? 0x04 : 0) | (noBasePlate ? 0x08 : 0))); - } - - @Override - public EntityData armorStandHeadRotation(Vector3f headRotation) { - return createRotations(16, headRotation); - } - - @Override - public EntityData armorStandBodyRotation(Vector3f bodyRotation) { - return createRotations(17, bodyRotation); - } - - @Override - public EntityData armorStandLeftArmRotation(Vector3f leftArmRotation) { - return createRotations(18, leftArmRotation); - } - - @Override - public EntityData armorStandRightArmRotation(Vector3f rightArmRotation) { - return createRotations(19, rightArmRotation); - } - - @Override - public EntityData armorStandLeftLegRotation(Vector3f leftLegRotation) { - return createRotations(20, leftLegRotation); - } - - @Override - public EntityData armorStandRightLegRotation(Vector3f rightLegRotation) { - return createRotations(21, rightLegRotation); - } - @Override public EntityData axolotlVariant(int variant) { return newEntityData(17, EntityDataTypes.INT, variant); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 7a86c1d..46e046f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -4,32 +4,11 @@ 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.protocol.entity.pose.EntityPose; -import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; import lol.pyr.znpcsplus.util.*; -import net.kyori.adventure.text.Component; import org.bukkit.DyeColor; @Deprecated public class V1_8MetadataFactory implements MetadataFactory { - @Override - public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return createSkinLayers(10, cape, jacket, leftSleeve, rightSleeve, leftLeg, rightLeg, hat); - } - - @Override - public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean usingItemLegacy) { - return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (usingItemLegacy ? 0x10 : 0) | (invisible ? 0x20 : 0))); - } - - @Override - public EntityData name(Component name) { - return newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getLegacyGsonSerializer().serialize(name)); - } - - @Override - public EntityData nameShown() { - return newEntityData(3, EntityDataTypes.BYTE, (byte) 1); - } @Override public EntityData noGravity() { @@ -71,41 +50,6 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The shoulder entity data isn't supported on this version"); } - @Override - public EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate) { - return newEntityData(10, EntityDataTypes.BYTE, (byte) ((small ? 0x01 : 0) | (arms ? 0x04 : 0) | (noBasePlate ? 0x08 : 0))); - } - - @Override - public EntityData armorStandHeadRotation(Vector3f headRotation) { - return createRotations(11, headRotation); - } - - @Override - public EntityData armorStandBodyRotation(Vector3f bodyRotation) { - return createRotations(12, bodyRotation); - } - - @Override - public EntityData armorStandLeftArmRotation(Vector3f leftArmRotation) { - return createRotations(13, leftArmRotation); - } - - @Override - public EntityData armorStandRightArmRotation(Vector3f rightArmRotation) { - return createRotations(14, rightArmRotation); - } - - @Override - public EntityData armorStandLeftLegRotation(Vector3f leftLegRotation) { - return createRotations(15, leftLegRotation); - } - - @Override - public EntityData armorStandRightLegRotation(Vector3f rightLegRotation) { - return createRotations(16, rightLegRotation); - } - @Override public EntityData axolotlVariant(int variant) { throw new UnsupportedOperationException("The axolotl variant entity data isn't supported on this version"); @@ -226,11 +170,6 @@ public class V1_8MetadataFactory implements MetadataFactory { return newEntityData(16, EntityDataTypes.INT, profession); } - @Override - public EntityData silent(boolean enabled) { - return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0)); - } - protected EntityData createSkinLayers(int index, boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { return newEntityData(index, EntityDataTypes.BYTE, (byte) ( (cape ? 0x01 : 0) | diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java index 433d1c8..33e5d75 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java @@ -2,27 +2,10 @@ package lol.pyr.znpcsplus.metadata; 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; import lol.pyr.znpcsplus.util.CreeperState; -import net.kyori.adventure.text.Component; @Deprecated public class V1_9MetadataFactory extends V1_8MetadataFactory { - @Override - public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return createSkinLayers(12, cape, jacket, leftSleeve, rightSleeve, leftLeg, rightLeg, hat); - } - - @Override - public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean usingItemLegacy) { - return newEntityData(0, EntityDataTypes.BYTE, (byte) ( - (onFire ? 0x01 : 0) | - (usingItemLegacy ? 0x10 : 0) | - (invisible ? 0x20 : 0) | - (glowing ? 0x40 : 0) | - (usingElytra ? 0x80 : 0) - )); - } @Override public EntityData potionAmbient(boolean ambient) { @@ -49,21 +32,6 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory { return newEntityData(12, EntityDataTypes.BOOLEAN, charged); } - @Override - public EntityData name(Component name) { - return newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)); - } - - @Override - public EntityData nameShown() { - return newEntityData(3, EntityDataTypes.BOOLEAN, true); - } - - @Override - public EntityData silent(boolean enabled) { - return newEntityData(4, EntityDataTypes.BOOLEAN, enabled); - } - @Override public EntityData ghastAttacking(boolean attacking) { return newEntityData(11, EntityDataTypes.BOOLEAN, attacking); From 83b654fd76a6b2a2016484dc3ae2e1f7c91022d1 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 15:27:00 +0200 Subject: [PATCH 32/78] ghast attacking property --- .../entity/EntityPropertyRegistryImpl.java | 14 ++++++++++---- .../pyr/znpcsplus/metadata/MetadataFactory.java | 5 ----- .../znpcsplus/metadata/V1_10MetadataFactory.java | 5 ----- .../znpcsplus/metadata/V1_14MetadataFactory.java | 5 ----- .../znpcsplus/metadata/V1_15MetadataFactory.java | 5 ----- .../znpcsplus/metadata/V1_17MetadataFactory.java | 5 ----- .../znpcsplus/metadata/V1_8MetadataFactory.java | 5 ----- .../znpcsplus/metadata/V1_9MetadataFactory.java | 5 ----- 8 files changed, 10 insertions(+), 39 deletions(-) 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 ff582ba..1d9e930 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -113,9 +113,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Frog registerType("frog_variant", FrogVariant.TEMPERATE); - // Ghast - registerType("attacking", false); - // Guardian registerType("is_elder", false); // TODO: ensure it only works till 1.10. Note: index is wrong on wiki.vg @@ -207,6 +204,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { public void registerTypes(PacketFactory packetFactory) { ServerVersion ver = PacketEvents.getAPI().getServerManager().getVersion(); + boolean legacyBooleans = ver.isOlderThan(ServerVersion.V_1_9); register(new EquipmentProperty(packetFactory, "helmet", EquipmentSlot.HELMET)); register(new EquipmentProperty(packetFactory, "chestplate", EquipmentSlot.CHEST_PLATE)); @@ -228,7 +226,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBitsetProperty("invisible", 0, 0x20)); linkProperties("glow", "fire", "invisible"); - register(new SimpleBooleanProperty("silent", 4, false, ver.isOlderThan(ServerVersion.V_1_9))); + register(new SimpleBooleanProperty("silent", 4, false, legacyBooleans)); final int armorStandIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandIndex = 15; @@ -271,6 +269,14 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new RotationProperty("left_leg_rotation", armorStandRotationIndex++, new Vector3f(-1, 0, -1))); register(new RotationProperty("right_leg_rotation", armorStandRotationIndex, new Vector3f(1, 0, 1))); + final int ghastAttackingIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) ghastAttackingIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) ghastAttackingIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) ghastAttackingIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) ghastAttackingIndex = 12; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) ghastAttackingIndex = 11; + else ghastAttackingIndex = 16; + register(new SimpleBooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index bb6857d..1f0035c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -73,15 +73,10 @@ public interface MetadataFactory { // Frog EntityData frogVariant(int variant); - // Ghast - EntityData ghastAttacking(boolean attacking); - // Goat EntityData goatHasLeftHorn(boolean hasLeftHorn); EntityData goatHasRightHorn(boolean hasRightHorn); - // Guardian - // Hoglin EntityData hoglinImmuneToZombification(boolean immuneToZombification); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java index e6af8b5..aaabeb8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java @@ -42,11 +42,6 @@ public class V1_10MetadataFactory extends V1_9MetadataFactory { return newEntityData(13, EntityDataTypes.BOOLEAN, charged); } - @Override - public EntityData ghastAttacking(boolean attacking) { - return newEntityData(12, EntityDataTypes.BOOLEAN, attacking); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(13, EntityDataTypes.INT, profession); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index b2626b5..076fc97 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -92,11 +92,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory { return newEntityData(16, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0))); } - @Override - public EntityData ghastAttacking(boolean attacking) { - return newEntityData(14, EntityDataTypes.BOOLEAN, attacking); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(16, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java index 3cb5264..6652a0a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java @@ -80,11 +80,6 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory { return newEntityData(17, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0))); } - @Override - public EntityData ghastAttacking(boolean attacking) { - return newEntityData(15, EntityDataTypes.BOOLEAN, attacking); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(17, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index 4ba29b7..ae9fc1f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -131,11 +131,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return newEntityData(18, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0))); } - @Override - public EntityData ghastAttacking(boolean attacking) { - return newEntityData(16, EntityDataTypes.BOOLEAN, attacking); - } - @Override public EntityData goatHasLeftHorn(boolean hasLeftHorn) { return newEntityData(18, EntityDataTypes.BOOLEAN, hasLeftHorn); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 46e046f..36f2149 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -145,11 +145,6 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The frog variant entity data isn't supported on this version"); } - @Override - public EntityData ghastAttacking(boolean attacking) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (attacking ? 1 : 0)); - } - @Override public EntityData goatHasLeftHorn(boolean hasLeftHorn) { throw new UnsupportedOperationException("The goat horn entity data isn't supported on this version"); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java index 33e5d75..37091df 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java @@ -32,11 +32,6 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory { return newEntityData(12, EntityDataTypes.BOOLEAN, charged); } - @Override - public EntityData ghastAttacking(boolean attacking) { - return newEntityData(11, EntityDataTypes.BOOLEAN, attacking); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(12, EntityDataTypes.INT, profession); From a3a0c409e63566287b7a16bfae67f0c57f9f56fd Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 15:36:03 +0200 Subject: [PATCH 33/78] goat horn properties --- .../entity/EntityPropertyRegistryImpl.java | 47 ++++++++++--------- .../znpcsplus/metadata/MetadataFactory.java | 4 -- .../metadata/V1_17MetadataFactory.java | 10 ---- .../metadata/V1_8MetadataFactory.java | 10 ---- 4 files changed, 24 insertions(+), 47 deletions(-) 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 1d9e930..ebfc03c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -228,17 +228,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBooleanProperty("silent", 4, false, legacyBooleans)); - final int armorStandIndex; - if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandIndex = 15; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandIndex = 14; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandIndex = 13; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandIndex = 11; - else armorStandIndex = 10; - register(new SimpleBitsetProperty("small", armorStandIndex, 0x01)); - register(new SimpleBitsetProperty("arms", armorStandIndex, 0x04)); - register(new SimpleBitsetProperty("base_plate", armorStandIndex, 0x08, true)); - linkProperties("small", "arms", "base_plate"); - final int skinLayersIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) skinLayersIndex = 17; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_16)) skinLayersIndex = 16; @@ -256,19 +245,25 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat"); - int armorStandRotationIndex; - if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandRotationIndex = 16; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandRotationIndex = 15; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandRotationIndex = 14; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandRotationIndex = 12; - else armorStandRotationIndex = 11; - register(new RotationProperty("head_rotation", armorStandRotationIndex++, Vector3f.zero())); - register(new RotationProperty("body_rotation", armorStandRotationIndex++, Vector3f.zero())); - register(new RotationProperty("left_arm_rotation", armorStandRotationIndex++, new Vector3f(-10, 0, -10))); - register(new RotationProperty("right_arm_rotation", armorStandRotationIndex++, new Vector3f(-15, 0, 10))); - register(new RotationProperty("left_leg_rotation", armorStandRotationIndex++, new Vector3f(-1, 0, -1))); - register(new RotationProperty("right_leg_rotation", armorStandRotationIndex, new Vector3f(1, 0, 1))); + // Armor Stand + int armorStandIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) armorStandIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) armorStandIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandIndex = 11; + else armorStandIndex = 10; + register(new SimpleBitsetProperty("small", armorStandIndex, 0x01)); + register(new SimpleBitsetProperty("arms", armorStandIndex, 0x04)); + register(new SimpleBitsetProperty("base_plate", armorStandIndex++, 0x08, true)); + register(new RotationProperty("head_rotation", armorStandIndex++, Vector3f.zero())); + register(new RotationProperty("body_rotation", armorStandIndex++, Vector3f.zero())); + register(new RotationProperty("left_arm_rotation", armorStandIndex++, new Vector3f(-10, 0, -10))); + register(new RotationProperty("right_arm_rotation", armorStandIndex++, new Vector3f(-15, 0, 10))); + register(new RotationProperty("left_leg_rotation", armorStandIndex++, new Vector3f(-1, 0, -1))); + register(new RotationProperty("right_leg_rotation", armorStandIndex, new Vector3f(1, 0, 1))); + linkProperties("small", "arms", "base_plate"); + // Ghast final int ghastAttackingIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) ghastAttackingIndex = 16; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) ghastAttackingIndex = 15; @@ -277,6 +272,12 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) ghastAttackingIndex = 11; else ghastAttackingIndex = 16; register(new SimpleBooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); + + // Goat + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) { + register(new SimpleBooleanProperty("has_left_horn", 18, true, legacyBooleans)); + register(new SimpleBooleanProperty("has_right_horn", 19, true, legacyBooleans)); + } } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 1f0035c..1e888cb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -73,10 +73,6 @@ public interface MetadataFactory { // Frog EntityData frogVariant(int variant); - // Goat - EntityData goatHasLeftHorn(boolean hasLeftHorn); - EntityData goatHasRightHorn(boolean hasRightHorn); - // Hoglin EntityData hoglinImmuneToZombification(boolean immuneToZombification); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index ae9fc1f..dbd7068 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -131,16 +131,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return newEntityData(18, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0))); } - @Override - public EntityData goatHasLeftHorn(boolean hasLeftHorn) { - return newEntityData(18, EntityDataTypes.BOOLEAN, hasLeftHorn); - } - - @Override - public EntityData goatHasRightHorn(boolean hasRightHorn) { - return newEntityData(19, EntityDataTypes.BOOLEAN, hasRightHorn); - } - @Override public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { return newEntityData(17, EntityDataTypes.BOOLEAN, immuneToZombification); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 36f2149..5c6522e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -145,16 +145,6 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The frog variant entity data isn't supported on this version"); } - @Override - public EntityData goatHasLeftHorn(boolean hasLeftHorn) { - throw new UnsupportedOperationException("The goat horn entity data isn't supported on this version"); - } - - @Override - public EntityData goatHasRightHorn(boolean hasRightHorn) { - throw new UnsupportedOperationException("The goat horn entity data isn't supported on this version"); - } - @Override public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { throw new UnsupportedOperationException("The hoglin zombification entity data isn't supported on this version"); From 1150a028cb9ce8fe14ac61d585f3504e40a1e615 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 19:59:15 +0200 Subject: [PATCH 34/78] remove goat properties from comment --- .../pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 6 ------ 1 file changed, 6 deletions(-) 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 02abda9..54d826e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -184,10 +184,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("piglin_dancing", false); // TODO registerType("piglin_charging_crossbow", false); // TODO - // Goat - registerType("has_left_horn", true); - registerType("has_right_horn", true); - // Vindicator registerType("celebrating", false); // TODO @@ -226,7 +222,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBitsetProperty("invisible", 0, 0x20)); register(new HoloItemProperty()); linkProperties("glow", "fire", "invisible"); - register(new SimpleBooleanProperty("silent", 4, false, legacyBooleans)); final int skinLayersIndex; @@ -243,7 +238,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new SimpleBitsetProperty("skin_left_leg", skinLayersIndex, 0x10)); register(new SimpleBitsetProperty("skin_right_leg", skinLayersIndex, 0x20)); register(new SimpleBitsetProperty("skin_hat", skinLayersIndex, 0x40)); - linkProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat"); // Armor Stand From 8ad3cb73fd6808a720fa92330df8adc7d97dcf5f Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 20:04:48 +0200 Subject: [PATCH 35/78] make the naming consistent --- .../entity/EntityPropertyRegistryImpl.java | 32 +++++++++---------- ...itsetProperty.java => BitsetProperty.java} | 6 ++-- ...leanProperty.java => BooleanProperty.java} | 4 +-- 3 files changed, 21 insertions(+), 21 deletions(-) rename plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/{SimpleBitsetProperty.java => BitsetProperty.java} (82%) rename plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/{SimpleBooleanProperty.java => BooleanProperty.java} (84%) 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 54d826e..af60ea9 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -218,11 +218,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new DummyProperty<>("skin", SkinDescriptor.class, false)); register(new GlowProperty(packetFactory)); - register(new SimpleBitsetProperty("fire", 0, 0x01)); - register(new SimpleBitsetProperty("invisible", 0, 0x20)); + register(new BitsetProperty("fire", 0, 0x01)); + register(new BitsetProperty("invisible", 0, 0x20)); register(new HoloItemProperty()); linkProperties("glow", "fire", "invisible"); - register(new SimpleBooleanProperty("silent", 4, false, legacyBooleans)); + register(new BooleanProperty("silent", 4, false, legacyBooleans)); final int skinLayersIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) skinLayersIndex = 17; @@ -231,13 +231,13 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) skinLayersIndex = 13; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) skinLayersIndex = 12; else skinLayersIndex = 10; - register(new SimpleBitsetProperty("skin_cape", skinLayersIndex, 0x01)); - register(new SimpleBitsetProperty("skin_jacket", skinLayersIndex, 0x02)); - register(new SimpleBitsetProperty("skin_left_sleeve", skinLayersIndex, 0x04)); - register(new SimpleBitsetProperty("skin_right_sleeve", skinLayersIndex, 0x08)); - register(new SimpleBitsetProperty("skin_left_leg", skinLayersIndex, 0x10)); - register(new SimpleBitsetProperty("skin_right_leg", skinLayersIndex, 0x20)); - register(new SimpleBitsetProperty("skin_hat", skinLayersIndex, 0x40)); + register(new BitsetProperty("skin_cape", skinLayersIndex, 0x01)); + register(new BitsetProperty("skin_jacket", skinLayersIndex, 0x02)); + register(new BitsetProperty("skin_left_sleeve", skinLayersIndex, 0x04)); + register(new BitsetProperty("skin_right_sleeve", skinLayersIndex, 0x08)); + register(new BitsetProperty("skin_left_leg", skinLayersIndex, 0x10)); + register(new BitsetProperty("skin_right_leg", skinLayersIndex, 0x20)); + register(new BitsetProperty("skin_hat", skinLayersIndex, 0x40)); linkProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat"); // Armor Stand @@ -247,9 +247,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) armorStandIndex = 13; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) armorStandIndex = 11; else armorStandIndex = 10; - register(new SimpleBitsetProperty("small", armorStandIndex, 0x01)); - register(new SimpleBitsetProperty("arms", armorStandIndex, 0x04)); - register(new SimpleBitsetProperty("base_plate", armorStandIndex++, 0x08, true)); + register(new BitsetProperty("small", armorStandIndex, 0x01)); + register(new BitsetProperty("arms", armorStandIndex, 0x04)); + register(new BitsetProperty("base_plate", armorStandIndex++, 0x08, true)); register(new RotationProperty("head_rotation", armorStandIndex++, Vector3f.zero())); register(new RotationProperty("body_rotation", armorStandIndex++, Vector3f.zero())); register(new RotationProperty("left_arm_rotation", armorStandIndex++, new Vector3f(-10, 0, -10))); @@ -266,12 +266,12 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) ghastAttackingIndex = 12; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) ghastAttackingIndex = 11; else ghastAttackingIndex = 16; - register(new SimpleBooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); + register(new BooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); // Goat if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) { - register(new SimpleBooleanProperty("has_left_horn", 18, true, legacyBooleans)); - register(new SimpleBooleanProperty("has_right_horn", 19, true, legacyBooleans)); + register(new BooleanProperty("has_left_horn", 18, true, legacyBooleans)); + register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java similarity index 82% rename from plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java rename to plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java index 113f336..579074e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBitsetProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java @@ -8,19 +8,19 @@ import org.bukkit.entity.Player; import java.util.Map; -public class SimpleBitsetProperty extends EntityPropertyImpl { +public class BitsetProperty extends EntityPropertyImpl { private final int index; private final int bitmask; private final boolean inverted; - public SimpleBitsetProperty(String name, int index, int bitmask, boolean inverted) { + public BitsetProperty(String name, int index, int bitmask, boolean inverted) { super(name, inverted, Boolean.class); this.index = index; this.bitmask = bitmask; this.inverted = inverted; } - public SimpleBitsetProperty(String name, int index, int bitmask) { + public BitsetProperty(String name, int index, int bitmask) { this(name, index, bitmask, false); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java similarity index 84% rename from plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java rename to plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java index 763b0a9..d04360c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SimpleBooleanProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java @@ -8,11 +8,11 @@ import org.bukkit.entity.Player; import java.util.Map; -public class SimpleBooleanProperty extends EntityPropertyImpl { +public class BooleanProperty extends EntityPropertyImpl { private final int index; private final boolean legacy; - public SimpleBooleanProperty(String name, int index, boolean defaultValue, boolean legacy) { + public BooleanProperty(String name, int index, boolean defaultValue, boolean legacy) { super(name, defaultValue, Boolean.class); this.index = index; this.legacy = legacy; From 0f6a953a5eadfd3f3f364360f29ca5c5beece02f Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 20:11:44 +0200 Subject: [PATCH 36/78] implement potion_color and potion_ambient --- .../entity/EntityPropertyRegistryImpl.java | 16 +++++++++--- .../entity/properties/ColorProperty.java | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java 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 af60ea9..ce2cc66 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -58,8 +58,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerLevel.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation - registerType("potion_color", Color.BLACK); - registerType("potion_ambient", false); + registerType("shaking", false); registerType("baby", false); // TODO registerType("pose", NpcPose.STANDING); @@ -215,7 +214,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new DinnerboneProperty(legacyName, optionalComponent)); register(new DummyProperty<>("look", false)); - register(new DummyProperty<>("skin", SkinDescriptor.class, false)); register(new GlowProperty(packetFactory)); register(new BitsetProperty("fire", 0, 0x01)); @@ -224,6 +222,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("glow", "fire", "invisible"); register(new BooleanProperty("silent", 4, false, legacyBooleans)); + int potionIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) potionIndex = 10; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) potionIndex = 9; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) potionIndex = 8; + else potionIndex = 7; + register(new ColorProperty("potion_color", potionIndex++, null)); + register(new BooleanProperty("potion_ambient", potionIndex, false, legacyBooleans)); + + // Player + register(new DummyProperty<>("skin", SkinDescriptor.class, false)); final int skinLayersIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) skinLayersIndex = 17; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_16)) skinLayersIndex = 16; @@ -273,6 +281,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BooleanProperty("has_left_horn", 18, true, legacyBooleans)); register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); } + + } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java new file mode 100644 index 0000000..87ccee6 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java @@ -0,0 +1,26 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.Color; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class ColorProperty extends EntityPropertyImpl { + private final int index; + + public ColorProperty(String name, int index, Color def) { + super(name, def, Color.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + Color color = entity.getProperty(this); + if (color == null) return; + properties.put(index, newEntityData(index, EntityDataTypes.INT, color.asRGB())); + } +} From 84fa7eb2c93e0d82179fa6f3f74ec45a5fca4ac9 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 20:27:01 +0200 Subject: [PATCH 37/78] implement shaking property --- .../entity/EntityPropertyRegistryImpl.java | 19 ++++++++------- .../entity/properties/BooleanProperty.java | 12 ++++++++-- .../entity/properties/IntegerProperty.java | 23 +++++++++++++++++++ .../entity/properties/ShakingProperty.java | 23 +++++++++++++++++++ .../znpcsplus/metadata/MetadataFactory.java | 4 +--- .../metadata/V1_10MetadataFactory.java | 10 -------- .../metadata/V1_14MetadataFactory.java | 10 -------- .../metadata/V1_17MetadataFactory.java | 15 ------------ .../metadata/V1_8MetadataFactory.java | 15 ------------ .../metadata/V1_9MetadataFactory.java | 5 ---- 10 files changed, 66 insertions(+), 70 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java 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 ce2cc66..d9c3694 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -200,6 +200,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { public void registerTypes(PacketFactory packetFactory) { ServerVersion ver = PacketEvents.getAPI().getServerManager().getVersion(); boolean legacyBooleans = ver.isOlderThan(ServerVersion.V_1_9); + boolean legacyNames = ver.isOlderThan(ServerVersion.V_1_9); + boolean optionalComponents = ver.isNewerThanOrEquals(ServerVersion.V_1_13); register(new EquipmentProperty(packetFactory, "helmet", EquipmentSlot.HELMET)); register(new EquipmentProperty(packetFactory, "chestplate", EquipmentSlot.CHEST_PLATE)); @@ -208,13 +210,10 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EquipmentProperty(packetFactory, "hand", EquipmentSlot.MAIN_HAND)); register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_HAND)); - 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 NameProperty(legacyNames, optionalComponents)); + register(new DinnerboneProperty(legacyNames, optionalComponents)); register(new DummyProperty<>("look", false)); - register(new GlowProperty(packetFactory)); register(new BitsetProperty("fire", 0, 0x01)); register(new BitsetProperty("invisible", 0, 0x20)); @@ -276,13 +275,13 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else ghastAttackingIndex = 16; register(new BooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; + // Goat - if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) { - register(new BooleanProperty("has_left_horn", 18, true, legacyBooleans)); - register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); - } - + register(new BooleanProperty("has_left_horn", 18, true, legacyBooleans)); + register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); + register(new ShakingProperty(7)); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java index d04360c..2355e56 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java @@ -11,16 +11,24 @@ import java.util.Map; public class BooleanProperty extends EntityPropertyImpl { private final int index; private final boolean legacy; + private final boolean inverted; public BooleanProperty(String name, int index, boolean defaultValue, boolean legacy) { + this(name, index, defaultValue, legacy, false); + } + + public BooleanProperty(String name, int index, boolean defaultValue, boolean legacy, boolean inverted) { super(name, defaultValue, Boolean.class); this.index = index; this.legacy = legacy; + this.inverted = inverted; } @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - if (legacy) properties.put(index, new EntityData(index, EntityDataTypes.BYTE, (entity.getProperty(this) ? 1 : 0))); - else properties.put(index, new EntityData(index, EntityDataTypes.BOOLEAN, entity.getProperty(this))); + boolean enabled = entity.getProperty(this); + if (inverted) enabled = !enabled; + if (legacy) properties.put(index, new EntityData(index, EntityDataTypes.BYTE, (enabled ? 1 : 0))); + else properties.put(index, new EntityData(index, EntityDataTypes.BOOLEAN, enabled)); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java new file mode 100644 index 0000000..2fe1c35 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java @@ -0,0 +1,23 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class IntegerProperty extends EntityPropertyImpl { + private final int index; + + protected IntegerProperty(String name, int index, Integer defaultValue) { + super(name, defaultValue, Integer.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + properties.put(index, newEntityData(index, EntityDataTypes.INT, entity.getProperty(this))); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java new file mode 100644 index 0000000..3d9266a --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java @@ -0,0 +1,23 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class ShakingProperty extends EntityPropertyImpl { + private final int index; + + public ShakingProperty(int index) { + super("shaking", false, Boolean.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + properties.put(index, newEntityData(index, EntityDataTypes.INT, entity.getProperty(this) ? 140 : 0)); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 1e888cb..843fb5a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -26,10 +26,8 @@ public interface MetadataFactory { EntityData noGravity(); EntityData pose(EntityPose pose); - EntityData shaking(boolean enabled); + EntityData usingItem(boolean enabled, boolean offhand, boolean riptide); - EntityData potionColor(int color); - EntityData potionAmbient(boolean ambient); EntityData shoulderEntityLeft(ParrotVariant variant); EntityData shoulderEntityRight(ParrotVariant variant); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java index aaabeb8..2358af9 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java @@ -12,16 +12,6 @@ public class V1_10MetadataFactory extends V1_9MetadataFactory { return newEntityData(5, EntityDataTypes.BOOLEAN, true); } - @Override - public EntityData potionColor(int color) { - return newEntityData(8, EntityDataTypes.INT, color); - } - - @Override - public EntityData potionAmbient(boolean ambient) { - return newEntityData(9, EntityDataTypes.BOOLEAN, ambient); - } - @Override public EntityData batHanging(boolean hanging) { return newEntityData(12, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index 076fc97..edfb880 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -22,16 +22,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory { return newEntityData(7, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0) | (riptide ? 0x04 : 0))); } - @Override - public EntityData potionColor(int color) { - return newEntityData(9, EntityDataTypes.INT, color); - } - - @Override - public EntityData potionAmbient(boolean ambient) { - return newEntityData(10, EntityDataTypes.BOOLEAN, ambient); - } - @Override public EntityData shoulderEntityLeft(ParrotVariant variant) { return createShoulderEntityLeft(17, variant); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index dbd7068..c7bc061 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -11,26 +11,11 @@ import org.bukkit.DyeColor; @Deprecated public class V1_17MetadataFactory extends V1_16MetadataFactory { - @Override - public EntityData shaking(boolean enabled) { - return newEntityData(7, EntityDataTypes.INT, enabled ? 140 : 0); - } - @Override public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { return newEntityData(8, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0) | (riptide ? 0x04 : 0))); } - @Override - public EntityData potionColor(int color) { - return newEntityData(10, EntityDataTypes.INT, color); - } - - @Override - public EntityData potionAmbient(boolean ambient) { - return newEntityData(11, EntityDataTypes.BOOLEAN, ambient); - } - @Override public EntityData shoulderEntityLeft(ParrotVariant variant) { return createShoulderEntityLeft(19, variant); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 5c6522e..da25b5d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -20,26 +20,11 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The pose entity data isn't supported on this version"); } - @Override - public EntityData shaking(boolean enabled) { - throw new UnsupportedOperationException("The shaking entity data isn't supported on this version"); - } - @Override public EntityData usingItem(boolean enabled, boolean offHand, boolean riptide) { throw new UnsupportedOperationException("The standalone using item data isn't supported on this version"); } - @Override - public EntityData potionColor(int color) { - return newEntityData(7, EntityDataTypes.INT, color); - } - - @Override - public EntityData potionAmbient(boolean ambient) { - return newEntityData(8, EntityDataTypes.BYTE, (byte) (ambient ? 1 : 0)); - } - @Override public EntityData shoulderEntityLeft(ParrotVariant variant) { throw new UnsupportedOperationException("The shoulder entity data isn't supported on this version"); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java index 37091df..8c69719 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java @@ -7,11 +7,6 @@ import lol.pyr.znpcsplus.util.CreeperState; @Deprecated public class V1_9MetadataFactory extends V1_8MetadataFactory { - @Override - public EntityData potionAmbient(boolean ambient) { - return newEntityData(8, EntityDataTypes.BOOLEAN, ambient); - } - @Override public EntityData batHanging(boolean hanging) { return newEntityData(11, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); From ddabf9dc2c41f55bcab39d9f6a5a9e71fde0cb68 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 20:54:38 +0200 Subject: [PATCH 38/78] implement fox properties --- .../znpcsplus/entity/EntityPropertyImpl.java | 7 +--- .../entity/EntityPropertyRegistryImpl.java | 35 +++++++++++----- .../entity/properties/ColorProperty.java | 26 ------------ .../properties/EncodedIntegerProperty.java | 40 +++++++++++++++++++ ...roperty.java => HologramItemProperty.java} | 4 +- .../entity/properties/ShakingProperty.java | 23 ----------- .../znpcsplus/metadata/MetadataFactory.java | 5 --- .../metadata/V1_10MetadataFactory.java | 5 --- .../metadata/V1_14MetadataFactory.java | 10 ----- .../metadata/V1_15MetadataFactory.java | 10 ----- .../metadata/V1_17MetadataFactory.java | 10 ----- .../metadata/V1_8MetadataFactory.java | 15 ------- 12 files changed, 68 insertions(+), 122 deletions(-) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java rename plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/{HoloItemProperty.java => HologramItemProperty.java} (88%) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java index 53b4392..25786d4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java @@ -5,16 +5,13 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType; import lol.pyr.znpcsplus.api.entity.EntityProperty; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public abstract class EntityPropertyImpl implements EntityProperty { private final String name; private final T defaultValue; private final Class clazz; - private final List> dependencies = new ArrayList<>(); + private final Set> dependencies = new HashSet<>(); private boolean playerModifiable = true; protected EntityPropertyImpl(String name, T defaultValue, Class clazz) { 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 d9c3694..1fd4b4b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -11,6 +11,7 @@ import lol.pyr.znpcsplus.entity.serializers.*; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; import lol.pyr.znpcsplus.util.*; +import org.bukkit.Color; import org.bukkit.DyeColor; import java.util.*; @@ -102,13 +103,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Evoker registerType("evoker_spell", SpellType.NONE); - // Fox - registerType("fox_variant", FoxVariant.RED); - registerType("fox_sitting", false); - registerType("fox_crouching", false); - registerType("fox_sleeping", false); - registerType("fox_faceplanted", false); - // Frog registerType("frog_variant", FrogVariant.TEMPERATE); @@ -217,7 +211,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new GlowProperty(packetFactory)); register(new BitsetProperty("fire", 0, 0x01)); register(new BitsetProperty("invisible", 0, 0x20)); - register(new HoloItemProperty()); + register(new HologramItemProperty()); linkProperties("glow", "fire", "invisible"); register(new BooleanProperty("silent", 4, false, legacyBooleans)); @@ -226,7 +220,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) potionIndex = 9; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) potionIndex = 8; else potionIndex = 7; - register(new ColorProperty("potion_color", potionIndex++, null)); + register(new EncodedIntegerProperty<>("potion_color", Color.class, potionIndex++, Color::asRGB)); register(new BooleanProperty("potion_ambient", potionIndex, false, legacyBooleans)); // Player @@ -257,13 +251,13 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("small", armorStandIndex, 0x01)); register(new BitsetProperty("arms", armorStandIndex, 0x04)); register(new BitsetProperty("base_plate", armorStandIndex++, 0x08, true)); + linkProperties("small", "arms", "base_plate"); register(new RotationProperty("head_rotation", armorStandIndex++, Vector3f.zero())); register(new RotationProperty("body_rotation", armorStandIndex++, Vector3f.zero())); register(new RotationProperty("left_arm_rotation", armorStandIndex++, new Vector3f(-10, 0, -10))); register(new RotationProperty("right_arm_rotation", armorStandIndex++, new Vector3f(-15, 0, 10))); register(new RotationProperty("left_leg_rotation", armorStandIndex++, new Vector3f(-1, 0, -1))); register(new RotationProperty("right_leg_rotation", armorStandIndex, new Vector3f(1, 0, 1))); - linkProperties("small", "arms", "base_plate"); // Ghast final int ghastAttackingIndex; @@ -275,13 +269,32 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else ghastAttackingIndex = 16; register(new BooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; + + // Fox + int foxIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) foxIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) foxIndex = 16; + else foxIndex = 15; + register(new EncodedIntegerProperty<>("fox_variant", FoxVariant.RED, foxIndex++, Enum::ordinal)); + register(new BitsetProperty("fox_sitting", foxIndex, 0x01)); + register(new BitsetProperty("fox_crouching", foxIndex, 0x04)); + register(new BitsetProperty("fox_sleeping", foxIndex, 0x20)); + linkProperties("fox_sitting", "fox_crouching", "fox_sleeping"); + + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_15)) return; + + register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40)); + linkProperties("fox_sitting", "fox_crouching", "fox_sleeping", "fox_faceplanted"); + + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; // Goat register(new BooleanProperty("has_left_horn", 18, true, legacyBooleans)); register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); - register(new ShakingProperty(7)); + register(new EncodedIntegerProperty<>("shaking", false,7, enabled -> enabled ? 140 : 0)); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java deleted file mode 100644 index 87ccee6..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ColorProperty.java +++ /dev/null @@ -1,26 +0,0 @@ -package lol.pyr.znpcsplus.entity.properties; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import lol.pyr.znpcsplus.entity.EntityPropertyImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import org.bukkit.Color; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class ColorProperty extends EntityPropertyImpl { - private final int index; - - public ColorProperty(String name, int index, Color def) { - super(name, def, Color.class); - this.index = index; - } - - @Override - public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - Color color = entity.getProperty(this); - if (color == null) return; - properties.put(index, newEntityData(index, EntityDataTypes.INT, color.asRGB())); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java new file mode 100644 index 0000000..a860e09 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java @@ -0,0 +1,40 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class EncodedIntegerProperty extends EntityPropertyImpl { + private final IntegerDecoder decoder; + private final int index; + + protected EncodedIntegerProperty(String name, T defaultValue, Class clazz, int index, IntegerDecoder decoder) { + super(name, defaultValue, clazz); + this.decoder = decoder; + this.index = index; + } + + @SuppressWarnings("unchecked") + public EncodedIntegerProperty(String name, T defaultValue, int index, IntegerDecoder decoder) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder); + } + + public EncodedIntegerProperty(String name, Class clazz, int index, IntegerDecoder decoder) { + this(name, null, clazz, index, decoder); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + T value = entity.getProperty(this); + if (value == null) return; + properties.put(index, newEntityData(index, EntityDataTypes.INT, decoder.decode(value))); + } + + public interface IntegerDecoder { + int decode(T obj); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HologramItemProperty.java similarity index 88% rename from plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java rename to plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HologramItemProperty.java index cb590c5..f97cbc4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HoloItemProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HologramItemProperty.java @@ -9,9 +9,9 @@ import org.bukkit.entity.Player; import java.util.Map; -public class HoloItemProperty extends EntityPropertyImpl { +public class HologramItemProperty extends EntityPropertyImpl { - public HoloItemProperty() { + public HologramItemProperty() { super("holo_item", null, ItemStack.class); setPlayerModifiable(false); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java deleted file mode 100644 index 3d9266a..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/ShakingProperty.java +++ /dev/null @@ -1,23 +0,0 @@ -package lol.pyr.znpcsplus.entity.properties; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import lol.pyr.znpcsplus.entity.EntityPropertyImpl; -import lol.pyr.znpcsplus.entity.PacketEntity; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class ShakingProperty extends EntityPropertyImpl { - private final int index; - - public ShakingProperty(int index) { - super("shaking", false, Boolean.class); - this.index = index; - } - - @Override - public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - properties.put(index, newEntityData(index, EntityDataTypes.INT, entity.getProperty(this) ? 140 : 0)); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 843fb5a..67db0fc 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -24,7 +24,6 @@ import org.bukkit.DyeColor; @Deprecated public interface MetadataFactory { - EntityData noGravity(); EntityData pose(EntityPose pose); EntityData usingItem(boolean enabled, boolean offhand, boolean riptide); @@ -64,10 +63,6 @@ public interface MetadataFactory { // Evoker EntityData evokerSpell(int spell); - // Fox - EntityData foxVariant(int variant); - EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted); - // Frog EntityData frogVariant(int variant); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java index 2358af9..7252a3e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java @@ -7,11 +7,6 @@ import lol.pyr.znpcsplus.util.CreeperState; @Deprecated public class V1_10MetadataFactory extends V1_9MetadataFactory { - @Override - public EntityData noGravity() { - return newEntityData(5, EntityDataTypes.BOOLEAN, true); - } - @Override public EntityData batHanging(boolean hanging) { return newEntityData(12, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index edfb880..7744dc0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -72,16 +72,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory { return newEntityData(15, EntityDataTypes.BYTE, (byte) spell); } - @Override - public EntityData foxVariant(int variant) { - return newEntityData(15, EntityDataTypes.INT, variant); - } - - @Override - public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0))); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(16, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java index 6652a0a..83821e0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java @@ -70,16 +70,6 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory { return newEntityData(16, EntityDataTypes.BYTE, (byte) spell); } - @Override - public EntityData foxVariant(int variant) { - return newEntityData(16, EntityDataTypes.INT, variant); - } - - @Override - public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) { - return newEntityData(17, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0))); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(17, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index c7bc061..9a9f28d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -106,16 +106,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return newEntityData(17, EntityDataTypes.BYTE, (byte) spell); } - @Override - public EntityData foxVariant(int variant) { - return newEntityData(17, EntityDataTypes.INT, variant); - } - - @Override - public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) { - return newEntityData(18, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0))); - } - @Override public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { return newEntityData(17, EntityDataTypes.BOOLEAN, immuneToZombification); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index da25b5d..30e8218 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -10,11 +10,6 @@ import org.bukkit.DyeColor; @Deprecated public class V1_8MetadataFactory implements MetadataFactory { - @Override - public EntityData noGravity() { - throw new UnsupportedOperationException("The gravity entity data isn't supported on this version"); - } - @Override public EntityData pose(EntityPose pose) { throw new UnsupportedOperationException("The pose entity data isn't supported on this version"); @@ -115,16 +110,6 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The evoker spell entity data isn't supported on this version"); } - @Override - public EntityData foxVariant(int variant) { - throw new UnsupportedOperationException("The fox variant entity data isn't supported on this version"); - } - - @Override - public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) { - throw new UnsupportedOperationException("The fox properties entity data isn't supported on this version"); - } - @Override public EntityData frogVariant(int variant) { throw new UnsupportedOperationException("The frog variant entity data isn't supported on this version"); From f2a4d51e282d7faba07ff0596b282d7500fa9a64 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 21:47:10 +0200 Subject: [PATCH 39/78] implement bat properties --- .../entity/EntityPropertyRegistryImpl.java | 20 ++++++++++++++----- .../entity/properties/BooleanProperty.java | 4 ++-- .../znpcsplus/metadata/MetadataFactory.java | 7 ------- .../metadata/V1_10MetadataFactory.java | 5 ----- .../metadata/V1_14MetadataFactory.java | 5 ----- .../metadata/V1_15MetadataFactory.java | 15 -------------- .../metadata/V1_17MetadataFactory.java | 15 -------------- .../metadata/V1_8MetadataFactory.java | 15 -------------- .../metadata/V1_9MetadataFactory.java | 5 ----- 9 files changed, 17 insertions(+), 74 deletions(-) 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 1fd4b4b..2ce417a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -60,7 +60,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation - registerType("shaking", false); registerType("baby", false); // TODO registerType("pose", NpcPose.STANDING); @@ -79,10 +78,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Bat registerType("hanging", false); - // Bee - registerType("angry", false); - registerType("has_nectar", false); - // Blaze registerType("blaze_on_fire", false); @@ -269,6 +264,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else ghastAttackingIndex = 16; register(new BooleanProperty("attacking", ghastAttackingIndex, false, legacyBooleans)); + // Bat + final int batIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) batIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) batIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) batIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) batIndex = 12; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) batIndex = 11; + else batIndex = 16; + register(new BooleanProperty("hanging", batIndex, false, true /* This isnt a mistake */)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Fox @@ -287,6 +292,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40)); linkProperties("fox_sitting", "fox_crouching", "fox_sleeping", "fox_faceplanted"); + int beeIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) beeIndex = 17; + else beeIndex = 18; + register(new BitsetProperty("has_nectar", beeIndex++, 0x08)); + register(new EncodedIntegerProperty<>("angry", false, beeIndex, enabled -> enabled ? 1 : 0)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java index 2355e56..5cdb880 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BooleanProperty.java @@ -28,7 +28,7 @@ public class BooleanProperty extends EntityPropertyImpl { public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { boolean enabled = entity.getProperty(this); if (inverted) enabled = !enabled; - if (legacy) properties.put(index, new EntityData(index, EntityDataTypes.BYTE, (enabled ? 1 : 0))); - else properties.put(index, new EntityData(index, EntityDataTypes.BOOLEAN, enabled)); + if (legacy) properties.put(index, newEntityData(index, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0))); + else properties.put(index, newEntityData(index, EntityDataTypes.BOOLEAN, enabled)); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 67db0fc..20d4d69 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -35,13 +35,6 @@ public interface MetadataFactory { EntityData axolotlVariant(int variant); EntityData playingDead(boolean playingDead); - // Bat - EntityData batHanging(boolean hanging); - - // Bee - EntityData beeAngry(boolean angry); - EntityData beeHasNectar(boolean hasNectar); - // Blaze EntityData blazeOnFire(boolean onFire); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java index 7252a3e..d6669c4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java @@ -7,11 +7,6 @@ import lol.pyr.znpcsplus.util.CreeperState; @Deprecated public class V1_10MetadataFactory extends V1_9MetadataFactory { - @Override - public EntityData batHanging(boolean hanging) { - return newEntityData(12, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); - } - @Override public EntityData blazeOnFire(boolean onFire) { return newEntityData(12, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index 7744dc0..4f9bd17 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -32,11 +32,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory { return createShoulderEntityRight(18, variant); } - @Override - public EntityData batHanging(boolean hanging) { - return newEntityData(14, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); - } - @Override public EntityData blazeOnFire(boolean onFire) { return newEntityData(14, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java index 83821e0..9a79da7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java @@ -20,21 +20,6 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory { return createShoulderEntityRight(19, variant); } - @Override - public EntityData batHanging(boolean hanging) { - return newEntityData(15, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); - } - - @Override - public EntityData beeAngry(boolean angry) { - return newEntityData(17, EntityDataTypes.INT, angry ? 1 : 0); - } - - @Override - public EntityData beeHasNectar(boolean hasNectar) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (hasNectar ? 0x08 : 0)); - } - @Override public EntityData blazeOnFire(boolean onFire) { return newEntityData(15, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index 9a9f28d..ae25c11 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -36,21 +36,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return newEntityData(18, EntityDataTypes.BOOLEAN, playingDead); } - @Override - public EntityData batHanging(boolean hanging) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); - } - - @Override - public EntityData beeAngry(boolean angry) { - return newEntityData(18, EntityDataTypes.INT, angry ? 1 : 0); - } - - @Override - public EntityData beeHasNectar(boolean hasNectar) { - return newEntityData(17, EntityDataTypes.BYTE, (byte) (hasNectar ? 0x08 : 0)); - } - @Override public EntityData blazeOnFire(boolean onFire) { return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 30e8218..2e5b777 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -40,21 +40,6 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The playing dead entity data isn't supported on this version"); } - @Override - public EntityData batHanging(boolean hanging) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (hanging ? 1 : 0)); - } - - @Override - public EntityData beeAngry(boolean angry) { - throw new UnsupportedOperationException("The bee properties entity data isn't supported on this version"); - } - - @Override - public EntityData beeHasNectar(boolean hasNectar) { - throw new UnsupportedOperationException("The bee properties entity data isn't supported on this version"); - } - @Override public EntityData blazeOnFire(boolean onFire) { return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 1 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java index 8c69719..1a4ce69 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java @@ -7,11 +7,6 @@ import lol.pyr.znpcsplus.util.CreeperState; @Deprecated public class V1_9MetadataFactory extends V1_8MetadataFactory { - @Override - public EntityData batHanging(boolean hanging) { - return newEntityData(11, EntityDataTypes.BYTE, (byte) (hanging ? 0x01 : 0)); - } - @Override public EntityData blazeOnFire(boolean onFire) { return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 1 : 0)); From 551b9892400f6fc7fa9524a10a5abd5bcf536743 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 22:23:30 +0200 Subject: [PATCH 40/78] implement cat & tamed property --- .../lol/pyr/znpcsplus/util/CatVariant.java | 32 +++++++------------ .../entity/EntityPropertyRegistryImpl.java | 20 ++++++++++++ .../properties/EncodedIntegerProperty.java | 16 +++++++--- .../znpcsplus/metadata/MetadataFactory.java | 8 ----- .../metadata/V1_14MetadataFactory.java | 17 ---------- .../metadata/V1_15MetadataFactory.java | 17 ---------- .../metadata/V1_17MetadataFactory.java | 22 ------------- .../metadata/V1_8MetadataFactory.java | 21 ------------ .../znpcsplus/npc/NpcTypeRegistryImpl.java | 5 +-- 9 files changed, 46 insertions(+), 112 deletions(-) diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/CatVariant.java b/api/src/main/java/lol/pyr/znpcsplus/util/CatVariant.java index 843036f..9aaa7f4 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/util/CatVariant.java +++ b/api/src/main/java/lol/pyr/znpcsplus/util/CatVariant.java @@ -1,25 +1,15 @@ package lol.pyr.znpcsplus.util; public enum CatVariant { - TABBY(0), - BLACK(1), - RED(2), - SIAMESE(3), - BRITISH_SHORTHAIR(4), - CALICO(5), - PERSIAN(6), - RAGDOLL(7), - WHITE(8), - JELLIE(9), - ALL_BLACK(10); - - private final int id; - - CatVariant(int id) { - this.id = id; - } - - public int getId() { - return id; - } + TABBY, + BLACK, + RED, + SIAMESE, + BRITISH_SHORTHAIR, + CALICO, + PERSIAN, + RAGDOLL, + WHITE, + JELLIE, + ALL_BLACK } 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 2ce417a..338133a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -2,6 +2,7 @@ package lol.pyr.znpcsplus.entity; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; @@ -210,6 +211,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("glow", "fire", "invisible"); register(new BooleanProperty("silent", 4, false, legacyBooleans)); + final int tamedIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) tamedIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) tamedIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) tamedIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) tamedIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) tamedIndex = 12; + else tamedIndex = 16; + register(new BitsetProperty("tamed", tamedIndex, 0x04)); + int potionIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) potionIndex = 10; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) potionIndex = 9; @@ -276,6 +286,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; + // Cat + int catIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) catIndex = 19; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) catIndex = 18; + else catIndex = 17; + register(new EncodedIntegerProperty<>("cat_variant", CatVariant.BLACK, catIndex++, Enum::ordinal, EntityDataTypes.CAT_VARIANT)); + register(new BooleanProperty("cat_laying", catIndex++, false, legacyBooleans)); + register(new BooleanProperty("cat_relaxed", catIndex++, false, legacyBooleans)); + register(new EncodedIntegerProperty<>("cat_collar", DyeColor.RED, catIndex, Enum::ordinal)); + // Fox int foxIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) foxIndex = 17; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java index a860e09..d089547 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedIntegerProperty.java @@ -1,6 +1,7 @@ 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 lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.PacketEntity; @@ -9,29 +10,36 @@ import org.bukkit.entity.Player; import java.util.Map; public class EncodedIntegerProperty extends EntityPropertyImpl { + private final EntityDataType type; private final IntegerDecoder decoder; private final int index; - protected EncodedIntegerProperty(String name, T defaultValue, Class clazz, int index, IntegerDecoder decoder) { + protected EncodedIntegerProperty(String name, T defaultValue, Class clazz, int index, IntegerDecoder decoder, EntityDataType type) { super(name, defaultValue, clazz); this.decoder = decoder; this.index = index; + this.type = type; } @SuppressWarnings("unchecked") public EncodedIntegerProperty(String name, T defaultValue, int index, IntegerDecoder decoder) { - this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder); + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, EntityDataTypes.INT); + } + + @SuppressWarnings("unchecked") + public EncodedIntegerProperty(String name, T defaultValue, int index, IntegerDecoder decoder, EntityDataType type) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, type); } public EncodedIntegerProperty(String name, Class clazz, int index, IntegerDecoder decoder) { - this(name, null, clazz, index, decoder); + this(name, null, clazz, index, decoder, EntityDataTypes.INT); } @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { T value = entity.getProperty(this); if (value == null) return; - properties.put(index, newEntityData(index, EntityDataTypes.INT, decoder.decode(value))); + properties.put(index, newEntityData(index, type, decoder.decode(value))); } public interface IntegerDecoder { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 20d4d69..d23a75a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -2,10 +2,8 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; -import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import org.bukkit.DyeColor; /** * 1.8 ... @@ -38,12 +36,6 @@ public interface MetadataFactory { // Blaze EntityData blazeOnFire(boolean onFire); - // Cat - EntityData catVariant(CatVariant variant); - EntityData catLying(boolean lying); - EntityData catTamed(boolean tamed); - EntityData catCollarColor(DyeColor collarColor); - // Creeper EntityData creeperState(CreeperState state); EntityData creeperCharged(boolean charged); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java index 4f9bd17..eebf156 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java @@ -4,10 +4,8 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; -import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import org.bukkit.DyeColor; @Deprecated public class V1_14MetadataFactory extends V1_13MetadataFactory { @@ -37,21 +35,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory { return newEntityData(14, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); } - @Override - public EntityData catVariant(CatVariant variant) { - return newEntityData(17, EntityDataTypes.CAT_VARIANT, variant.getId()); - } - - @Override - public EntityData catLying(boolean lying) { - throw new UnsupportedOperationException("The cat lying entity data isn't supported on this version"); - } - - @Override - public EntityData catCollarColor(DyeColor collarColor) { - return newEntityData(20, EntityDataTypes.INT, collarColor.ordinal()); - } - @Override public EntityData creeperState(CreeperState state) { return newEntityData(14, EntityDataTypes.INT, state.getState()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java index 9a79da7..5a3f1b3 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java @@ -3,10 +3,8 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; -import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import org.bukkit.DyeColor; @Deprecated public class V1_15MetadataFactory extends V1_14MetadataFactory { @@ -25,21 +23,6 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory { return newEntityData(15, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); } - @Override - public EntityData catVariant(CatVariant variant) { - return newEntityData(18, EntityDataTypes.CAT_VARIANT, variant.getId()); - } - - @Override - public EntityData catLying(boolean lying) { - return newEntityData(19, EntityDataTypes.BOOLEAN, lying); - } - - @Override - public EntityData catCollarColor(DyeColor collarColor) { - return newEntityData(21, EntityDataTypes.INT, collarColor.ordinal()); - } - @Override public EntityData creeperState(CreeperState state) { return newEntityData(15, EntityDataTypes.INT, state.getState()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index ae25c11..3e0da54 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -3,10 +3,8 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; -import lol.pyr.znpcsplus.util.CatVariant; import lol.pyr.znpcsplus.util.CreeperState; import lol.pyr.znpcsplus.util.ParrotVariant; -import org.bukkit.DyeColor; @Deprecated public class V1_17MetadataFactory extends V1_16MetadataFactory { @@ -41,26 +39,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); } - @Override - public EntityData catVariant(CatVariant variant) { - return newEntityData(19, EntityDataTypes.CAT_VARIANT, variant.getId()); - } - - @Override - public EntityData catLying(boolean lying) { - return newEntityData(20, EntityDataTypes.BOOLEAN, lying); - } - - @Override - public EntityData catTamed(boolean tamed) { - return newEntityData(17, EntityDataTypes.BYTE, (byte) (tamed ? 0x04 : 0)); - } - - @Override - public EntityData catCollarColor(DyeColor collarColor) { - return newEntityData(22, EntityDataTypes.INT, collarColor.ordinal()); - } - @Override public EntityData creeperState(CreeperState state) { return newEntityData(16, EntityDataTypes.INT, state.getState()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 2e5b777..1bde7bb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -5,7 +5,6 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; import lol.pyr.znpcsplus.util.*; -import org.bukkit.DyeColor; @Deprecated public class V1_8MetadataFactory implements MetadataFactory { @@ -45,26 +44,6 @@ public class V1_8MetadataFactory implements MetadataFactory { return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 1 : 0)); } - @Override - public EntityData catVariant(CatVariant variant) { - throw new UnsupportedOperationException("The cat variant entity data isn't supported on this version"); - } - - @Override - public EntityData catLying(boolean lying) { - throw new UnsupportedOperationException("The cat lying entity data isn't supported on this version"); - } - - @Override - public EntityData catTamed(boolean tamed) { - throw new UnsupportedOperationException("The cat tamed entity data isn't supported on this version"); - } - - @Override - public EntityData catCollarColor(DyeColor collarColor) { - throw new UnsupportedOperationException("The cat collar color entity data isn't supported on this version"); - } - @Override public EntityData creeperState(CreeperState state) { return newEntityData(16, EntityDataTypes.BYTE, (byte) state.getState()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 89cc48f..9e66516 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -143,7 +143,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(1.525)); register(builder(p, "wolf", EntityTypes.WOLF) - .setHologramOffset(-1.125)); + .setHologramOffset(-1.125) + .addProperties("tamed")); register(builder(p, "zombie", EntityTypes.ZOMBIE) .setHologramOffset(-0.025) @@ -250,7 +251,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "cat", EntityTypes.CAT) .setHologramOffset(-1.275) - .addProperties("cat_variant", "cat_lying", "cat_collar_color")); + .addProperties("cat_variant", "cat_laying", "cat_relaxed", "cat_collar", "tamed")); register(builder(p, "fox", EntityTypes.FOX) .setHologramOffset(-1.275) From 3741b76189f3179b3a0b832c81445e2040a43f70 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Mon, 7 Aug 2023 22:35:33 +0200 Subject: [PATCH 41/78] implement hoglin --- .../entity/EntityPropertyRegistryImpl.java | 18 +++++++----------- .../znpcsplus/metadata/MetadataFactory.java | 3 --- .../metadata/V1_16MetadataFactory.java | 7 ------- .../metadata/V1_17MetadataFactory.java | 5 ----- .../metadata/V1_8MetadataFactory.java | 5 ----- 5 files changed, 7 insertions(+), 31 deletions(-) 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 338133a..f41eb42 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -76,17 +76,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("axolotl_variant", 0); registerType("playing_dead", false); // TODO fix disabling - // Bat - registerType("hanging", false); - // Blaze registerType("blaze_on_fire", false); - // Cat - registerType("cat_variant", CatVariant.BLACK); - registerType("cat_lying", false); - registerType("cat_collar_color", DyeColor.RED); - // Creeper registerType("creeper_state", CreeperState.IDLE); registerType("creeper_charged", false); @@ -105,9 +97,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Guardian registerType("is_elder", false); // TODO: ensure it only works till 1.10. Note: index is wrong on wiki.vg - // Piglin / Hoglin - registerType("immune_to_zombification", true); - // Pufferfish registerType("puff_state", null); // TODO: Make a puff state enum class @@ -318,6 +307,13 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("has_nectar", beeIndex++, 0x08)); register(new EncodedIntegerProperty<>("angry", false, beeIndex, enabled -> enabled ? 1 : 0)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_16)) return; + + final int zombificationIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) zombificationIndex = 17; + else zombificationIndex = 16; + register(new BooleanProperty("immune_to_zombification", zombificationIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; // Goat diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index d23a75a..e73973f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -51,9 +51,6 @@ public interface MetadataFactory { // Frog EntityData frogVariant(int variant); - // Hoglin - EntityData hoglinImmuneToZombification(boolean immuneToZombification); - // Villager EntityData villagerData(int type, int profession, int level); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java index 924efb7..d1c3c6f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java @@ -1,13 +1,6 @@ package lol.pyr.znpcsplus.metadata; -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; - @Deprecated public class V1_16MetadataFactory extends V1_15MetadataFactory { - @Override - public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { - return newEntityData(16, EntityDataTypes.BOOLEAN, immuneToZombification); - } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index 3e0da54..38a3a7f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -69,11 +69,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { return newEntityData(17, EntityDataTypes.BYTE, (byte) spell); } - @Override - public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { - return newEntityData(17, EntityDataTypes.BOOLEAN, immuneToZombification); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(18, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 1bde7bb..4cb3cf7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -79,11 +79,6 @@ public class V1_8MetadataFactory implements MetadataFactory { throw new UnsupportedOperationException("The frog variant entity data isn't supported on this version"); } - @Override - public EntityData hoglinImmuneToZombification(boolean immuneToZombification) { - throw new UnsupportedOperationException("The hoglin zombification entity data isn't supported on this version"); - } - @Override public EntityData villagerData(int type, int profession, int level) { return newEntityData(16, EntityDataTypes.INT, profession); From 40323c57e515fa05ceb72f4d894c9e9eda72ec04 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 9 Aug 2023 12:55:55 +0530 Subject: [PATCH 42/78] fix equipment property --- .../znpcsplus/commands/property/PropertySetCommand.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 1813ea4..335cc16 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.commands.property; import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState; import com.github.retrooper.packetevents.protocol.world.states.type.StateType; import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes; +import io.github.retrooper.packetevents.util.SpigotConversionUtil; import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.common.command.CommandExecutionException; @@ -16,7 +17,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; import org.bukkit.DyeColor; -import org.bukkit.inventory.ItemStack; +import com.github.retrooper.packetevents.protocol.item.ItemStack; import java.util.Collections; import java.util.List; @@ -42,12 +43,12 @@ public class PropertySetCommand implements CommandHandler { Object value; String valueName; if (type == ItemStack.class) { - ItemStack bukkitStack = context.ensureSenderIsPlayer().getInventory().getItemInHand(); + org.bukkit.inventory.ItemStack bukkitStack = context.ensureSenderIsPlayer().getInventory().getItemInHand(); if (bukkitStack.getAmount() == 0) { value = null; valueName = "EMPTY"; } else { - value = bukkitStack; + value = SpigotConversionUtil.fromBukkitItemStack(bukkitStack); valueName = bukkitStack.toString(); } } From beb3d21ba4a983dc3eb39e708c5c88cdc82b6834 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:09:47 +0530 Subject: [PATCH 43/78] added axolotl properties --- .../main/java/lol/pyr/znpcsplus/util/AxolotlVariant.java | 9 +++++++++ plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../znpcsplus/commands/property/PropertySetCommand.java | 1 + .../pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 5 +++++ 4 files changed, 16 insertions(+) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/AxolotlVariant.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/AxolotlVariant.java b/api/src/main/java/lol/pyr/znpcsplus/util/AxolotlVariant.java new file mode 100644 index 0000000..b38b907 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/AxolotlVariant.java @@ -0,0 +1,9 @@ +package lol.pyr.znpcsplus.util; + +public enum AxolotlVariant { + LUCY, + WILD, + GOLD, + CYAN, + BLUE +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 9e0f44b..77cf676 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -264,6 +264,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, VillagerType.class, incorrectUsageMessage); registerEnumParser(manager, VillagerProfession.class, incorrectUsageMessage); registerEnumParser(manager, VillagerLevel.class, incorrectUsageMessage); + registerEnumParser(manager, AxolotlVariant.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 335cc16..25b6a5c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -131,6 +131,7 @@ public class PropertySetCommand implements CommandHandler { if (type == VillagerType.class) return context.suggestEnum(VillagerType.values()); if (type == VillagerProfession.class) return context.suggestEnum(VillagerProfession.values()); if (type == VillagerLevel.class) return context.suggestEnum(VillagerLevel.values()); + if (type == AxolotlVariant.class) return context.suggestEnum(AxolotlVariant.values()); } else if (context.argSize() == 4) { if (type == BlockState.class) { 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 f41eb42..844ef5b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -58,6 +58,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerType.class); registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerLevel.class); + registerEnumSerializer(AxolotlVariant.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -301,6 +302,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40)); linkProperties("fox_sitting", "fox_crouching", "fox_sleeping", "fox_faceplanted"); + // Bee int beeIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) beeIndex = 17; else beeIndex = 18; @@ -315,6 +317,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BooleanProperty("immune_to_zombification", zombificationIndex, false, legacyBooleans)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; + // Axolotl + register(new EncodedIntegerProperty<>("axolotl_variant", AxolotlVariant.LUCY, 17, Enum::ordinal)); + register(new BooleanProperty("playing_dead", 18, false, legacyBooleans)); // Goat register(new BooleanProperty("has_left_horn", 18, true, legacyBooleans)); From f03162398ca23d1995cc11fb6e3a83a88908559d Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:12:20 +0530 Subject: [PATCH 44/78] added blaze_on_fire property --- .../entity/EntityPropertyRegistryImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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 844ef5b..b2a69e7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -73,13 +73,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("beam_target", null); // TODO: Make a block pos class for this registerType("show_base", true); // TODO - // Axolotl - registerType("axolotl_variant", 0); - registerType("playing_dead", false); // TODO fix disabling - - // Blaze - registerType("blaze_on_fire", false); - // Creeper registerType("creeper_state", CreeperState.IDLE); registerType("creeper_charged", false); @@ -274,6 +267,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else batIndex = 16; register(new BooleanProperty("hanging", batIndex, false, true /* This isnt a mistake */)); + // Blaze + final int blazeIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) blazeIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) blazeIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) blazeIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) blazeIndex = 12; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) blazeIndex = 11; + else blazeIndex = 16; + register(new BitsetProperty("blaze_on_fire", blazeIndex, 0x01)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Cat From fc5df502f34b7d85d2af512517fcfc95f5062d34 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:13:47 +0530 Subject: [PATCH 45/78] added bashing property for camel --- .../lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 5 +++++ .../main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) 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 b2a69e7..09ef856 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -329,6 +329,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); register(new EncodedIntegerProperty<>("shaking", false,7, enabled -> enabled ? 140 : 0)); + + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_20)) return; + + // Camel + register(new BooleanProperty("bashing", 18, false, legacyBooleans)); } private void registerSerializer(PropertySerializer serializer) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 9e66516..ba761c9 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -335,7 +335,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(0.125)); register(builder(p, "camel", EntityTypes.CAMEL) - .setHologramOffset(0.25)); + .setHologramOffset(0.25) + .addProperties("bashing")); } public Collection getAll() { From 329d344013aa111375f78ee3b4308c6395dafb86 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:16:12 +0530 Subject: [PATCH 46/78] added pose property --- .../entity/EntityPropertyRegistryImpl.java | 3 ++- .../entity/properties/NpcPoseProperty.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NpcPoseProperty.java 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 09ef856..3ceeed8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -63,7 +63,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation registerType("baby", false); // TODO - registerType("pose", NpcPose.STANDING); // Player registerType("shoulder_entity_left", ParrotVariant.NONE); @@ -278,6 +277,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("blaze_on_fire", blazeIndex, 0x01)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; + // Pose + register(new NpcPoseProperty()); // Cat int catIndex; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NpcPoseProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NpcPoseProperty.java new file mode 100644 index 0000000..3599f64 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NpcPoseProperty.java @@ -0,0 +1,23 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.util.NpcPose; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class NpcPoseProperty extends EntityPropertyImpl { + + public NpcPoseProperty() { + super("pose", NpcPose.STANDING, NpcPose.class); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + properties.put(6, newEntityData(6, EntityDataTypes.ENTITY_POSE, EntityPose.valueOf(entity.getProperty(this).name()))); + } +} From 12ea0eab22a6bbf27c4492429fdc82edc8f04713 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:17:30 +0530 Subject: [PATCH 47/78] added baby property --- .../znpcsplus/entity/EntityPropertyRegistryImpl.java | 11 +++++++++-- .../main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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 3ceeed8..9ffcbb4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -62,8 +62,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation - registerType("baby", false); // TODO - // Player registerType("shoulder_entity_left", ParrotVariant.NONE); registerType("shoulder_entity_right", ParrotVariant.NONE); @@ -210,6 +208,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EncodedIntegerProperty<>("potion_color", Color.class, potionIndex++, Color::asRGB)); register(new BooleanProperty("potion_ambient", potionIndex, false, legacyBooleans)); + int babyIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) babyIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) babyIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) babyIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) babyIndex = 12; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) babyIndex = 11; + else babyIndex = 12; + register(new BooleanProperty("baby", babyIndex, false, legacyBooleans)); + // Player register(new DummyProperty<>("skin", SkinDescriptor.class, false)); final int skinLayersIndex; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 4d406c0..2c8f05c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.npc; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; +import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.npc.NpcType; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; @@ -92,6 +93,9 @@ public class NpcTypeImpl implements NpcType { if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) addProperties("pose"); if (version.isNewerThanOrEquals(ServerVersion.V_1_17)) addProperties("shaking"); + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_AGEABLE)) { + addProperties("baby"); + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties)); } } From 2121db4a904d3ae621c5bfb8ab88ccbbe98a36f3 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:18:01 +0530 Subject: [PATCH 48/78] added creeper properties --- .../znpcsplus/entity/EntityPropertyRegistryImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 9ffcbb4..ed29403 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -283,6 +283,17 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else blazeIndex = 16; register(new BitsetProperty("blaze_on_fire", blazeIndex, 0x01)); + // Creeper + int creeperIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) creeperIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) creeperIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) creeperIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) creeperIndex = 12; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) creeperIndex = 11; + else creeperIndex= 16; + register(new EncodedIntegerProperty<>("creeper_state", CreeperState.IDLE, creeperIndex++, CreeperState::getState)); + register(new BooleanProperty("creeper_charged", creeperIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); From 33b22b534df1141960706c94143f79cb35752218 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 21 Aug 2023 20:44:16 +0530 Subject: [PATCH 49/78] added serializer checking before setting property when loading npc --- .../java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 9f0ef66..336deab 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -65,7 +65,12 @@ public class YamlStorage implements NpcStorage { Bukkit.getLogger().log(Level.WARNING, "Unknown property '" + key + "' for npc '" + config.getString("id") + "'. skipping ..."); continue; } - npc.UNSAFE_setProperty(property, propertyRegistry.getSerializer(property.getType()).deserialize(properties.getString(key))); + PropertySerializer serializer = propertyRegistry.getSerializer(property.getType()); + if (serializer == null) { + Bukkit.getLogger().log(Level.WARNING, "Unknown serializer for property '" + key + "' for npc '" + config.getString("id") + "'. skipping ..."); + continue; + } + npc.UNSAFE_setProperty(property, serializer.deserialize(properties.getString(key))); } } HologramImpl hologram = npc.getHologram(); From 80b89c5b939bce9af359630ed0ce6fd0f7e18135 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 22 Aug 2023 23:46:00 +0530 Subject: [PATCH 50/78] fixed Equipment property serialization --- .../entity/serializers/ItemStackPropertySerializer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/ItemStackPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/ItemStackPropertySerializer.java index d9f59d2..c6f1cb5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/ItemStackPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/ItemStackPropertySerializer.java @@ -1,18 +1,19 @@ package lol.pyr.znpcsplus.entity.serializers; +import com.github.retrooper.packetevents.protocol.item.ItemStack; +import io.github.retrooper.packetevents.util.SpigotConversionUtil; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.util.ItemSerializationUtil; -import org.bukkit.inventory.ItemStack; public class ItemStackPropertySerializer implements PropertySerializer { @Override public String serialize(ItemStack property) { - return ItemSerializationUtil.itemToB64(property); + return ItemSerializationUtil.itemToB64(SpigotConversionUtil.toBukkitItemStack(property)); } @Override public ItemStack deserialize(String property) { - return ItemSerializationUtil.itemFromB64(property); + return SpigotConversionUtil.fromBukkitItemStack(ItemSerializationUtil.itemFromB64(property)); } @Override From 467eac59728191c2d120d147b0935221e16ee431 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 23 Aug 2023 02:53:26 +0530 Subject: [PATCH 51/78] generalized suggestion of enum property in property set command --- .../commands/property/PropertySetCommand.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 25b6a5c..752f8cb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -16,7 +16,6 @@ import lol.pyr.znpcsplus.util.*; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; -import org.bukkit.DyeColor; import com.github.retrooper.packetevents.protocol.item.ItemStack; import java.util.Collections; @@ -118,20 +117,13 @@ public class PropertySetCommand implements CommandHandler { if (context.argSize() == 3) { if (type == Boolean.class) return context.suggestLiteral("true", "false"); if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys()); - if (type == NpcPose.class) return context.suggestEnum(NpcPose.values()); if (type == Color.class) return context.suggestLiteral("0x0F00FF", "#FFFFFF"); - if (type == DyeColor.class) return context.suggestEnum(DyeColor.values()); - if (type == CatVariant.class) return context.suggestEnum(CatVariant.values()); - if (type == CreeperState.class) return context.suggestEnum(CreeperState.values()); - if (type == ParrotVariant.class) return context.suggestEnum(ParrotVariant.values()); if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block"); - if (type == SpellType.class) return context.suggestEnum(SpellType.values()); - if (type == FoxVariant.class) return context.suggestEnum(FoxVariant.values()); - if (type == FrogVariant.class) return context.suggestEnum(FrogVariant.values()); - if (type == VillagerType.class) return context.suggestEnum(VillagerType.values()); - if (type == VillagerProfession.class) return context.suggestEnum(VillagerProfession.values()); - if (type == VillagerLevel.class) return context.suggestEnum(VillagerLevel.values()); - if (type == AxolotlVariant.class) return context.suggestEnum(AxolotlVariant.values()); + + // Suggest enum values directly + if (type.isEnum()) { + return context.suggestEnum((Enum[]) type.getEnumConstants()); + } } else if (context.argSize() == 4) { if (type == BlockState.class) { From b79b41b26dbe910da8c8a4bb5f4edc8d0b298ee7 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 23 Aug 2023 02:57:18 +0530 Subject: [PATCH 52/78] added all (i guess)) horse properties --- .../lol/pyr/znpcsplus/util/HorseArmor.java | 8 +++ .../lol/pyr/znpcsplus/util/HorseColor.java | 11 ++++ .../lol/pyr/znpcsplus/util/HorseStyle.java | 9 +++ .../lol/pyr/znpcsplus/util/HorseType.java | 9 +++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 5 ++ .../entity/EntityPropertyRegistryImpl.java | 60 +++++++++++++++++-- .../entity/properties/BitsetProperty.java | 12 +++- .../properties/EncodedByteProperty.java | 48 +++++++++++++++ .../entity/properties/HorseColorProperty.java | 26 ++++++++ .../entity/properties/HorseStyleProperty.java | 26 ++++++++ .../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 15 ++++- .../znpcsplus/npc/NpcTypeRegistryImpl.java | 3 +- 12 files changed, 223 insertions(+), 9 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/HorseArmor.java create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/HorseColor.java create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/HorseStyle.java create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/HorseType.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedByteProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseColorProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseStyleProperty.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/HorseArmor.java b/api/src/main/java/lol/pyr/znpcsplus/util/HorseArmor.java new file mode 100644 index 0000000..80fa2f2 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/HorseArmor.java @@ -0,0 +1,8 @@ +package lol.pyr.znpcsplus.util; + +public enum HorseArmor { + NONE, + IRON, + GOLD, + DIAMOND +} diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/HorseColor.java b/api/src/main/java/lol/pyr/znpcsplus/util/HorseColor.java new file mode 100644 index 0000000..ae6327a --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/HorseColor.java @@ -0,0 +1,11 @@ +package lol.pyr.znpcsplus.util; + +public enum HorseColor { + WHITE, + CREAMY, + CHESTNUT, + BROWN, + BLACK, + GRAY, + DARK_BROWN +} diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/HorseStyle.java b/api/src/main/java/lol/pyr/znpcsplus/util/HorseStyle.java new file mode 100644 index 0000000..b5544c4 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/HorseStyle.java @@ -0,0 +1,9 @@ +package lol.pyr.znpcsplus.util; + +public enum HorseStyle { + NONE, + WHITE, + WHITEFIELD, + WHITE_DOTS, + BLACK_DOTS +} diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/HorseType.java b/api/src/main/java/lol/pyr/znpcsplus/util/HorseType.java new file mode 100644 index 0000000..9526d67 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/HorseType.java @@ -0,0 +1,9 @@ +package lol.pyr.znpcsplus.util; + +public enum HorseType { + HORSE, + DONKEY, + MULE, + ZOMBIE, + SKELETON +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 77cf676..d414ead 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -253,6 +253,7 @@ public class ZNpcsPlus extends JavaPlugin { manager.registerParser(Color.class, new ColorParser(incorrectUsageMessage)); manager.registerParser(Vector3f.class, new Vector3fParser(incorrectUsageMessage)); + // TODO: Need to find a better way to do this registerEnumParser(manager, NpcPose.class, incorrectUsageMessage); registerEnumParser(manager, DyeColor.class, incorrectUsageMessage); registerEnumParser(manager, CatVariant.class, incorrectUsageMessage); @@ -265,6 +266,10 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, VillagerProfession.class, incorrectUsageMessage); registerEnumParser(manager, VillagerLevel.class, incorrectUsageMessage); registerEnumParser(manager, AxolotlVariant.class, incorrectUsageMessage); + registerEnumParser(manager, HorseType.class, incorrectUsageMessage); + registerEnumParser(manager, HorseStyle.class, incorrectUsageMessage); + registerEnumParser(manager, HorseColor.class, incorrectUsageMessage); + registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 ed29403..56d8788 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -59,6 +59,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerLevel.class); registerEnumSerializer(AxolotlVariant.class); + registerEnumSerializer(HorseType.class); + registerEnumSerializer(HorseColor.class); + registerEnumSerializer(HorseStyle.class); + registerEnumSerializer(HorseArmor.class); + /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -97,11 +102,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Sniffer registerType("sniffer_state", null); // TODO: Nothing on wiki.vg, look in mc source - // Horse - registerType("horse_style", 0); // TODO: Figure this out - registerType("horse_chest", false); // TODO - registerType("horse_saddle", false); // TODO - // LLama registerType("carpet_color", DyeColor.class); // TODO registerType("llama_variant", 0); // TODO @@ -294,6 +294,56 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EncodedIntegerProperty<>("creeper_state", CreeperState.IDLE, creeperIndex++, CreeperState::getState)); register(new BooleanProperty("creeper_charged", creeperIndex, false, legacyBooleans)); + // Abstract Horse + int horseIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) horseIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) horseIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) horseIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) horseIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) horseIndex = 12; + else horseIndex = 16; + int horseEating = ver.isNewerThanOrEquals(ServerVersion.V_1_12) ? 0x10 : 0x20; + boolean v1_8 = ver.isOlderThan(ServerVersion.V_1_9); + register(new BitsetProperty("is_tame", horseIndex, 0x02, false, v1_8)); + register(new BitsetProperty("is_saddled", horseIndex, 0x04, false, v1_8)); + register(new BitsetProperty("is_eating", horseIndex, horseEating, false, v1_8)); + register(new BitsetProperty("is_rearing", horseIndex, horseEating << 1, false, v1_8)); + register(new BitsetProperty("has_mouth_open", horseIndex, horseEating << 2, false, v1_8)); + + // Horse + if (ver.isNewerThanOrEquals(ServerVersion.V_1_8) && ver.isOlderThan(ServerVersion.V_1_9)) { + register(new EncodedByteProperty<>("horse_type", HorseType.HORSE, 19, obj -> (byte) obj.ordinal())); + } else if (ver.isOlderThan(ServerVersion.V_1_11)) { + int horseTypeIndex = 14; + if (ver.isOlderThan(ServerVersion.V_1_10)) horseTypeIndex = 13; + register(new EncodedIntegerProperty<>("horse_type", HorseType.HORSE, horseTypeIndex, Enum::ordinal)); + } + int horseVariantIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_18)) horseVariantIndex = 18; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) horseVariantIndex = 19; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) horseVariantIndex = 18; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) horseVariantIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) horseVariantIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) horseVariantIndex = 14; + else horseVariantIndex = 20; + register(new HorseStyleProperty(horseVariantIndex)); + register(new HorseColorProperty(horseVariantIndex)); + linkProperties("horse_style", "horse_color"); + + // Use chesteplate property for 1.14 and above + if (ver.isOlderThan(ServerVersion.V_1_14)) { + register(new EncodedIntegerProperty<>("horse_armor", HorseArmor.NONE, horseVariantIndex + 2, Enum::ordinal)); + } + + // Chested Horse + if (ver.isOlderThan(ServerVersion.V_1_11)) { + register(new BitsetProperty("has_chest", horseIndex, 0x08, false, v1_8)); + linkProperties("is_saddled", "has_chest", "is_eating", "is_rearing", "has_mouth_open"); + } else { + register(new BooleanProperty("has_chest", horseVariantIndex, false, legacyBooleans)); + linkProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); + } + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java index 579074e..1a1e5f2 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/BitsetProperty.java @@ -12,6 +12,12 @@ public class BitsetProperty extends EntityPropertyImpl { private final int index; private final int bitmask; private final boolean inverted; + private boolean integer = false; + + public BitsetProperty(String name, int index, int bitmask, boolean inverted, boolean integer) { + this(name, index, bitmask, inverted); + this.integer = integer; + } public BitsetProperty(String name, int index, int bitmask, boolean inverted) { super(name, inverted, Boolean.class); @@ -27,9 +33,11 @@ public class BitsetProperty extends EntityPropertyImpl { @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { EntityData oldData = properties.get(index); - byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); boolean enabled = entity.getProperty(this); if (inverted) enabled = !enabled; - properties.put(index, newEntityData(index, EntityDataTypes.BYTE, (byte) (oldValue | (enabled ? bitmask : 0)))); + properties.put(index, + integer ? newEntityData(index, EntityDataTypes.INT, (oldData == null ? 0 : (int) oldData.getValue()) | (enabled ? bitmask : 0)) : + newEntityData(index, EntityDataTypes.BYTE, (byte) ((oldData == null ? 0 : (byte) oldData.getValue()) | (enabled ? bitmask : 0)))); + } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedByteProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedByteProperty.java new file mode 100644 index 0000000..af64b11 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedByteProperty.java @@ -0,0 +1,48 @@ +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 lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class EncodedByteProperty extends EntityPropertyImpl { + private final EntityDataType type; + private final ByteDecoder decoder; + private final int index; + + protected EncodedByteProperty(String name, T defaultValue, Class clazz, int index, ByteDecoder decoder, EntityDataType type) { + super(name, defaultValue, clazz); + this.decoder = decoder; + this.index = index; + this.type = type; + } + + @SuppressWarnings("unchecked") + public EncodedByteProperty(String name, T defaultValue, int index, ByteDecoder decoder) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, EntityDataTypes.BYTE); + } + + @SuppressWarnings("unchecked") + public EncodedByteProperty(String name, T defaultValue, int index, ByteDecoder decoder, EntityDataType type) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, type); + } + + public EncodedByteProperty(String name, Class clazz, int index, ByteDecoder decoder) { + this(name, null, clazz, index, decoder, EntityDataTypes.BYTE); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + T value = entity.getProperty(this); + if (value == null) return; + properties.put(index, newEntityData(index, type, decoder.decode(value))); + } + + public interface ByteDecoder { + byte decode(T obj); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseColorProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseColorProperty.java new file mode 100644 index 0000000..b7b12ed --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseColorProperty.java @@ -0,0 +1,26 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.util.HorseColor; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class HorseColorProperty extends EntityPropertyImpl { + private final int index; + + public HorseColorProperty(int index) { + super("horse_color", HorseColor.WHITE, HorseColor.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + EntityData oldData = properties.get(index); + HorseColor value = entity.getProperty(this); + properties.put(index, newEntityData(index, EntityDataTypes.INT, value.ordinal() | (oldData == null ? 0 : ((int) oldData.getValue() & 0xFF00)))); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseStyleProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseStyleProperty.java new file mode 100644 index 0000000..ebb1b53 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/HorseStyleProperty.java @@ -0,0 +1,26 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.util.HorseStyle; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class HorseStyleProperty extends EntityPropertyImpl { + private final int index; + + public HorseStyleProperty(int index) { + super("horse_style", HorseStyle.NONE, HorseStyle.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + EntityData oldData = properties.get(index); + HorseStyle value = entity.getProperty(this); + properties.put(index, newEntityData(index, EntityDataTypes.INT, (oldData == null ? 0 : ((int) oldData.getValue() & 0x00FF)) | (value.ordinal() << 8))); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 2c8f05c..5a9131e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -91,11 +91,24 @@ public class NpcTypeImpl implements NpcType { addProperties("fire", "invisible", "silent", "look", "using_item", "potion_color", "potion_ambient", "dinnerbone"); if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); - if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) addProperties("pose"); + if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) { + addProperties("pose"); + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.HORSE)) { + addProperties("chestplate"); + } + } if (version.isNewerThanOrEquals(ServerVersion.V_1_17)) addProperties("shaking"); if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_AGEABLE)) { addProperties("baby"); } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_HORSE)) { + addProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); + } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.CHESTED_HORSE)) { + addProperties("has_chest"); + } else if (version.isOlderThan(ServerVersion.V_1_11) && type.equals(EntityTypes.HORSE)) { + addProperties("has_chest"); + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties)); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index ba761c9..6835ead 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -88,7 +88,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(-1.125)); register(builder(p, "horse", EntityTypes.HORSE) - .setHologramOffset(-0.375)); + .setHologramOffset(-0.375) + .addProperties("horse_type", "horse_style", "horse_color", "horse_armor")); register(builder(p, "iron_golem", EntityTypes.IRON_GOLEM) .setHologramOffset(0.725)); From 9bb74de8e6a1d031e0008e7528147409624de6f3 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 26 Aug 2023 22:17:56 +0200 Subject: [PATCH 53/78] add default properties --- .../conversion/citizens/CitizensImporter.java | 2 ++ .../conversion/znpcs/ZNpcImporter.java | 1 + .../pyr/znpcsplus/npc/NpcRegistryImpl.java | 1 + .../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 24 +++++++++++++++++-- .../znpcsplus/npc/NpcTypeRegistryImpl.java | 9 ++++++- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java index 2a17d34..86e3895 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java @@ -82,6 +82,8 @@ public class CitizensImporter implements DataImporter { world = Bukkit.getWorlds().get(0).getName(); } NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world, typeRegistry.getByName("armor_stand"), new NpcLocation(0, 0, 0, 0, 0)); + npc.getType().applyDefaultProperties(npc); + npc.getHologram().addTextLineComponent(textSerializer.deserialize(name)); ConfigurationSection traits = npcSection.getConfigurationSection("traits"); if (traits != null) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java index 202d477..4fa3c76 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java @@ -103,6 +103,7 @@ public class ZNpcImporter implements DataImporter { NpcLocation location = new NpcLocation(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ(), oldLoc.getYaw(), oldLoc.getPitch()); UUID uuid = model.getUuid() == null ? UUID.randomUUID() : model.getUuid(); NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, oldLoc.getWorld(), typeRegistry.getByName(type), location); + npc.getType().applyDefaultProperties(npc); HologramImpl hologram = npc.getHologram(); hologram.setOffset(model.getHologramHeight()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java index 6de6b1e..78ab624 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java @@ -139,6 +139,7 @@ public class NpcRegistryImpl implements NpcRegistry { id = id.toLowerCase(); if (npcIdLookupMap.containsKey(id)) throw new IllegalArgumentException("An npc with the id " + id + " already exists!"); NpcImpl npc = new NpcImpl(UUID.randomUUID(), propertyRegistry, configManager, textSerializer, world, type, location, packetFactory); + type.applyDefaultProperties(npc); NpcEntryImpl entry = new NpcEntryImpl(id, npc); register(entry); return entry; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 5a9131e..6c42efe 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -16,14 +16,16 @@ import java.util.stream.Collectors; public class NpcTypeImpl implements NpcType { private final EntityType type; private final Set> allowedProperties; + private final Map, Object> defaultProperties; private final String name; private final double hologramOffset; - private NpcTypeImpl(String name, EntityType type, double hologramOffset, Set> allowedProperties) { + private NpcTypeImpl(String name, EntityType type, double hologramOffset, Set> allowedProperties, Map, Object> defaultProperties) { this.name = name.toLowerCase(); this.type = type; this.hologramOffset = hologramOffset; this.allowedProperties = allowedProperties; + this.defaultProperties = defaultProperties; } public String getName() { @@ -42,6 +44,12 @@ public class NpcTypeImpl implements NpcType { return allowedProperties.stream().map(property -> (EntityProperty) property).collect(Collectors.toSet()); } + public void applyDefaultProperties(NpcImpl npc) { + for (Map.Entry, Object> entry : defaultProperties.entrySet()) { + npc.UNSAFE_setProperty(entry.getKey(), entry.getValue()); + } + } + protected static final class Builder { private final static Logger logger = Logger.getLogger("NpcTypeBuilder"); @@ -49,6 +57,7 @@ public class NpcTypeImpl implements NpcType { private final String name; private final EntityType type; private final List> allowedProperties = new ArrayList<>(); + private final Map, Object> defaultProperties = new HashMap<>(); private double hologramOffset = 0; Builder(EntityPropertyRegistryImpl propertyRegistry, String name, EntityType type) { @@ -81,6 +90,17 @@ public class NpcTypeImpl implements NpcType { return this; } + @SuppressWarnings("unchecked") + public Builder addDefaultProperty(String name, T value) { + EntityPropertyImpl property = (EntityPropertyImpl) propertyRegistry.getByName(name); + if (property == null) { + logger.warning("Tried to register the non-existent \"" + name + "\" default property to the \"" + this.name + "\" npc type"); + return this; + } + defaultProperties.put(property, value); + return this; + } + public Builder setHologramOffset(double hologramOffset) { this.hologramOffset = hologramOffset; return this; @@ -109,7 +129,7 @@ public class NpcTypeImpl implements NpcType { } else if (version.isOlderThan(ServerVersion.V_1_11) && type.equals(EntityTypes.HORSE)) { addProperties("has_chest"); } - return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties)); + return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 6835ead..bcb0856 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -36,7 +36,14 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "player", EntityTypes.PLAYER) .setHologramOffset(-0.15D) .addEquipmentProperties() - .addProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat", "shoulder_entity_left", "shoulder_entity_right")); + .addProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat", "shoulder_entity_left", "shoulder_entity_right") + .addDefaultProperty("skin_cape", true) + .addDefaultProperty("skin_jacket", true) + .addDefaultProperty("skin_left_sleeve", true) + .addDefaultProperty("skin_right_sleeve", true) + .addDefaultProperty("skin_left_leg", true) + .addDefaultProperty("skin_right_leg", true) + .addDefaultProperty("skin_hat", true)); // Most hologram offsets generated using Entity#getHeight() in 1.19.4 From 5948993346061af9dae3cad3c20e9435afaf88a1 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 26 Aug 2023 22:19:58 +0200 Subject: [PATCH 54/78] remove using_item from default properties since it does nothing for most types --- plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 6c42efe..b22810a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -109,7 +109,7 @@ public class NpcTypeImpl implements NpcType { public NpcTypeImpl build() { ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); addProperties("fire", "invisible", "silent", "look", - "using_item", "potion_color", "potion_ambient", "dinnerbone"); + "potion_color", "potion_ambient", "dinnerbone"); if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) { addProperties("pose"); From 86e021f2776429467777f4dc97b752421c149c8c Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 26 Aug 2023 22:23:24 +0200 Subject: [PATCH 55/78] delete metadata classes --- .../znpcsplus/metadata/MetadataFactory.java | 56 --------- .../metadata/V1_10MetadataFactory.java | 29 ----- .../metadata/V1_11MetadataFactory.java | 17 --- .../metadata/V1_12MetadataFactory.java | 33 ------ .../metadata/V1_13MetadataFactory.java | 13 --- .../metadata/V1_14MetadataFactory.java | 57 ---------- .../metadata/V1_15MetadataFactory.java | 45 -------- .../metadata/V1_16MetadataFactory.java | 6 - .../metadata/V1_17MetadataFactory.java | 76 ------------- .../metadata/V1_19MetadataFactory.java | 12 -- .../metadata/V1_8MetadataFactory.java | 106 ------------------ .../metadata/V1_9MetadataFactory.java | 29 ----- 12 files changed, 479 deletions(-) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java deleted file mode 100644 index e73973f..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; -import lol.pyr.znpcsplus.util.CreeperState; -import lol.pyr.znpcsplus.util.ParrotVariant; - -/** - * 1.8 ... - * 1.9 ... - * 1.10 ... - * 1.11 ... - * 1.12 ... - * 1.13 ... - * 1.14 ... - * 1.15 ... - * 1.16 ... - * 1.17 ... - * 1.18-1.19 ... - * 1.20 ... - */ -@Deprecated -public interface MetadataFactory { - - EntityData pose(EntityPose pose); - - EntityData usingItem(boolean enabled, boolean offhand, boolean riptide); - - EntityData shoulderEntityLeft(ParrotVariant variant); - EntityData shoulderEntityRight(ParrotVariant variant); - - // Axolotl - EntityData axolotlVariant(int variant); - EntityData playingDead(boolean playingDead); - - // Blaze - EntityData blazeOnFire(boolean onFire); - - // Creeper - EntityData creeperState(CreeperState state); - EntityData creeperCharged(boolean charged); - - // Enderman - EntityData endermanHeldBlock(int heldBlock); - EntityData endermanScreaming(boolean screaming); - EntityData endermanStaring(boolean staring); - - // Evoker - EntityData evokerSpell(int spell); - - // Frog - EntityData frogVariant(int variant); - - // Villager - EntityData villagerData(int type, int profession, int level); -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java deleted file mode 100644 index d6669c4..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_10MetadataFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import lol.pyr.znpcsplus.util.CreeperState; - -@Deprecated -public class V1_10MetadataFactory extends V1_9MetadataFactory { - - @Override - public EntityData blazeOnFire(boolean onFire) { - return newEntityData(12, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); - } - - @Override - public EntityData creeperState(CreeperState state) { - return newEntityData(12, EntityDataTypes.INT, state.getState()); - } - - @Override - public EntityData creeperCharged(boolean charged) { - return newEntityData(13, EntityDataTypes.BOOLEAN, charged); - } - - @Override - public EntityData villagerData(int type, int profession, int level) { - return newEntityData(13, EntityDataTypes.INT, profession); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java deleted file mode 100644 index fb68a00..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_11MetadataFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; - -@Deprecated -public class V1_11MetadataFactory extends V1_10MetadataFactory { - @Override - public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { - return newEntityData(6, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0))); - } - - @Override - public EntityData evokerSpell(int spell) { - return newEntityData(12, EntityDataTypes.BYTE, (byte) spell); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java deleted file mode 100644 index 66660b4..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_12MetadataFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; -import lol.pyr.znpcsplus.entity.ParrotNBTCompound; -import lol.pyr.znpcsplus.util.ParrotVariant; - -@Deprecated -public class V1_12MetadataFactory extends V1_11MetadataFactory { - @Override - public EntityData shoulderEntityLeft(ParrotVariant variant) { - return createShoulderEntityLeft(15, variant); - } - - public EntityData createShoulderEntityLeft(int index, ParrotVariant variant) { - return newEntityData(index, EntityDataTypes.NBT, variant == ParrotVariant.NONE ? new NBTCompound() : new ParrotNBTCompound(variant).getTag()); - } - - @Override - public EntityData shoulderEntityRight(ParrotVariant variant) { - return createShoulderEntityRight(16, variant); - } - - public EntityData createShoulderEntityRight(int index, ParrotVariant variant) { - return newEntityData(index, EntityDataTypes.NBT, variant == ParrotVariant.NONE ? new NBTCompound() : new ParrotNBTCompound(variant).getTag()); - } - - @Override - public EntityData evokerSpell(int spell) { - return newEntityData(13, EntityDataTypes.BYTE, (byte) spell); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java deleted file mode 100644 index 6f127a6..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_13MetadataFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; - -@Deprecated -public class V1_13MetadataFactory extends V1_12MetadataFactory { - - @Override - public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { - return newEntityData(6, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0) | (riptide ? 0x04 : 0))); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java deleted file mode 100644 index eebf156..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_14MetadataFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; -import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; -import lol.pyr.znpcsplus.util.CreeperState; -import lol.pyr.znpcsplus.util.ParrotVariant; - -@Deprecated -public class V1_14MetadataFactory extends V1_13MetadataFactory { - - @Override - public EntityData pose(EntityPose pose) { - return newEntityData(6, EntityDataTypes.ENTITY_POSE, pose); - } - - @Override - public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { - return newEntityData(7, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0) | (riptide ? 0x04 : 0))); - } - - @Override - public EntityData shoulderEntityLeft(ParrotVariant variant) { - return createShoulderEntityLeft(17, variant); - } - - @Override - public EntityData shoulderEntityRight(ParrotVariant variant) { - return createShoulderEntityRight(18, variant); - } - - @Override - public EntityData blazeOnFire(boolean onFire) { - return newEntityData(14, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); - } - - @Override - public EntityData creeperState(CreeperState state) { - return newEntityData(14, EntityDataTypes.INT, state.getState()); - } - - @Override - public EntityData creeperCharged(boolean charged) { - return newEntityData(15, EntityDataTypes.BOOLEAN, charged); - } - - @Override - public EntityData evokerSpell(int spell) { - return newEntityData(15, EntityDataTypes.BYTE, (byte) spell); - } - - @Override - public EntityData villagerData(int type, int profession, int level) { - return newEntityData(16, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java deleted file mode 100644 index 5a3f1b3..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_15MetadataFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; -import lol.pyr.znpcsplus.util.CreeperState; -import lol.pyr.znpcsplus.util.ParrotVariant; - -@Deprecated -public class V1_15MetadataFactory extends V1_14MetadataFactory { - @Override - public EntityData shoulderEntityLeft(ParrotVariant variant) { - return createShoulderEntityLeft(18, variant); - } - - @Override - public EntityData shoulderEntityRight(ParrotVariant variant) { - return createShoulderEntityRight(19, variant); - } - - @Override - public EntityData blazeOnFire(boolean onFire) { - return newEntityData(15, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); - } - - @Override - public EntityData creeperState(CreeperState state) { - return newEntityData(15, EntityDataTypes.INT, state.getState()); - } - - @Override - public EntityData creeperCharged(boolean charged) { - return newEntityData(16, EntityDataTypes.BOOLEAN, charged); - } - - @Override - public EntityData evokerSpell(int spell) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) spell); - } - - @Override - public EntityData villagerData(int type, int profession, int level) { - return newEntityData(17, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java deleted file mode 100644 index d1c3c6f..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_16MetadataFactory.java +++ /dev/null @@ -1,6 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -@Deprecated -public class V1_16MetadataFactory extends V1_15MetadataFactory { - -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java deleted file mode 100644 index 38a3a7f..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; -import lol.pyr.znpcsplus.util.CreeperState; -import lol.pyr.znpcsplus.util.ParrotVariant; - -@Deprecated -public class V1_17MetadataFactory extends V1_16MetadataFactory { - - @Override - public EntityData usingItem(boolean usingItem, boolean offHand, boolean riptide) { - return newEntityData(8, EntityDataTypes.BYTE, (byte) ((usingItem ? 0x01 : 0) | (offHand ? 0x02 : 0) | (riptide ? 0x04 : 0))); - } - - @Override - public EntityData shoulderEntityLeft(ParrotVariant variant) { - return createShoulderEntityLeft(19, variant); - } - - @Override - public EntityData shoulderEntityRight(ParrotVariant variant) { - return createShoulderEntityRight(20, variant); - } - - @Override - public EntityData axolotlVariant(int variant) { - return newEntityData(17, EntityDataTypes.INT, variant); - } - - @Override - public EntityData playingDead(boolean playingDead) { - return newEntityData(18, EntityDataTypes.BOOLEAN, playingDead); - } - - @Override - public EntityData blazeOnFire(boolean onFire) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0)); - } - - @Override - public EntityData creeperState(CreeperState state) { - return newEntityData(16, EntityDataTypes.INT, state.getState()); - } - - @Override - public EntityData creeperCharged(boolean charged) { - return newEntityData(17, EntityDataTypes.BOOLEAN, charged); - } - - @Override - public EntityData endermanHeldBlock(int carriedBlock) { - return newEntityData(16, EntityDataTypes.INT, carriedBlock); - } - - @Override - public EntityData endermanScreaming(boolean screaming) { - return newEntityData(17, EntityDataTypes.BOOLEAN, screaming); - } - - @Override - public EntityData endermanStaring(boolean staring) { - return newEntityData(18, EntityDataTypes.BOOLEAN, staring); - } - - @Override - public EntityData evokerSpell(int spell) { - return newEntityData(17, EntityDataTypes.BYTE, (byte) spell); - } - - @Override - public EntityData villagerData(int type, int profession, int level) { - return newEntityData(18, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level)); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java deleted file mode 100644 index c39fb4a..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_19MetadataFactory.java +++ /dev/null @@ -1,12 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; - -@Deprecated -public class V1_19MetadataFactory extends V1_17MetadataFactory { - @Override - public EntityData frogVariant(int variant) { - return newEntityData(17, EntityDataTypes.FROG_VARIANT, variant); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java deleted file mode 100644 index 4cb3cf7..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ /dev/null @@ -1,106 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -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.protocol.entity.pose.EntityPose; -import lol.pyr.znpcsplus.util.*; - -@Deprecated -public class V1_8MetadataFactory implements MetadataFactory { - - @Override - public EntityData pose(EntityPose pose) { - throw new UnsupportedOperationException("The pose entity data isn't supported on this version"); - } - - @Override - public EntityData usingItem(boolean enabled, boolean offHand, boolean riptide) { - throw new UnsupportedOperationException("The standalone using item data isn't supported on this version"); - } - - @Override - public EntityData shoulderEntityLeft(ParrotVariant variant) { - throw new UnsupportedOperationException("The shoulder entity data isn't supported on this version"); - } - - @Override - public EntityData shoulderEntityRight(ParrotVariant variant) { - throw new UnsupportedOperationException("The shoulder entity data isn't supported on this version"); - } - - @Override - public EntityData axolotlVariant(int variant) { - throw new UnsupportedOperationException("The axolotl variant entity data isn't supported on this version"); - } - - @Override - public EntityData playingDead(boolean playingDead) { - throw new UnsupportedOperationException("The playing dead entity data isn't supported on this version"); - } - - @Override - public EntityData blazeOnFire(boolean onFire) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 1 : 0)); - } - - @Override - public EntityData creeperState(CreeperState state) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) state.getState()); - } - - @Override - public EntityData creeperCharged(boolean charged) { - return newEntityData(17, EntityDataTypes.BYTE, (byte) (charged ? 1 : 0)); - } - - @Override - public EntityData endermanHeldBlock(int carriedBlock) { - throw new UnsupportedOperationException("The enderman carried block entity data isn't supported on this version"); - } - - @Override - public EntityData endermanScreaming(boolean screaming) { - throw new UnsupportedOperationException("The enderman screaming entity data isn't supported on this version"); - } - - @Override - public EntityData endermanStaring(boolean staring) { - return newEntityData(18, EntityDataTypes.BOOLEAN, staring); - } - - @Override - public EntityData evokerSpell(int spell) { - throw new UnsupportedOperationException("The evoker spell entity data isn't supported on this version"); - } - - @Override - public EntityData frogVariant(int variant) { - throw new UnsupportedOperationException("The frog variant entity data isn't supported on this version"); - } - - @Override - public EntityData villagerData(int type, int profession, int level) { - return newEntityData(16, EntityDataTypes.INT, profession); - } - - protected EntityData createSkinLayers(int index, boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) { - return newEntityData(index, EntityDataTypes.BYTE, (byte) ( - (cape ? 0x01 : 0) | - (jacket ? 0x02 : 0) | - (leftSleeve ? 0x04 : 0) | - (rightSleeve ? 0x08 : 0) | - (leftLeg ? 0x10 : 0) | - (rightLeg ? 0x20 : 0) | - (hat ? 0x40 : 0)) - ); - } - - protected EntityData newEntityData(int index, EntityDataType type, T value) { - return new EntityData(index, type, value); - } - - protected EntityData createRotations(int index, Vector3f rotations) { - return newEntityData(index, EntityDataTypes.ROTATION, new com.github.retrooper.packetevents.util.Vector3f(rotations.getX(), rotations.getY(), rotations.getZ())); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java deleted file mode 100644 index 1a4ce69..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_9MetadataFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -package lol.pyr.znpcsplus.metadata; - -import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; -import lol.pyr.znpcsplus.util.CreeperState; - -@Deprecated -public class V1_9MetadataFactory extends V1_8MetadataFactory { - - @Override - public EntityData blazeOnFire(boolean onFire) { - return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 1 : 0)); - } - - @Override - public EntityData creeperState(CreeperState state) { - return newEntityData(11, EntityDataTypes.INT, state.getState()); - } - - @Override - public EntityData creeperCharged(boolean charged) { - return newEntityData(12, EntityDataTypes.BOOLEAN, charged); - } - - @Override - public EntityData villagerData(int type, int profession, int level) { - return newEntityData(12, EntityDataTypes.INT, profession); - } -} From dd029786ddcccbe4e62b963fb4083d4c4d4fab7d Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Thu, 31 Aug 2023 09:23:50 +0530 Subject: [PATCH 56/78] fixed placeholder not working in name property --- .../java/lol/pyr/znpcsplus/entity/properties/NameProperty.java | 2 ++ 1 file changed, 2 insertions(+) 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 ec57fcd..e3b7230 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 @@ -5,6 +5,7 @@ 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 lol.pyr.znpcsplus.util.PapiUtil; import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; @@ -29,6 +30,7 @@ public class NameProperty extends EntityPropertyImpl { String serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) : AdventureSerializer.getGsonSerializer().serialize(value); + serialized = PapiUtil.set(player, serialized); if (optional) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized))); else properties.put(2, newEntityData(2, EntityDataTypes.STRING, serialized)); } From 0569df795bf30b0ffac59cfb639b280a63b79dd1 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 14:31:38 +0530 Subject: [PATCH 57/78] added spell property --- .../commands/property/PropertySetCommand.java | 20 +++++++++++++++++++ .../entity/EntityPropertyRegistryImpl.java | 14 +++++++++---- .../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 3 +++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 752f8cb..d8e7a21 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -1,5 +1,7 @@ package lol.pyr.znpcsplus.commands.property; +import com.github.retrooper.packetevents.PacketEvents; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState; import com.github.retrooper.packetevents.protocol.world.states.type.StateType; import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes; @@ -18,6 +20,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; import com.github.retrooper.packetevents.protocol.item.ItemStack; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -96,6 +99,20 @@ public class PropertySetCommand implements CommandHandler { return; } } + else if (type == SpellType.class) { + if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_13)) { + value = context.parse(type); + valueName = String.valueOf(value); + if (((SpellType) value).ordinal() > 3) { + context.send(Component.text("Spell type " + valueName + " is not supported on this version", NamedTextColor.RED)); + return; + } + } + else { + value = context.parse(type); + valueName = String.valueOf(value); + } + } else { value = context.parse(type); valueName = String.valueOf(value); @@ -119,6 +136,9 @@ public class PropertySetCommand implements CommandHandler { if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys()); if (type == Color.class) return context.suggestLiteral("0x0F00FF", "#FFFFFF"); if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block"); + if (type == SpellType.class) return PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_13) ? + context.suggestEnum(Arrays.stream(SpellType.values()).filter(spellType -> spellType.ordinal() <= 3).toArray(SpellType[]::new)) : + context.suggestEnum(SpellType.values()); // Suggest enum values directly if (type.isEnum()) { 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 56d8788..a18b539 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -84,9 +84,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("enderman_screaming", false); // TODO registerType("enderman_staring", false); // TODO - // Evoker - registerType("evoker_spell", SpellType.NONE); - // Frog registerType("frog_variant", FrogVariant.TEMPERATE); @@ -271,7 +268,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) batIndex = 12; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) batIndex = 11; else batIndex = 16; - register(new BooleanProperty("hanging", batIndex, false, true /* This isnt a mistake */)); + register(new BooleanProperty("hanging", batIndex, false, true /* This isn't a mistake */)); // Blaze final int blazeIndex; @@ -344,6 +341,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); } + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; + // Spellcaster Illager + int spellIndex = 12; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) spellIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) spellIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) spellIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_12)) spellIndex = 13; + register(new EncodedByteProperty<>("spell", SpellType.NONE, spellIndex, obj -> (byte) Math.min(obj.ordinal(), ver.isOlderThan(ServerVersion.V_1_13) ? 3 : 5))); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index b22810a..81fa7b0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -129,6 +129,9 @@ public class NpcTypeImpl implements NpcType { } else if (version.isOlderThan(ServerVersion.V_1_11) && type.equals(EntityTypes.HORSE)) { addProperties("has_chest"); } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_EVO_ILLU_ILLAGER)) { + addProperties("spell"); + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } From ddbdd8f78c3182879ca42a5851c8c4d974548abe Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 15:25:38 +0530 Subject: [PATCH 58/78] added frog_variant property --- .../pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 a18b539..cb2f042 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -84,9 +84,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("enderman_screaming", false); // TODO registerType("enderman_staring", false); // TODO - // Frog - registerType("frog_variant", FrogVariant.TEMPERATE); - // Guardian registerType("is_elder", false); // TODO: ensure it only works till 1.10. Note: index is wrong on wiki.vg @@ -404,6 +401,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BooleanProperty("has_right_horn", 19, true, legacyBooleans)); register(new EncodedIntegerProperty<>("shaking", false,7, enabled -> enabled ? 140 : 0)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_19)) return; + // Frog + register(new EncodedIntegerProperty<>("frog_variant", FrogVariant.TEMPERATE, 17, Enum::ordinal, EntityDataTypes.FROG_VARIANT)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_20)) return; From 1010a18e71e37f9f05861c9dfc3082a78bd0cd2a Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 15:26:47 +0530 Subject: [PATCH 59/78] partial implementation of target npc property --- .../commands/property/PropertySetCommand.java | 4 +++ .../entity/properties/TargetNpcProperty.java | 29 +++++++++++++++++++ .../TargetNpcPropertySerializer.java | 21 ++++++++++++++ .../znpcsplus/npc/NpcTypeRegistryImpl.java | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/TargetNpcProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/TargetNpcPropertySerializer.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index d8e7a21..3ea0074 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -113,6 +113,10 @@ public class PropertySetCommand implements CommandHandler { valueName = String.valueOf(value); } } + else if (type == NpcEntryImpl.class) { + value = context.parse(type); + valueName = value == null ? "NONE" : ((NpcEntryImpl) value).getId(); + } else { value = context.parse(type); valueName = String.valueOf(value); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/TargetNpcProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/TargetNpcProperty.java new file mode 100644 index 0000000..fbe4beb --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/TargetNpcProperty.java @@ -0,0 +1,29 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class TargetNpcProperty extends EntityPropertyImpl { + private final int index; + + public TargetNpcProperty(String name, int index, NpcEntryImpl defaultValue) { + super(name, defaultValue, NpcEntryImpl.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + NpcEntryImpl value = entity.getProperty(this); + if (value == null) return; + if (value.getNpc().getEntity().getEntityId() == entity.getEntityId()) return; + if (value.getNpc().isVisibleTo(player)) { + properties.put(index, newEntityData(index, EntityDataTypes.INT, value.getNpc().getEntity().getEntityId())); + } + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/TargetNpcPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/TargetNpcPropertySerializer.java new file mode 100644 index 0000000..7cd3654 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/TargetNpcPropertySerializer.java @@ -0,0 +1,21 @@ +package lol.pyr.znpcsplus.entity.serializers; + +import lol.pyr.znpcsplus.entity.PropertySerializer; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; + +public class TargetNpcPropertySerializer implements PropertySerializer { + @Override + public String serialize(NpcEntryImpl property) { + return property.getId(); + } + + @Override + public NpcEntryImpl deserialize(String property) { + return null; // TODO: find a way to do this + } + + @Override + public Class getTypeClass() { + return NpcEntryImpl.class; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index bcb0856..509e246 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -329,7 +329,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "frog", EntityTypes.FROG) .setHologramOffset(-1.475) - .addProperties("frog_variant")); + .addProperties("frog_variant", "frog_target_npc")); register(builder(p, "tadpole", EntityTypes.TADPOLE) .setHologramOffset(-1.675)); From 488b9ccb5b26227ed9d60366e8d812e150a1c03d Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 15:53:27 +0530 Subject: [PATCH 60/78] small fix for immune to zombification property --- .../lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 3 ++- plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 3 +++ .../main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) 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 cb2f042..c99bee1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -389,7 +389,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { final int zombificationIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) zombificationIndex = 17; else zombificationIndex = 16; - register(new BooleanProperty("immune_to_zombification", zombificationIndex, false, legacyBooleans)); + register(new BooleanProperty("hoglin_immune_to_zombification", zombificationIndex, false, legacyBooleans)); + register(new BooleanProperty("piglin_immune_to_zombification", zombificationIndex-1, false, legacyBooleans)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; // Axolotl diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 81fa7b0..7b59802 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -132,6 +132,9 @@ public class NpcTypeImpl implements NpcType { if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_EVO_ILLU_ILLAGER)) { addProperties("spell"); } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_PIGLIN)) { + addProperties("piglin_immune_to_zombification"); + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 509e246..5821f46 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -292,7 +292,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "hoglin", EntityTypes.HOGLIN) .setHologramOffset(-0.575) - .addProperties("immune_to_zombification")); + .addProperties("hoglin_immune_to_zombification")); register(builder(p, "piglin", EntityTypes.PIGLIN) .setHologramOffset(-1.0) From 81b087628bc920ddda43f2cabd780479f305b5c5 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 16:09:55 +0530 Subject: [PATCH 61/78] added baby property for zombie (and types) and zoglin --- plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 7b59802..de2afdf 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -118,7 +118,7 @@ public class NpcTypeImpl implements NpcType { } } if (version.isNewerThanOrEquals(ServerVersion.V_1_17)) addProperties("shaking"); - if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_AGEABLE)) { + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_AGEABLE) || EntityTypes.isTypeInstanceOf(type, EntityTypes.ZOMBIE) || EntityTypes.isTypeInstanceOf(type, EntityTypes.ZOGLIN)) { addProperties("baby"); } if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_HORSE)) { From 2c601c450d2c3c6b8f9894a4d25bd06de45aa5a5 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 16:45:39 +0530 Subject: [PATCH 62/78] added llama properties --- .../lol/pyr/znpcsplus/util/LlamaVariant.java | 8 ++++++++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 19 +++++++++++-------- .../znpcsplus/npc/NpcTypeRegistryImpl.java | 6 ++++-- 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/LlamaVariant.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/LlamaVariant.java b/api/src/main/java/lol/pyr/znpcsplus/util/LlamaVariant.java new file mode 100644 index 0000000..be5cdc9 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/LlamaVariant.java @@ -0,0 +1,8 @@ +package lol.pyr.znpcsplus.util; + +public enum LlamaVariant { + CREAMY, + WHITE, + BROWN, + GRAY +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index d414ead..be5f764 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -270,6 +270,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, HorseStyle.class, incorrectUsageMessage); registerEnumParser(manager, HorseColor.class, incorrectUsageMessage); registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage); + registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 c99bee1..821660f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -63,6 +63,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(HorseColor.class); registerEnumSerializer(HorseStyle.class); registerEnumSerializer(HorseArmor.class); + registerEnumSerializer(LlamaVariant.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -75,10 +76,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("beam_target", null); // TODO: Make a block pos class for this registerType("show_base", true); // TODO - // Creeper - registerType("creeper_state", CreeperState.IDLE); - registerType("creeper_charged", false); - // Enderman registerType("enderman_held_block", new BlockState(0)); // TODO: figure out the type on this registerType("enderman_screaming", false); // TODO @@ -96,10 +93,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Sniffer registerType("sniffer_state", null); // TODO: Nothing on wiki.vg, look in mc source - // LLama - registerType("carpet_color", DyeColor.class); // TODO - registerType("llama_variant", 0); // TODO - // Panda registerType("panda_sneezing", false); // TODO registerType("panda_rolling", false); // TODO @@ -347,6 +340,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_12)) spellIndex = 13; register(new EncodedByteProperty<>("spell", SpellType.NONE, spellIndex, obj -> (byte) Math.min(obj.ordinal(), ver.isOlderThan(ServerVersion.V_1_13) ? 3 : 5))); + // Llama + int llamaIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_18)) llamaIndex = 20; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) llamaIndex = 21; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) llamaIndex = 20; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) llamaIndex = 19; + else llamaIndex = 17; + register(new EncodedIntegerProperty("carpet_color", DyeColor.class, llamaIndex++, obj -> obj == null ? -1 : obj.ordinal())); + register(new EncodedIntegerProperty<>("llama_variant", LlamaVariant.CREAMY, llamaIndex, Enum::ordinal)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 5821f46..fd6f865 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -202,7 +202,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .addProperties("evoker_spell")); register(builder(p, "llama", EntityTypes.LLAMA) - .setHologramOffset(-0.105)); + .setHologramOffset(-0.105) + .addProperties("carpet_color", "llama_variant")); register(builder(p, "vex", EntityTypes.VEX) .setHologramOffset(-1.175) @@ -276,7 +277,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(0.225)); register(builder(p, "trader_llama", EntityTypes.TRADER_LLAMA) - .setHologramOffset(-0.105)); + .setHologramOffset(-0.105) + .addProperties("llama_variant")); register(builder(p, "wandering_trader", EntityTypes.WANDERING_TRADER) .setHologramOffset(-0.025) From f28de908dacc679c1d2cd8341c7a42689b6b959e Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 17:20:40 +0530 Subject: [PATCH 63/78] added size property for Slime, Magma Cube and Phantom --- .../znpcsplus/entity/EntityPropertyRegistryImpl.java | 12 ++++++++++-- .../znpcsplus/entity/properties/IntegerProperty.java | 12 ++++++++++-- .../main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 3 +++ 3 files changed, 23 insertions(+), 4 deletions(-) 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 821660f..b9d3e0a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -149,8 +149,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Phantom registerType("phantom_size", 0); // TODO - // Slime - registerType("slime_size", 0); // TODO */ } @@ -331,6 +329,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); } + // Slime and Magma Cube + int sizeIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) sizeIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) sizeIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) sizeIndex = 14; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) sizeIndex = 12; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) sizeIndex = 11; + else sizeIndex = 16; + register(new IntegerProperty("size", sizeIndex, 1, v1_8)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; // Spellcaster Illager int spellIndex = 12; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java index 2fe1c35..26f42c4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/IntegerProperty.java @@ -10,14 +10,22 @@ import java.util.Map; public class IntegerProperty extends EntityPropertyImpl { private final int index; + private final boolean legacy; - protected IntegerProperty(String name, int index, Integer defaultValue) { + public IntegerProperty(String name, int index, Integer defaultValue) { + this(name, index, defaultValue, false); + } + + public IntegerProperty(String name, int index, Integer defaultValue, boolean legacy) { super(name, defaultValue, Integer.class); this.index = index; + this.legacy = legacy; } @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - properties.put(index, newEntityData(index, EntityDataTypes.INT, entity.getProperty(this))); + properties.put(index, legacy ? + newEntityData(index, EntityDataTypes.BYTE, (byte) entity.getProperty(this).intValue()) : + newEntityData(index, EntityDataTypes.INT, entity.getProperty(this))); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index de2afdf..5d72cbf 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -135,6 +135,9 @@ public class NpcTypeImpl implements NpcType { if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_PIGLIN)) { addProperties("piglin_immune_to_zombification"); } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.SLIME) || EntityTypes.isTypeInstanceOf(type, EntityTypes.PHANTOM)) { + addProperties("size"); + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } From 14ded1ea496cd4cabd2a8e621d48dac12180e0eb Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 17:35:52 +0530 Subject: [PATCH 64/78] fix for null serializer when saving npcs --- .../main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 336deab..8325cc9 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -108,6 +108,10 @@ public class YamlStorage implements NpcStorage { for (EntityProperty property : npc.getAppliedProperties()) { PropertySerializer serializer = propertyRegistry.getSerializer(((EntityPropertyImpl) property).getType()); + if (serializer == null) { + Bukkit.getLogger().log(Level.WARNING, "Unknown serializer for property '" + property.getName() + "' for npc '" + entry.getId() + "'. skipping ..."); + continue; + } config.set("properties." + property.getName(), serializer.UNSAFE_serialize(npc.getProperty(property))); } From 55308d6a790572b4fc4939135abfa7ca0cd0d91f Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 17:37:09 +0530 Subject: [PATCH 65/78] added integer property serializer. oops --- .../entity/EntityPropertyRegistryImpl.java | 1 + .../IntegerPropertySerializer.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java 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 b9d3e0a..634ca08 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -46,6 +46,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerSerializer(new ColorPropertySerializer()); registerSerializer(new Vector3fPropertySerializer()); registerSerializer(new BlockStatePropertySerializer()); + registerSerializer(new IntegerPropertySerializer()); registerEnumSerializer(NpcPose.class); registerEnumSerializer(DyeColor.class); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java new file mode 100644 index 0000000..4ef2ff5 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java @@ -0,0 +1,26 @@ +package lol.pyr.znpcsplus.entity.serializers; + +import lol.pyr.znpcsplus.entity.PropertySerializer; + +public class IntegerPropertySerializer implements PropertySerializer { + @Override + public String serialize(Integer property) { + return String.valueOf(property); + } + + @Override + public Integer deserialize(String property) { + int i = 0; + try { + i = Integer.parseInt(property); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + return i; + } + + @Override + public Class getTypeClass() { + return Integer.class; + } +} From 0127af865b95141d5aeb4c9166e3496e9e719db7 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 18:49:05 +0530 Subject: [PATCH 66/78] Added mooshroom_variant property --- .../pyr/znpcsplus/util/MooshroomVariant.java | 10 ++++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 10 ++-- .../properties/EncodedStringProperty.java | 48 +++++++++++++++++++ .../znpcsplus/npc/NpcTypeRegistryImpl.java | 3 +- 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/MooshroomVariant.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedStringProperty.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/MooshroomVariant.java b/api/src/main/java/lol/pyr/znpcsplus/util/MooshroomVariant.java new file mode 100644 index 0000000..f79fa0b --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/MooshroomVariant.java @@ -0,0 +1,10 @@ +package lol.pyr.znpcsplus.util; + +public enum MooshroomVariant { + RED, + BROWN; + + public static String getVariantName(MooshroomVariant variant) { + return variant.name().toLowerCase(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index be5f764..03d4202 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -271,6 +271,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, HorseColor.class, incorrectUsageMessage); registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage); registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage); + registerEnumParser(manager, MooshroomVariant.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 634ca08..cc44222 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -65,6 +65,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(HorseStyle.class); registerEnumSerializer(HorseArmor.class); registerEnumSerializer(LlamaVariant.class); + registerEnumSerializer(MooshroomVariant.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -147,9 +148,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Wither registerType("invulnerable_time", 0); // TODO - // Phantom - registerType("phantom_size", 0); // TODO - */ } @@ -384,6 +382,12 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("fox_sleeping", foxIndex, 0x20)); linkProperties("fox_sitting", "fox_crouching", "fox_sleeping"); + int mooshroomIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) mooshroomIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) mooshroomIndex = 16; + else mooshroomIndex = 15; + register(new EncodedStringProperty<>("mooshroom_variant", MooshroomVariant.RED, mooshroomIndex, MooshroomVariant::getVariantName)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_15)) return; register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedStringProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedStringProperty.java new file mode 100644 index 0000000..84e0cd1 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EncodedStringProperty.java @@ -0,0 +1,48 @@ +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 lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class EncodedStringProperty extends EntityPropertyImpl { + private final EntityDataType type; + private final EncodedStringProperty.StringDecoder decoder; + private final int index; + + public EncodedStringProperty(String name, T defaultValue, Class clazz, int index, StringDecoder decoder, EntityDataType type) { + super(name, defaultValue, clazz); + this.decoder = decoder; + this.index = index; + this.type = type; + } + + @SuppressWarnings("unchecked") + public EncodedStringProperty(String name, T defaultValue, int index, StringDecoder decoder) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, EntityDataTypes.STRING); + } + + @SuppressWarnings("unchecked") + public EncodedStringProperty(String name, T defaultValue, int index, StringDecoder decoder, EntityDataType type) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, type); + } + + public EncodedStringProperty(String name, Class clazz, int index, StringDecoder decoder) { + this(name, null, clazz, index, decoder, EntityDataTypes.STRING); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + T value = entity.getProperty(this); + if (value == null) return; + properties.put(index, newEntityData(index, type, decoder.decode(value))); + } + + public interface StringDecoder { + String decode(T obj); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index fd6f865..ee5401f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -104,7 +104,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "magma_cube", EntityTypes.MAGMA_CUBE)); // TODO: Hologram offset scaling with size property register(builder(p, "mooshroom", EntityTypes.MOOSHROOM) - .setHologramOffset(-0.575)); + .setHologramOffset(-0.575) + .addProperties("mooshroom_variant")); register(builder(p, "ocelot", EntityTypes.OCELOT) .setHologramOffset(-1.275)); From 1008d31df082b3b06a1fac19e6074f7a57f261fb Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 11 Sep 2023 18:11:36 +0530 Subject: [PATCH 67/78] Added ocelot_type property --- .../java/lol/pyr/znpcsplus/util/OcelotType.java | 8 ++++++++ .../src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 13 ++++++++++++- .../java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java b/api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java new file mode 100644 index 0000000..593ec57 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java @@ -0,0 +1,8 @@ +package lol.pyr.znpcsplus.util; + +public enum OcelotType { + OCELOT, + TUXEDO, + TABBY, + SIAMESE, +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 03d4202..04458b4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -272,6 +272,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage); registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage); registerEnumParser(manager, MooshroomVariant.class, incorrectUsageMessage); + registerEnumParser(manager, OcelotType.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 cc44222..f60a9fe 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -66,6 +66,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(HorseArmor.class); registerEnumSerializer(LlamaVariant.class); registerEnumSerializer(MooshroomVariant.class); + registerEnumSerializer(OcelotType.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -328,7 +329,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); } - // Slime and Magma Cube + // Slime, Magma Cube and Phantom int sizeIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) sizeIndex = 16; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) sizeIndex = 15; @@ -338,6 +339,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else sizeIndex = 16; register(new IntegerProperty("size", sizeIndex, 1, v1_8)); + // Ocelot + if (ver.isOlderThan(ServerVersion.V_1_14)) { + int ocelotIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) ocelotIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) ocelotIndex = 14; + else ocelotIndex = 18; + if (v1_8) register(new EncodedByteProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, obj -> (byte) obj.ordinal())); + else register(new EncodedIntegerProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, Enum::ordinal)); + } + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; // Spellcaster Illager int spellIndex = 12; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 5d72cbf..d86bede 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -110,6 +110,7 @@ public class NpcTypeImpl implements NpcType { ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); addProperties("fire", "invisible", "silent", "look", "potion_color", "potion_ambient", "dinnerbone"); + // TODO: make this look nicer after completing the rest of the properties if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) { addProperties("pose"); @@ -138,6 +139,11 @@ public class NpcTypeImpl implements NpcType { if (EntityTypes.isTypeInstanceOf(type, EntityTypes.SLIME) || EntityTypes.isTypeInstanceOf(type, EntityTypes.PHANTOM)) { addProperties("size"); } + if (version.isOlderThan(ServerVersion.V_1_14)) { + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.OCELOT)) { + addProperties("ocelot_type"); + } + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } From 747e6b92beb43cd5bbc4a840c464da0d25c2fa81 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 12 Sep 2023 21:49:53 +0530 Subject: [PATCH 68/78] changed to use static npc registry instead of NpcApiProvider --- plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java | 2 +- .../pyr/znpcsplus/conversion/DataImporterRegistry.java | 5 +++-- .../conversion/citizens/CitizensImporter.java | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 04458b4..1e23b92 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -145,7 +145,7 @@ public class ZNpcsPlus extends JavaPlugin { DataImporterRegistry importerRegistry = new DataImporterRegistry(configManager, adventure, bungeeConnector, scheduler, packetFactory, textSerializer, typeRegistry, getDataFolder().getParentFile(), - propertyRegistry, skinCache); + propertyRegistry, skinCache, npcRegistry); log(ChatColor.WHITE + " * Registerring components..."); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java index 55d1012..a162529 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/DataImporterRegistry.java @@ -4,6 +4,7 @@ import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.conversion.citizens.CitizensImporter; import lol.pyr.znpcsplus.conversion.znpcs.ZNpcImporter; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; @@ -25,14 +26,14 @@ public class DataImporterRegistry { public DataImporterRegistry(ConfigManager configManager, BukkitAudiences adventure, BungeeConnector bungeeConnector, TaskScheduler taskScheduler, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, NpcTypeRegistryImpl typeRegistry, File pluginsFolder, EntityPropertyRegistryImpl propertyRegistry, - MojangSkinCache skinCache) { + MojangSkinCache skinCache, NpcRegistryImpl npcRegistry) { register("znpcs", LazyLoader.of(() -> new ZNpcImporter(configManager, adventure, bungeeConnector, taskScheduler, packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "ServersNPC/data.json")))); register("znpcsplus_legacy", LazyLoader.of(() -> new ZNpcImporter(configManager, adventure, bungeeConnector, taskScheduler, packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "ZNPCsPlusLegacy/data.json")))); register("citizens", LazyLoader.of(() -> new CitizensImporter(configManager, adventure, bungeeConnector, taskScheduler, - packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "Citizens/saves.yml")))); + packetFactory, textSerializer, typeRegistry, propertyRegistry, skinCache, new File(pluginsFolder, "Citizens/saves.yml"), npcRegistry))); } private void register(String id, LazyLoader loader) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java index 86e3895..003ad69 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java @@ -1,6 +1,5 @@ package lol.pyr.znpcsplus.conversion.citizens; -import lol.pyr.znpcsplus.api.NpcApiProvider; import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.conversion.DataImporter; import lol.pyr.znpcsplus.conversion.citizens.model.CitizensTrait; @@ -8,6 +7,7 @@ import lol.pyr.znpcsplus.conversion.citizens.model.CitizensTraitsRegistry; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; @@ -39,11 +39,12 @@ public class CitizensImporter implements DataImporter { private final MojangSkinCache skinCache; private final File dataFile; private final CitizensTraitsRegistry traitsRegistry; + private final NpcRegistryImpl npcRegistry; public CitizensImporter(ConfigManager configManager, BukkitAudiences adventure, BungeeConnector bungeeConnector, TaskScheduler taskScheduler, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, MojangSkinCache skinCache, - File dataFile) { + File dataFile, NpcRegistryImpl npcRegistry) { this.configManager = configManager; this.adventure = adventure; this.bungeeConnector = bungeeConnector; @@ -55,6 +56,7 @@ public class CitizensImporter implements DataImporter { this.skinCache = skinCache; this.dataFile = dataFile; this.traitsRegistry = new CitizensTraitsRegistry(typeRegistry, propertyRegistry, skinCache); + this.npcRegistry = npcRegistry; } @Override @@ -96,8 +98,8 @@ public class CitizensImporter implements DataImporter { } } String id = key.toLowerCase(); - while (NpcApiProvider.get().getNpcRegistry().getById(id) != null) { - id += "_"; + while (npcRegistry.getById(id) != null) { + id += "_"; // TODO: make a backup of the old npc instead } NpcEntryImpl entry = new NpcEntryImpl(id, npc); entry.enableEverything(); From 4c8d25c4df8c018d3d1c6d3289de1796feddde86 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 12 Sep 2023 22:12:30 +0530 Subject: [PATCH 69/78] Added Panda properties --- .../lol/pyr/znpcsplus/util/PandaGene.java | 11 ++++++++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 27 ++++++++++++++----- .../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 7 +++++ .../znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/PandaGene.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/PandaGene.java b/api/src/main/java/lol/pyr/znpcsplus/util/PandaGene.java new file mode 100644 index 0000000..dcb3f47 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/PandaGene.java @@ -0,0 +1,11 @@ +package lol.pyr.znpcsplus.util; + +public enum PandaGene { + NORMAL, + LAZY, + WORRIED, + PLAYFUL, + BROWN, + WEAK, + AGGRESSIVE +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 1e23b92..daca0a5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -273,6 +273,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage); registerEnumParser(manager, MooshroomVariant.class, incorrectUsageMessage); registerEnumParser(manager, OcelotType.class, incorrectUsageMessage); + registerEnumParser(manager, PandaGene.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 f60a9fe..4c5b3b1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -67,6 +67,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(LlamaVariant.class); registerEnumSerializer(MooshroomVariant.class); registerEnumSerializer(OcelotType.class); + registerEnumSerializer(PandaGene.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -96,12 +97,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Sniffer registerType("sniffer_state", null); // TODO: Nothing on wiki.vg, look in mc source - // Panda - registerType("panda_sneezing", false); // TODO - registerType("panda_rolling", false); // TODO - registerType("panda_sitting", false); // TODO - registerType("panda_on_back", false); // TODO - // Pig registerType("pig_saddle", false); // TODO @@ -399,6 +394,26 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else mooshroomIndex = 15; register(new EncodedStringProperty<>("mooshroom_variant", MooshroomVariant.RED, mooshroomIndex, MooshroomVariant::getVariantName)); + // Panda + int pandaIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) pandaIndex = 20; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) pandaIndex = 19; + else pandaIndex = 18; + register(new EncodedByteProperty<>("panda_main_gene", PandaGene.NORMAL, pandaIndex++, obj -> (byte) obj.ordinal())); + register(new EncodedByteProperty<>("panda_hidden_gene", PandaGene.NORMAL, pandaIndex++, obj -> (byte) obj.ordinal())); + if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) { + register(new BitsetProperty("panda_sneezing", pandaIndex, 0x02)); + register(new BitsetProperty("panda_rolling", pandaIndex, 0x04)); + register(new BitsetProperty("panda_sitting", pandaIndex, 0x08)); + register(new BitsetProperty("panda_on_back", pandaIndex, 0x10)); + linkProperties("panda_sneezing", "panda_rolling", "panda_sitting", "panda_on_back"); + } else { + register(new BitsetProperty("panda_sneezing", pandaIndex, 0x02)); + register(new BitsetProperty("panda_eating", pandaIndex, 0x04)); + linkProperties("panda_sneezing", "panda_eating"); + } + + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_15)) return; register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index d86bede..f2d9b7b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -144,6 +144,13 @@ public class NpcTypeImpl implements NpcType { addProperties("ocelot_type"); } } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.PANDA)) { + if (version.isNewerThanOrEquals(ServerVersion.V_1_15)) { + addProperties("panda_rolling", "panda_sitting", "panda_on_back"); + } else { + addProperties("panda_eating"); + } + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index ee5401f..288de67 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -268,7 +268,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .addProperties("hand", "fox_variant", "fox_sitting", "fox_crouching", "fox_sleeping", "fox_faceplanted")); register(builder(p, "panda", EntityTypes.PANDA) - .setHologramOffset(-0.725)); + .setHologramOffset(-0.725) + .addProperties("panda_main_gene", "panda_hidden_gene", "panda_sneezing")); register(builder(p, "pillager", EntityTypes.PILLAGER) .setHologramOffset(-0.025) From dd3eda551283a7b9dd0291d0dcca2a118c783f0e Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 12 Sep 2023 22:53:58 +0530 Subject: [PATCH 70/78] Small fix for property deserialization --- .../znpcsplus/commands/property/PropertySetCommand.java | 2 +- .../lol/pyr/znpcsplus/entity/EnumPropertySerializer.java | 6 +++++- .../entity/serializers/IntegerPropertySerializer.java | 5 ++--- .../java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java | 7 ++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 3ea0074..0380025 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -63,7 +63,7 @@ public class PropertySetCommand implements CommandHandler { valueName = "NONE"; } else if (type == ParrotVariant.class && context.argSize() < 1 && npc.getProperty(property) != null) { - value = ParrotVariant.NONE; + value = null; valueName = "NONE"; } else if (type == BlockState.class) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java index c9a93c8..d71fb07 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java @@ -15,7 +15,11 @@ public class EnumPropertySerializer> implements PropertySerial @Override public T deserialize(String property) { - return Enum.valueOf(enumClass, property.toUpperCase()); + try { + return Enum.valueOf(enumClass, property.toUpperCase()); + } catch (IllegalArgumentException e) { + return null; + } } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java index 4ef2ff5..e918668 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java @@ -10,13 +10,12 @@ public class IntegerPropertySerializer implements PropertySerializer { @Override public Integer deserialize(String property) { - int i = 0; try { - i = Integer.parseInt(property); + return Integer.parseInt(property); } catch (NumberFormatException e) { e.printStackTrace(); } - return i; + return null; } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 8325cc9..032a916 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -70,7 +70,12 @@ public class YamlStorage implements NpcStorage { Bukkit.getLogger().log(Level.WARNING, "Unknown serializer for property '" + key + "' for npc '" + config.getString("id") + "'. skipping ..."); continue; } - npc.UNSAFE_setProperty(property, serializer.deserialize(properties.getString(key))); + Object value = serializer.deserialize(properties.getString(key)); + if (value == null) { + Bukkit.getLogger().log(Level.WARNING, "Failed to deserialize property '" + key + "' for npc '" + config.getString("id") + "'. Resetting to default ..."); + value = property.getDefaultValue(); + } + npc.UNSAFE_setProperty(property, value); } } HologramImpl hologram = npc.getHologram(); From bfbd883f033747b5cf83d4aae698b8ae1f15ce54 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 12 Sep 2023 23:16:42 +0530 Subject: [PATCH 71/78] Added parrot_variant property --- .../main/java/lol/pyr/znpcsplus/util/ParrotVariant.java | 3 +-- .../pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java | 9 +++++++++ .../java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/ParrotVariant.java b/api/src/main/java/lol/pyr/znpcsplus/util/ParrotVariant.java index 5014e03..82d56b1 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/util/ParrotVariant.java +++ b/api/src/main/java/lol/pyr/znpcsplus/util/ParrotVariant.java @@ -5,6 +5,5 @@ public enum ParrotVariant { BLUE, GREEN, YELLOW_BLUE, - GRAY, - NONE // only used to set empty nbt compound + GRAY } 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 4c5b3b1..36c26ce 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -363,6 +363,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EncodedIntegerProperty("carpet_color", DyeColor.class, llamaIndex++, obj -> obj == null ? -1 : obj.ordinal())); register(new EncodedIntegerProperty<>("llama_variant", LlamaVariant.CREAMY, llamaIndex, Enum::ordinal)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_12)) return; + // Parrot + int parrotIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) parrotIndex = 19; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) parrotIndex = 18; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) parrotIndex = 17; + else parrotIndex = 15; + register(new EncodedIntegerProperty<>("parrot_variant", ParrotVariant.RED_BLUE, parrotIndex, Enum::ordinal)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 288de67..5249a7f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -227,7 +227,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(-0.025)); register(builder(p, "parrot", EntityTypes.PARROT) - .setHologramOffset(-1.075)); + .setHologramOffset(-1.075) + .addProperties("parrot_variant")); if (!version.isNewerThanOrEquals(ServerVersion.V_1_13)) return; From b1f87d12bdee075a52ce3f928ab2ef44de992030 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 12 Sep 2023 23:49:08 +0530 Subject: [PATCH 72/78] Added pig_saddled property --- .../entity/EntityPropertyRegistryImpl.java | 33 ++++++++++--------- .../znpcsplus/npc/NpcTypeRegistryImpl.java | 3 +- 2 files changed, 20 insertions(+), 16 deletions(-) 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 36c26ce..9c7a4ef 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -97,9 +97,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Sniffer registerType("sniffer_state", null); // TODO: Nothing on wiki.vg, look in mc source - // Pig - registerType("pig_saddle", false); // TODO - // Rabbit registerType("rabbit_type", 0); // TODO: Figure this out @@ -118,9 +115,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("wolf_collar_color", DyeColor.RED); // TODO registerType("wolf_angry", false); // TODO - // Parrot - registerType("parrot_variant", 0); // TODO - // Villager registerType("villager_type", VillagerType.PLAINS); registerType("villager_profession", VillagerProfession.NONE); @@ -283,12 +277,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) horseIndex = 12; else horseIndex = 16; int horseEating = ver.isNewerThanOrEquals(ServerVersion.V_1_12) ? 0x10 : 0x20; - boolean v1_8 = ver.isOlderThan(ServerVersion.V_1_9); - register(new BitsetProperty("is_tame", horseIndex, 0x02, false, v1_8)); - register(new BitsetProperty("is_saddled", horseIndex, 0x04, false, v1_8)); - register(new BitsetProperty("is_eating", horseIndex, horseEating, false, v1_8)); - register(new BitsetProperty("is_rearing", horseIndex, horseEating << 1, false, v1_8)); - register(new BitsetProperty("has_mouth_open", horseIndex, horseEating << 2, false, v1_8)); + register(new BitsetProperty("is_tame", horseIndex, 0x02, false, legacyBooleans)); + register(new BitsetProperty("is_saddled", horseIndex, 0x04, false, legacyBooleans)); + register(new BitsetProperty("is_eating", horseIndex, horseEating, false, legacyBooleans)); + register(new BitsetProperty("is_rearing", horseIndex, horseEating << 1, false, legacyBooleans)); + register(new BitsetProperty("has_mouth_open", horseIndex, horseEating << 2, false, legacyBooleans)); // Horse if (ver.isNewerThanOrEquals(ServerVersion.V_1_8) && ver.isOlderThan(ServerVersion.V_1_9)) { @@ -317,7 +310,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Chested Horse if (ver.isOlderThan(ServerVersion.V_1_11)) { - register(new BitsetProperty("has_chest", horseIndex, 0x08, false, v1_8)); + register(new BitsetProperty("has_chest", horseIndex, 0x08, false, legacyBooleans)); linkProperties("is_saddled", "has_chest", "is_eating", "is_rearing", "has_mouth_open"); } else { register(new BooleanProperty("has_chest", horseVariantIndex, false, legacyBooleans)); @@ -332,7 +325,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) sizeIndex = 12; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) sizeIndex = 11; else sizeIndex = 16; - register(new IntegerProperty("size", sizeIndex, 1, v1_8)); + register(new IntegerProperty("size", sizeIndex, 1, legacyBooleans)); // Ocelot if (ver.isOlderThan(ServerVersion.V_1_14)) { @@ -340,10 +333,20 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) ocelotIndex = 15; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) ocelotIndex = 14; else ocelotIndex = 18; - if (v1_8) register(new EncodedByteProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, obj -> (byte) obj.ordinal())); + if (legacyBooleans) register(new EncodedByteProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, obj -> (byte) obj.ordinal())); else register(new EncodedIntegerProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, Enum::ordinal)); } + // Pig + int pigIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) pigIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) pigIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) pigIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) pigIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) pigIndex = 12; + else pigIndex = 16; + register(new BooleanProperty("pig_saddled", pigIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; // Spellcaster Illager int spellIndex = 12; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 5249a7f..6c41b0e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -111,7 +111,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(-1.275)); register(builder(p, "pig", EntityTypes.PIG) - .setHologramOffset(-1.075)); + .setHologramOffset(-1.075) + .addProperties("pig_saddled")); register(builder(p, "rabbit", EntityTypes.RABBIT) .setHologramOffset(-1.475)); From 5f5ed6ccb53cff7dcf01bd9e3d6381725b20181b Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 13 Sep 2023 00:03:08 +0530 Subject: [PATCH 73/78] Added Piglin properties --- .../entity/EntityPropertyRegistryImpl.java | 13 ++++++++----- .../lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) 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 9c7a4ef..444304e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -128,10 +128,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("shield_height", 0); // TODO: figure this out registerType("shulker_color", DyeColor.RED); // TODO - // Piglin - registerType("piglin_dancing", false); // TODO - registerType("piglin_charging_crossbow", false); // TODO - // Vindicator registerType("celebrating", false); // TODO @@ -440,12 +436,19 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { if (!ver.isNewerThanOrEquals(ServerVersion.V_1_16)) return; + // Hoglin and Piglin Zombification final int zombificationIndex; - if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) zombificationIndex = 17; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) zombificationIndex = 17; // Change piglinIndex if you change this else zombificationIndex = 16; register(new BooleanProperty("hoglin_immune_to_zombification", zombificationIndex, false, legacyBooleans)); register(new BooleanProperty("piglin_immune_to_zombification", zombificationIndex-1, false, legacyBooleans)); + // Piglin + int piglinIndex = zombificationIndex; + register(new BooleanProperty("piglin_baby", piglinIndex++, false, legacyBooleans)); + register(new BooleanProperty("piglin_charging_crossbow", piglinIndex++, false, legacyBooleans)); + register(new BooleanProperty("piglin_dancing", piglinIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; // Axolotl register(new EncodedIntegerProperty<>("axolotl_variant", AxolotlVariant.LUCY, 17, Enum::ordinal)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 6c41b0e..7190d4b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -302,7 +302,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "piglin", EntityTypes.PIGLIN) .setHologramOffset(-1.0) - .addEquipmentProperties()); + .addEquipmentProperties() + .addProperties("piglin_baby", "piglin_charging_crossbow", "piglin_dancing")); register(builder(p, "piglin_brute", EntityTypes.PIGLIN_BRUTE) .setHologramOffset(-0.025) From e4ff39bc79213beb34af477dd87f7e8fb2634fac Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 13 Sep 2023 00:14:50 +0530 Subject: [PATCH 74/78] Added pillager_charging and celebrating properties --- .../entity/EntityPropertyRegistryImpl.java | 13 +++++++++---- .../lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) 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 444304e..11db913 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -128,9 +128,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("shield_height", 0); // TODO: figure this out registerType("shulker_color", DyeColor.RED); // TODO - // Vindicator - registerType("celebrating", false); // TODO - // Wither registerType("invulnerable_time", 0); // TODO @@ -438,7 +435,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Hoglin and Piglin Zombification final int zombificationIndex; - if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) zombificationIndex = 17; // Change piglinIndex if you change this + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) zombificationIndex = 17; // Change piglinIndex and pillagerIndex if you change this else zombificationIndex = 16; register(new BooleanProperty("hoglin_immune_to_zombification", zombificationIndex, false, legacyBooleans)); register(new BooleanProperty("piglin_immune_to_zombification", zombificationIndex-1, false, legacyBooleans)); @@ -449,6 +446,14 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BooleanProperty("piglin_charging_crossbow", piglinIndex++, false, legacyBooleans)); register(new BooleanProperty("piglin_dancing", piglinIndex, false, legacyBooleans)); + // Pillager + int pillagerIndex = zombificationIndex; + register(new BooleanProperty("pillager_charging", pillagerIndex, false, legacyBooleans)); + + // Vindicator + int vindicatorIndex = pillagerIndex-1; + register(new BooleanProperty("celebrating", vindicatorIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; // Axolotl register(new EncodedIntegerProperty<>("axolotl_variant", AxolotlVariant.LUCY, 17, Enum::ordinal)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 7190d4b..afac796 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -212,7 +212,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .addHandProperties()); register(builder(p, "vindicator", EntityTypes.VINDICATOR) - .setHologramOffset(-0.025)); + .setHologramOffset(-0.025) + .addProperties("celebrating")); register(builder(p, "wither_skeleton", EntityTypes.WITHER_SKELETON) .setHologramOffset(0.425) @@ -275,7 +276,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "pillager", EntityTypes.PILLAGER) .setHologramOffset(-0.025) - .addHandProperties()); + .addHandProperties() + .addProperties("pillager_charging")); register(builder(p, "ravager", EntityTypes.RAVAGER) .setHologramOffset(0.225)); From 9be27f07480fa3b21b70156f0b6c5a862bd7af1e Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 13 Sep 2023 00:53:25 +0530 Subject: [PATCH 75/78] Added shoulder property for Player --- .../entity/EntityPropertyRegistryImpl.java | 18 +++++-- .../entity/properties/NBTProperty.java | 49 +++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java 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 11db913..5ac4796 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -3,6 +3,9 @@ package lol.pyr.znpcsplus.entity; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; +import com.github.retrooper.packetevents.protocol.nbt.NBTInt; +import com.github.retrooper.packetevents.protocol.nbt.NBTString; import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; @@ -72,10 +75,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation - // Player - registerType("shoulder_entity_left", ParrotVariant.NONE); - registerType("shoulder_entity_right", ParrotVariant.NONE); - // End Crystal registerType("beam_target", null); // TODO: Make a block pos class for this registerType("show_base", true); // TODO @@ -368,6 +367,17 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else parrotIndex = 15; register(new EncodedIntegerProperty<>("parrot_variant", ParrotVariant.RED_BLUE, parrotIndex, Enum::ordinal)); + // Player + NBTProperty.NBTDecoder parrotVariantDecoder = (variant) -> { + NBTCompound compound = new NBTCompound(); + compound.setTag("id", new NBTString("minecraft:parrot")); + compound.setTag("Variant", new NBTInt(variant.ordinal())); + return compound; + }; + int shoulderIndex = skinLayersIndex+2; + register(new NBTProperty<>("shoulder_entity_left", ParrotVariant.class, shoulderIndex++, parrotVariantDecoder)); + register(new NBTProperty<>("shoulder_entity_right", ParrotVariant.class, shoulderIndex, parrotVariantDecoder)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java new file mode 100644 index 0000000..9829790 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java @@ -0,0 +1,49 @@ +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.protocol.nbt.NBTCompound; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class NBTProperty extends EntityPropertyImpl { + private final EntityDataType type; + private final NBTDecoder decoder; + private final int index; + + public NBTProperty(String name, T defaultValue, Class clazz, int index, NBTDecoder decoder, EntityDataType type) { + super(name, defaultValue, clazz); + this.decoder = decoder; + this.index = index; + this.type = type; + } + + @SuppressWarnings("unchecked") + public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, EntityDataTypes.NBT); + } + + @SuppressWarnings("unchecked") + public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder, EntityDataType type) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, type); + } + + public NBTProperty(String name, Class clazz, int index, NBTDecoder decoder) { + this(name, null, clazz, index, decoder, EntityDataTypes.NBT); + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + T value = entity.getProperty(this); + if (value == null) return; + properties.put(index, newEntityData(index, type, decoder.decode(value))); + } + + public interface NBTDecoder { + NBTCompound decode(T obj); + } +} From 7d1772236ab1b8e353aaeb78c5385b8e46f3dbc7 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 13 Sep 2023 01:02:15 +0530 Subject: [PATCH 76/78] Added polar_bear_standing property --- .../znpcsplus/entity/EntityPropertyRegistryImpl.java | 12 +++++++++--- .../lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) 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 5ac4796..0bdd01d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -99,9 +99,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Rabbit registerType("rabbit_type", 0); // TODO: Figure this out - // Polar Bear - registerType("polar_bear_standing", false); // TODO - // Sheep registerType("sheep_color", DyeColor.WHITE); // TODO: Figure this out registerType("sheep_sheared", false); // TODO @@ -339,6 +336,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else pigIndex = 16; register(new BooleanProperty("pig_saddled", pigIndex, false, legacyBooleans)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_10)) return; + // Polar Bear + int polarBearIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) polarBearIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) polarBearIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) polarBearIndex = 15; + else polarBearIndex = 13; + register(new BooleanProperty("polar_bear_standing", polarBearIndex, false, false)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; // Spellcaster Illager int spellIndex = 12; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index afac796..00307b6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -175,7 +175,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { if (!version.isNewerThanOrEquals(ServerVersion.V_1_10)) return; register(builder(p, "polar_bear", EntityTypes.POLAR_BEAR) - .setHologramOffset(-0.575)); + .setHologramOffset(-0.575) + .addProperties("polar_bear_standing")); if (!version.isNewerThanOrEquals(ServerVersion.V_1_11)) return; From 41cccf419f95db5b0808251d9f77b201ed1498b7 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Wed, 13 Sep 2023 01:13:46 +0530 Subject: [PATCH 77/78] Added puff_state property --- .../main/java/lol/pyr/znpcsplus/util/PuffState.java | 7 +++++++ .../src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 13 ++++++++++--- .../lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/PuffState.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/PuffState.java b/api/src/main/java/lol/pyr/znpcsplus/util/PuffState.java new file mode 100644 index 0000000..0243932 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/PuffState.java @@ -0,0 +1,7 @@ +package lol.pyr.znpcsplus.util; + +public enum PuffState { + DEFLATED, + HALF_INFLATED, + FULLY_INFLATED, +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index daca0a5..1e86537 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -274,6 +274,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, MooshroomVariant.class, incorrectUsageMessage); registerEnumParser(manager, OcelotType.class, incorrectUsageMessage); registerEnumParser(manager, PandaGene.class, incorrectUsageMessage); + registerEnumParser(manager, PuffState.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 0bdd01d..b3f64c3 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -71,6 +71,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(MooshroomVariant.class); registerEnumSerializer(OcelotType.class); registerEnumSerializer(PandaGene.class); + registerEnumSerializer(PuffState.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -87,9 +88,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Guardian registerType("is_elder", false); // TODO: ensure it only works till 1.10. Note: index is wrong on wiki.vg - // Pufferfish - registerType("puff_state", null); // TODO: Make a puff state enum class - // Tropical Fish registerType("tropical_fish_variant", null); // TODO: Maybe make an enum class for this? its just an int on wiki.vg @@ -384,6 +382,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new NBTProperty<>("shoulder_entity_left", ParrotVariant.class, shoulderIndex++, parrotVariantDecoder)); register(new NBTProperty<>("shoulder_entity_right", ParrotVariant.class, shoulderIndex, parrotVariantDecoder)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_13)) return; + // Pufferfish + int pufferfishIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) pufferfishIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) pufferfishIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) pufferfishIndex = 15; + else pufferfishIndex = 13; + register(new EncodedIntegerProperty<>("puff_state", PuffState.DEFLATED, pufferfishIndex, Enum::ordinal)); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 00307b6..e12d9e2 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -250,7 +250,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { .setHologramOffset(-1.475)); register(builder(p, "pufferfish", EntityTypes.PUFFERFISH) - .setHologramOffset(-1.625)); + .setHologramOffset(-1.625) + .addProperties("puff_state")); register(builder(p, "salmon", EntityTypes.SALMON) .setHologramOffset(-1.575)); From df5fd8078f55f41360d4a5be29eb0226a8bb20a7 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Wed, 13 Sep 2023 01:59:52 +0200 Subject: [PATCH 78/78] implement villager properties --- .../znpcsplus/util/VillagerProfession.java | 38 +++++++++---------- .../lol/pyr/znpcsplus/util/VillagerType.java | 23 +++++++---- .../entity/EntityPropertyRegistryImpl.java | 26 +++++++++---- .../villager/VillagerDataProperty.java | 31 +++++++++++++++ .../villager/VillagerLevelProperty.java | 16 ++++++++ .../villager/VillagerProfessionProperty.java | 17 +++++++++ .../villager/VillagerTypeProperty.java | 17 +++++++++ 7 files changed, 134 insertions(+), 34 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerDataProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerLevelProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerProfessionProperty.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerTypeProperty.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java b/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java index b083f55..f02a53c 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java +++ b/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java @@ -2,28 +2,28 @@ package lol.pyr.znpcsplus.util; public enum VillagerProfession { NONE(0), - ARMORER(3), - BUTCHER(4), - CARTOGRAPHER(1), - CLERIC(2), - FARMER(0), - FISHERMAN(0), - FLETCHER(0), - LEATHER_WORKER(4), - LIBRARIAN(1), - MASON(-1), - NITWIT(5), - SHEPHERD(0), - TOOL_SMITH(3), - WEAPON_SMITH(3); + ARMORER(1), + BUTCHER(2), + CARTOGRAPHER(3), + CLERIC(4), + FARMER(5), + FISHERMAN(6), + FLETCHER(7), + LEATHER_WORKER(8), + LIBRARIAN(9), + MASON(10), + NITWIT(11), + SHEPHERD(12), + TOOL_SMITH(13), + WEAPON_SMITH(14); - private final int legacyId; + private final int id; - VillagerProfession(int legacyId) { - this.legacyId = legacyId; + VillagerProfession(int id) { + this.id = id; } - public int getLegacyId() { - return legacyId; + public int getId() { + return id; } } diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/VillagerType.java b/api/src/main/java/lol/pyr/znpcsplus/util/VillagerType.java index d29c12b..77623ff 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/util/VillagerType.java +++ b/api/src/main/java/lol/pyr/znpcsplus/util/VillagerType.java @@ -1,11 +1,20 @@ package lol.pyr.znpcsplus.util; public enum VillagerType { - DESERT, - JUNGLE, - PLAINS, - SAVANNA, - SNOW, - SWAMP, - TAIGA + DESERT(0), + JUNGLE(1), + PLAINS(2), + SAVANNA(3), + SNOW(4), + SWAMP(5), + TAIGA(6); + private final int id; + + VillagerType(int id) { + this.id = id; + } + + public int getId() { + return id; + } } 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 b3f64c3..c5b08dc 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -11,6 +11,9 @@ import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; import lol.pyr.znpcsplus.api.skin.SkinDescriptor; import lol.pyr.znpcsplus.entity.properties.*; +import lol.pyr.znpcsplus.entity.properties.villager.VillagerLevelProperty; +import lol.pyr.znpcsplus.entity.properties.villager.VillagerProfessionProperty; +import lol.pyr.znpcsplus.entity.properties.villager.VillagerTypeProperty; import lol.pyr.znpcsplus.entity.serializers.*; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.skin.cache.MojangSkinCache; @@ -109,11 +112,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("wolf_collar_color", DyeColor.RED); // TODO registerType("wolf_angry", false); // TODO - // Villager - registerType("villager_type", VillagerType.PLAINS); - registerType("villager_profession", VillagerProfession.NONE); - registerType("villager_level", VillagerLevel.STONE); - // Show Golem registerType("pumpkin", true); // TODO @@ -395,6 +393,19 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Pose register(new NpcPoseProperty()); + // Villager + final int villagerIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) villagerIndex = 18; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) villagerIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) villagerIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) villagerIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) villagerIndex = 12; + else villagerIndex = 16; + register(new VillagerTypeProperty("villager_type", villagerIndex, VillagerType.PLAINS)); + register(new VillagerProfessionProperty("villager_profession", villagerIndex, VillagerProfession.NONE)); + register(new VillagerLevelProperty("villager_level", villagerIndex, VillagerLevel.STONE)); + linkProperties("villager_type", "villager_profession", "villager_level"); + // Cat int catIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) catIndex = 19; @@ -470,11 +481,10 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BooleanProperty("piglin_dancing", piglinIndex, false, legacyBooleans)); // Pillager - int pillagerIndex = zombificationIndex; - register(new BooleanProperty("pillager_charging", pillagerIndex, false, legacyBooleans)); + register(new BooleanProperty("pillager_charging", zombificationIndex, false, legacyBooleans)); // Vindicator - int vindicatorIndex = pillagerIndex-1; + int vindicatorIndex = zombificationIndex -1; register(new BooleanProperty("celebrating", vindicatorIndex, false, legacyBooleans)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_17)) return; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerDataProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerDataProperty.java new file mode 100644 index 0000000..e86973b --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerDataProperty.java @@ -0,0 +1,31 @@ +package lol.pyr.znpcsplus.entity.properties.villager; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; +import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfessions; +import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import org.bukkit.entity.Player; + +import java.util.Map; + +public abstract class VillagerDataProperty extends EntityPropertyImpl { + private final int index; + + @SuppressWarnings("unchecked") + public VillagerDataProperty(String name, int index, T def) { + super(name, def, (Class) def.getClass()); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + EntityData oldData = properties.get(index); + VillagerData old = oldData == null ? new VillagerData(VillagerTypes.PLAINS, VillagerProfessions.NONE, 1) : (VillagerData) oldData.getValue(); + properties.put(index, newEntityData(index, EntityDataTypes.VILLAGER_DATA, apply(old, entity.getProperty(this)))); + } + + protected abstract VillagerData apply(VillagerData data, T value); +} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerLevelProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerLevelProperty.java new file mode 100644 index 0000000..af81f40 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerLevelProperty.java @@ -0,0 +1,16 @@ +package lol.pyr.znpcsplus.entity.properties.villager; + +import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; +import lol.pyr.znpcsplus.util.VillagerLevel; + +public class VillagerLevelProperty extends VillagerDataProperty { + public VillagerLevelProperty(String name, int index, VillagerLevel def) { + super(name, index, def); + } + + @Override + protected VillagerData apply(VillagerData data, VillagerLevel value) { + data.setLevel(value.ordinal() + 1); + return data; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerProfessionProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerProfessionProperty.java new file mode 100644 index 0000000..6571676 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerProfessionProperty.java @@ -0,0 +1,17 @@ +package lol.pyr.znpcsplus.entity.properties.villager; + +import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; +import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfessions; +import lol.pyr.znpcsplus.util.VillagerProfession; + +public class VillagerProfessionProperty extends VillagerDataProperty { + public VillagerProfessionProperty(String name, int index, VillagerProfession def) { + super(name, index, def); + } + + @Override + protected VillagerData apply(VillagerData data, VillagerProfession value) { + data.setProfession(VillagerProfessions.getById(value.getId())); + return data; + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerTypeProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerTypeProperty.java new file mode 100644 index 0000000..a3d2448 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/villager/VillagerTypeProperty.java @@ -0,0 +1,17 @@ +package lol.pyr.znpcsplus.entity.properties.villager; + +import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData; +import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerTypes; +import lol.pyr.znpcsplus.util.VillagerType; + +public class VillagerTypeProperty extends VillagerDataProperty { + public VillagerTypeProperty(String name, int index, VillagerType def) { + super(name, index, def); + } + + @Override + protected VillagerData apply(VillagerData data, VillagerType value) { + data.setType(VillagerTypes.getById(value.getId())); + return data; + } +}