diff --git a/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java b/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java index 82abea0..8ef9a4d 100644 --- a/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java +++ b/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java @@ -141,10 +141,10 @@ public class ZNPCsPlus extends JavaPlugin { for (NPCType type : NPCType.values()) { NPC npc = new NPC(world, type, new PacketLocation(x * 3, 200, z * 3, 0, 0)); if (type.getType() == EntityTypes.PLAYER) { - npc.setProperty(NPCProperty.GLOW, NamedTextColor.RED); - npc.setProperty(NPCProperty.FIRE, true); NPCSkin.forName("Notch", (skin, ex) -> npc.setProperty(NPCProperty.SKIN, skin)); } + npc.setProperty(NPCProperty.GLOW, NamedTextColor.RED); + npc.setProperty(NPCProperty.FIRE, true); NPCRegistry.register("debug_npc" + (z * wrap + x), npc); if (x++ > wrap) { x = 0; diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java b/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java index b422bf5..b36b7fa 100644 --- a/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java @@ -11,7 +11,7 @@ public class V1_8Factory implements MetadataFactory { @Override public EntityData effects(boolean onFire, boolean glowing) { - return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (glowing ? 0x40 : 0))); + return new EntityData(0, EntityDataTypes.BYTE, onFire ? 0x01 : 0); } protected EntityData createSkinLayers(int index) { diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java b/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java index 0d5bd78..1a8a9c5 100644 --- a/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java @@ -1,10 +1,16 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; public class V1_9Factory extends V1_8Factory { @Override public EntityData skinLayers() { return createSkinLayers(13); } + + @Override + public EntityData effects(boolean onFire, boolean glowing) { + return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (glowing ? 0x40 : 0))); + } } diff --git a/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java b/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java index ef98ffd..9496537 100644 --- a/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java +++ b/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java @@ -20,7 +20,7 @@ public class NPCProperty { BY_NAME.put(this.name, this); } - public String getName() { + public String name() { return name; } diff --git a/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java b/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java index 3d81460..db8a12a 100644 --- a/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java +++ b/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java @@ -33,10 +33,10 @@ public class NPCType { static { ImmutableList.Builder builder = new ImmutableList.Builder<>(); - builder.add(new NPCType(EntityTypes.PLAYER, NPCProperty.SKIN)); - builder.add(new NPCType(EntityTypes.CREEPER)); - builder.add(new NPCType(EntityTypes.ZOMBIE)); - builder.add(new NPCType(EntityTypes.SKELETON)); + builder.add(new NPCType(EntityTypes.PLAYER, NPCProperty.GLOW, NPCProperty.FIRE, NPCProperty.SKIN, NPCProperty.SKIN_LAYERS)); + builder.add(new NPCType(EntityTypes.CREEPER, NPCProperty.GLOW, NPCProperty.FIRE)); + builder.add(new NPCType(EntityTypes.ZOMBIE, NPCProperty.GLOW, NPCProperty.FIRE)); + builder.add(new NPCType(EntityTypes.SKELETON, NPCProperty.GLOW, NPCProperty.FIRE)); npcTypes = builder.build(); } diff --git a/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java index 2005987..6c5f9f9 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java @@ -19,6 +19,7 @@ public interface PacketFactory { void removeTabPlayer(Player player, PacketEntity entity); void createTeam(Player player, PacketEntity entity); void removeTeam(Player player, PacketEntity entity); + void sendAllMetadata(Player player, PacketEntity entity); void sendMetadata(Player player, PacketEntity entity, EntityData... data); PacketFactory factory = get(); @@ -39,6 +40,7 @@ public interface PacketFactory { private static Map> buildFactoryMap() { HashMap> map = new HashMap<>(); map.put(ServerVersion.V_1_8, LazyLoader.of(V1_8Factory::new)); + map.put(ServerVersion.V_1_9, LazyLoader.of(V1_9Factory::new)); map.put(ServerVersion.V_1_14, LazyLoader.of(V1_14Factory::new)); map.put(ServerVersion.V_1_19, LazyLoader.of(V1_19Factory::new)); return map; diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java index 07c8a7e..560f948 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java @@ -3,15 +3,18 @@ package lol.pyr.znpcsplus.packets; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketLocation; +import lol.pyr.znpcsplus.npc.NPCProperty; import org.bukkit.entity.Player; import java.util.Optional; -public class V1_14Factory extends V1_8Factory { +public class V1_14Factory extends V1_9Factory { @Override public void spawnEntity(Player player, PacketEntity entity) { PacketLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), location.toVector3d(), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); + if (entity.getOwner().hasProperty(NPCProperty.GLOW)) createTeam(player, entity); + sendAllMetadata(player, entity); } } diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java index b00c0a4..5c8be45 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java @@ -28,16 +28,12 @@ import java.util.Optional; public class V1_8Factory implements PacketFactory { @Override public void spawnPlayer(Player player, PacketEntity entity) { - NPC owner = entity.getOwner(); addTabPlayer(player, entity); createTeam(player, entity); PacketLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), List.of())); - if (owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers()); - boolean glow = owner.hasProperty(NPCProperty.GLOW); - boolean fire = owner.getProperty(NPCProperty.FIRE); - if (glow || fire) sendMetadata(player, entity, MetadataFactory.get().effects(fire, glow)); + sendAllMetadata(player, entity); ZNPCsPlus.SCHEDULER.scheduleSyncDelayedTask(() -> removeTabPlayer(player, entity), 60); } @@ -51,6 +47,7 @@ public class V1_8Factory implements PacketFactory { location.getYaw(), location.getPitch(), location.getPitch(), new Vector3d(), List.of()) : new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), location.toVector3d(), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); + sendAllMetadata(player, entity); } @Override @@ -92,7 +89,8 @@ public class V1_8Factory implements PacketFactory { owner.hasProperty(NPCProperty.GLOW) ? owner.getProperty(NPCProperty.GLOW) : NamedTextColor.WHITE, WrapperPlayServerTeams.OptionData.NONE ))); - sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null, Integer.toString(entity.getEntityId()))); + sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null, + entity.getType() == EntityTypes.PLAYER ? Integer.toString(entity.getEntityId()) : entity.getUuid().toString())); } @Override @@ -100,6 +98,13 @@ public class V1_8Factory implements PacketFactory { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.REMOVE, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null)); } + @Override + public void sendAllMetadata(Player player, PacketEntity entity) { + NPC owner = entity.getOwner(); + if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers()); + if (owner.getProperty(NPCProperty.FIRE)) sendMetadata(player, entity, MetadataFactory.get().effects(true, false)); + } + @Override public void sendMetadata(Player player, PacketEntity entity, EntityData... data) { PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), List.of(data))); diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java new file mode 100644 index 0000000..dac06ed --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java @@ -0,0 +1,31 @@ +package lol.pyr.znpcsplus.packets; + +import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.metadata.MetadataFactory; +import lol.pyr.znpcsplus.npc.NPC; +import lol.pyr.znpcsplus.npc.NPCProperty; +import org.bukkit.entity.Player; + +public class V1_9Factory extends V1_8Factory { + @Override + public void sendAllMetadata(Player player, PacketEntity entity) { + NPC owner = entity.getOwner(); + if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers()); + boolean glow = owner.hasProperty(NPCProperty.GLOW); + boolean fire = owner.getProperty(NPCProperty.FIRE); + if (glow || fire) sendMetadata(player, entity, MetadataFactory.get().effects(fire, glow)); + } + + @Override + public void spawnEntity(Player player, PacketEntity entity) { + super.spawnEntity(player, entity); + if (entity.getOwner().hasProperty(NPCProperty.GLOW)) createTeam(player, entity); + } + + @Override + public void destroyEntity(Player player, PacketEntity entity) { + super.destroyEntity(player, entity); + if (entity.getType() != EntityTypes.PLAYER && entity.getOwner().hasProperty(NPCProperty.GLOW)) removeTeam(player, entity); + } +}