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 c09258d..5f029ca 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -47,9 +47,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("hand", ItemStack.class); registerType("offhand", ItemStack.class); - registerType("using_item", false); // TODO: Eating/Drinking/Blocking with sword/etc + registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation registerType("potion_color", PotionColor.DEFAULT, PotionColor.class); - registerType("potion_ambient", false); // TODO + registerType("potion_ambient", false); registerType("shaking", false); registerType("baby", false); // TODO registerType("pose", NpcPose.STANDING); 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 bde752d..51edc53 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -54,11 +54,16 @@ public class NpcTypeImpl implements NpcType { } public Builder addEquipmentProperties() { - return addProperties("helmet", "chestplate", "leggings", "boots", "hand", "offhand"); + addProperties("helmet", "chestplate", "leggings", "boots"); + return addHandProperties(); } public Builder addHandProperties() { - return addProperties("hand", "offhand"); + if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) { + return addProperties("hand", "offhand"); + } else { + return addProperties("hand"); + } } public Builder addProperties(String... names) { 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 cf83b86..35f4df2 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 @@ -5,21 +5,19 @@ 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.item.type.ItemTypes; import com.github.retrooper.packetevents.protocol.player.*; 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.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.util.PotionColor; import lol.pyr.znpcsplus.metadata.MetadataFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.skin.BaseSkinDescriptor; import lol.pyr.znpcsplus.util.NpcLocation; +import lol.pyr.znpcsplus.util.PotionColor; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.entity.Player; @@ -168,27 +166,19 @@ public class V1_8PacketFactory implements PacketFactory { } 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<>(); - ItemStack air = new ItemStack.Builder().type(ItemTypes.AIR).build(); - - EntityPropertyImpl helmet = propertyRegistry.getByName("helmet", ItemStack.class); - equipements.add(new Equipment(EquipmentSlot.HELMET, properties.hasProperty(helmet) ? properties.getProperty(helmet) : air)); - - EntityPropertyImpl chestplate = propertyRegistry.getByName("chestplate", ItemStack.class); - equipements.add(new Equipment(EquipmentSlot.CHEST_PLATE, properties.hasProperty(chestplate) ? properties.getProperty(chestplate) : air)); - - EntityPropertyImpl leggings = propertyRegistry.getByName("leggings", ItemStack.class); - equipements.add(new Equipment(EquipmentSlot.LEGGINGS, properties.hasProperty(leggings) ? properties.getProperty(leggings) : air)); - - EntityPropertyImpl boots = propertyRegistry.getByName("boots", ItemStack.class); - equipements.add(new Equipment(EquipmentSlot.BOOTS, properties.hasProperty(boots) ? properties.getProperty(boots) : air)); - - EntityPropertyImpl hand = propertyRegistry.getByName("hand", ItemStack.class); - equipements.add(new Equipment(EquipmentSlot.MAIN_HAND, properties.hasProperty(hand) ? properties.getProperty(hand) : air)); - - EntityPropertyImpl offhand = propertyRegistry.getByName("offhand", ItemStack.class); - equipements.add(new Equipment(EquipmentSlot.OFF_HAND, properties.hasProperty(offhand) ? properties.getProperty(offhand) : air)); + 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; }