From 69b6509a0e572d70a5d9ff033d67d868e8334095 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 1 May 2023 01:13:51 +0800 Subject: [PATCH] Send player look packets for older versions --- .../v1_13_R2/util/PlayerlistTrackerEntry.java | 6 ++ .../nms/v1_14_R1/util/PlayerlistTracker.java | 6 ++ .../nms/v1_15_R1/util/PlayerlistTracker.java | 6 ++ .../nms/v1_16_R3/util/PlayerlistTracker.java | 6 ++ .../nms/v1_17_R1/util/PlayerlistTracker.java | 15 +++-- .../nms/v1_18_R2/util/PlayerlistTracker.java | 12 +++- .../nms/v1_19_R3/util/NMSImpl.java | 62 ++++++++++--------- 7 files changed, 76 insertions(+), 37 deletions(-) diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerlistTrackerEntry.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerlistTrackerEntry.java index 93a03f02c..ff0b6af35 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerlistTrackerEntry.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerlistTrackerEntry.java @@ -18,6 +18,7 @@ import net.minecraft.server.v1_13_R2.Entity; import net.minecraft.server.v1_13_R2.EntityPlayer; import net.minecraft.server.v1_13_R2.EntityTracker; import net.minecraft.server.v1_13_R2.EntityTrackerEntry; +import net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutEntityLook; public class PlayerlistTrackerEntry extends EntityTrackerEntry { private EntityPlayer lastUpdatedPlayer; @@ -42,6 +43,11 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry { final EntityPlayer entityplayer = lastUpdatedPlayer; NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); lastUpdatedPlayer = null; + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMSImpl.sendPacket(entityplayer.getBukkitEntity(), + new PacketPlayOutEntityLook(tracker.getId(), (byte) (tracker.yaw * 256.0F / 360.0F), + (byte) (tracker.pitch * 256.0F / 360.0F), tracker.onGround)); + }, 1); if (!Setting.DISABLE_TABLIST.asBoolean()) return; Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerlistTracker.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerlistTracker.java index 4b2ba982c..298624226 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerlistTracker.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/PlayerlistTracker.java @@ -16,6 +16,7 @@ import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_14_R1.Entity; import net.minecraft.server.v1_14_R1.EntityPlayer; import net.minecraft.server.v1_14_R1.EntityTrackerEntry; +import net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_14_R1.PlayerChunkMap; import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker; @@ -37,6 +38,11 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker { return; final EntityPlayer entityplayer = lastUpdatedPlayer; NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMSImpl.sendPacket(entityplayer.getBukkitEntity(), + new PacketPlayOutEntityLook(tracker.getId(), (byte) (tracker.yaw * 256.0F / 360.0F), + (byte) (tracker.pitch * 256.0F / 360.0F), tracker.onGround)); + }, 1); if (!Setting.DISABLE_TABLIST.asBoolean()) return; Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerlistTracker.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerlistTracker.java index f45fc7ae5..8574d3ca0 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerlistTracker.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/PlayerlistTracker.java @@ -16,6 +16,7 @@ import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_15_R1.Entity; import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.EntityTrackerEntry; +import net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_15_R1.PlayerChunkMap; import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker; @@ -37,6 +38,11 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker { return; final EntityPlayer entityplayer = lastUpdatedPlayer; NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMSImpl.sendPacket(entityplayer.getBukkitEntity(), + new PacketPlayOutEntityLook(tracker.getId(), (byte) (tracker.yaw * 256.0F / 360.0F), + (byte) (tracker.pitch * 256.0F / 360.0F), tracker.onGround)); + }, 1); if (!Setting.DISABLE_TABLIST.asBoolean()) return; Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java index 7a962f116..d25a82c9e 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java @@ -16,6 +16,7 @@ import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_16_R3.Entity; import net.minecraft.server.v1_16_R3.EntityPlayer; import net.minecraft.server.v1_16_R3.EntityTrackerEntry; +import net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_16_R3.PlayerChunkMap; import net.minecraft.server.v1_16_R3.PlayerChunkMap.EntityTracker; @@ -37,6 +38,11 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker { return; final EntityPlayer entityplayer = lastUpdatedPlayer; NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMSImpl.sendPacket(entityplayer.getBukkitEntity(), + new PacketPlayOutEntityLook(tracker.getId(), (byte) (tracker.yaw * 256.0F / 360.0F), + (byte) (tracker.pitch * 256.0F / 360.0F), tracker.isOnGround())); + }, 1); if (!Setting.DISABLE_TABLIST.asBoolean()) return; Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java index 588ad57f2..39381bb70 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java @@ -13,6 +13,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; +import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap.TrackedEntity; import net.minecraft.server.level.ServerEntity; @@ -38,14 +39,16 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity { return; final ServerPlayer entityplayer = lastUpdatedPlayer; NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMSImpl.sendPacket(entityplayer.getBukkitEntity(), + new ClientboundMoveEntityPacket.Rot(tracker.getId(), (byte) (tracker.getYRot() * 256.0F / 360.0F), + (byte) (tracker.getXRot() * 256.0F / 360.0F), tracker.isOnGround())); + }, 1); if (!Setting.DISABLE_TABLIST.asBoolean()) return; - Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { - @Override - public void run() { - NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); - } - }, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), + () -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()), + Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks()); } @Override diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java index daa88a388..99809cf89 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java @@ -13,6 +13,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; +import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap.TrackedEntity; import net.minecraft.server.level.ServerEntity; @@ -38,11 +39,16 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity { return; final ServerPlayer entityplayer = lastUpdatedPlayer; NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMSImpl.sendPacket(entityplayer.getBukkitEntity(), + new ClientboundMoveEntityPacket.Rot(tracker.getId(), (byte) (tracker.getYRot() * 256.0F / 360.0F), + (byte) (tracker.getXRot() * 256.0F / 360.0F), tracker.onGround)); + }, 1); if (!Setting.DISABLE_TABLIST.asBoolean()) return; - Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), - () -> NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()), - Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks()); + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> { + NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity()); + }, Setting.TABLIST_REMOVE_PACKET_DELAY.asTicks()); } @Override diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java index e75b62587..f7eae13d7 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java @@ -1355,34 +1355,7 @@ public class NMSImpl implements NMSBridge { @Override public void sendPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, Float pitch, Float headYaw) { - Entity handle = getHandle(from); - if (bodyYaw == null) { - bodyYaw = handle.getYRot(); - } - if (pitch == null) { - pitch = handle.getXRot(); - } - List> toSend = Lists.newArrayList(); - if (position) { - TrackedEntity entry = ((ServerLevel) handle.level).getChunkSource().chunkMap.entityMap.get(handle.getId()); - VecDeltaCodec vdc = null; - try { - vdc = (VecDeltaCodec) POSITION_CODEC_GETTER.invoke((ServerEntity) SERVER_ENTITY_GETTER.invoke(entry)); - } catch (Throwable e) { - e.printStackTrace(); - return; - } - Vec3 pos = handle.trackingPosition(); - toSend.add(new ClientboundMoveEntityPacket.PosRot(handle.getId(), (short) vdc.encodeX(pos), - (short) vdc.encodeY(pos), (short) vdc.encodeZ(pos), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), handle.onGround)); - } else { - toSend.add(new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), handle.onGround)); - } - if (headYaw != null) { - toSend.add(new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F))); - } + List> toSend = getPositionUpdate(from, position, bodyYaw, pitch, headYaw); sendPacketsNearby(null, from.getLocation(), toSend, 64); } @@ -2228,6 +2201,39 @@ public class NMSImpl implements NMSBridge { } } + public static List> getPositionUpdate(org.bukkit.entity.Entity from, boolean position, Float bodyYaw, + Float pitch, Float headYaw) { + Entity handle = getHandle(from); + if (bodyYaw == null) { + bodyYaw = handle.getYRot(); + } + if (pitch == null) { + pitch = handle.getXRot(); + } + List> toSend = Lists.newArrayList(); + if (position) { + TrackedEntity entry = ((ServerLevel) handle.level).getChunkSource().chunkMap.entityMap.get(handle.getId()); + VecDeltaCodec vdc = null; + try { + vdc = (VecDeltaCodec) POSITION_CODEC_GETTER.invoke((ServerEntity) SERVER_ENTITY_GETTER.invoke(entry)); + } catch (Throwable e) { + e.printStackTrace(); + return Collections.emptyList(); + } + Vec3 pos = handle.trackingPosition(); + toSend.add(new ClientboundMoveEntityPacket.PosRot(handle.getId(), (short) vdc.encodeX(pos), + (short) vdc.encodeY(pos), (short) vdc.encodeZ(pos), (byte) (bodyYaw * 256.0F / 360.0F), + (byte) (pitch * 256.0F / 360.0F), handle.onGround)); + } else { + toSend.add(new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), + (byte) (pitch * 256.0F / 360.0F), handle.onGround)); + } + if (headYaw != null) { + toSend.add(new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F))); + } + return toSend; + } + public static EntityDataAccessor getRabbitTypeField() { return RABBIT_TYPE_DATAWATCHER; }