diff --git a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java index f41ae97a3..aab3b1ab9 100644 --- a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java +++ b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java @@ -101,6 +101,7 @@ public class ProtocolLibListener { PacketRotationSession session = trait.getPacketSession(event.getPlayer()); if (session == null || !session.isActive()) return; + PacketContainer packet = event.getPacket(); PacketType type = event.getPacketType(); if (type == Server.ENTITY_HEAD_ROTATION) { diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index f2ec60852..e427315ed 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -228,7 +228,6 @@ import net.minecraft.server.v1_10_R1.NetworkManager; import net.minecraft.server.v1_10_R1.Packet; import net.minecraft.server.v1_10_R1.PacketPlayOutAnimation; import net.minecraft.server.v1_10_R1.PacketPlayOutBed; -import net.minecraft.server.v1_10_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow; @@ -1065,11 +1064,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index df7f5f07f..fea0bae2d 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -248,7 +248,6 @@ import net.minecraft.server.v1_11_R1.NetworkManager; import net.minecraft.server.v1_11_R1.Packet; import net.minecraft.server.v1_11_R1.PacketPlayOutAnimation; import net.minecraft.server.v1_11_R1.PacketPlayOutBed; -import net.minecraft.server.v1_11_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_11_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_11_R1.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow; @@ -1124,11 +1123,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index dd7eaafe5..38cad196c 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -252,7 +252,6 @@ import net.minecraft.server.v1_12_R1.NetworkManager; import net.minecraft.server.v1_12_R1.Packet; import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation; import net.minecraft.server.v1_12_R1.PacketPlayOutBed; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_12_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_12_R1.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_12_R1.PacketPlayOutOpenWindow; @@ -1131,11 +1130,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index f30a80c14..befcdc4a7 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -286,7 +286,6 @@ import net.minecraft.server.v1_14_R1.MobEffects; import net.minecraft.server.v1_14_R1.NavigationAbstract; import net.minecraft.server.v1_14_R1.NetworkManager; import net.minecraft.server.v1_14_R1.Packet; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_14_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_14_R1.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow; @@ -1193,11 +1192,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 5abd40565..110409ad5 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -291,7 +291,6 @@ import net.minecraft.server.v1_15_R1.MobEffects; import net.minecraft.server.v1_15_R1.NavigationAbstract; import net.minecraft.server.v1_15_R1.NetworkManager; import net.minecraft.server.v1_15_R1.Packet; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_15_R1.PacketPlayOutOpenWindow; @@ -1211,11 +1210,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index 5479ea1a5..a9f2ef472 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -300,7 +300,6 @@ import net.minecraft.server.v1_16_R3.MobEffects; import net.minecraft.server.v1_16_R3.NavigationAbstract; import net.minecraft.server.v1_16_R3.NetworkManager; import net.minecraft.server.v1_16_R3.Packet; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_16_R3.PacketPlayOutOpenWindow; @@ -1241,11 +1240,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index 57d5ef0da..fe0228c46 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -245,7 +245,6 @@ import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; @@ -1232,11 +1231,16 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), handle.isOnGround()), - new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)) }; - sendPacketsNearby(null, from.getLocation(), packets); + float oldBody = handle.getYRot(); + float oldPitch = handle.getXRot(); + handle.setYBodyRot(bodyYaw); + handle.setXRot(pitch); + sendPacketsNearby(null, from.getLocation(), new Packet[] { new ClientboundTeleportEntityPacket(handle), + // new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), + // (byte) (pitch * 256.0F / 360.0F), handle.onGround), + new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)) }); + handle.setYBodyRot(oldBody); + handle.setXRot(oldPitch); } @Override diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerAnimationImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerAnimationImpl.java index 0a478c80d..9eb7e92d4 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerAnimationImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerAnimationImpl.java @@ -2,10 +2,14 @@ package net.citizensnpcs.nms.v1_17_R1.util; import java.util.EnumMap; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.scheduler.BukkitRunnable; import com.google.common.collect.Maps; +import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.util.PlayerAnimation; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; @@ -35,11 +39,39 @@ public class PlayerAnimationImpl { break; case START_USE_MAINHAND_ITEM: player.startUsingItem(InteractionHand.MAIN_HAND); + new BukkitRunnable() { + @Override + public void run() { + player.startUsingItem(InteractionHand.MAIN_HAND); + sendPacketNearby( + new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), + player, radius); + if (!player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + player.getBukkitEntity().setMetadata("citizens-using-item-id", + new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId())); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks() - 1, + player.getUseItemRemainingTicks() - 1); sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), player, radius); break; case START_USE_OFFHAND_ITEM: player.startUsingItem(InteractionHand.OFF_HAND); + new BukkitRunnable() { + @Override + public void run() { + player.startUsingItem(InteractionHand.OFF_HAND); + sendPacketNearby( + new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), + player, radius); + if (!player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + player.getBukkitEntity().setMetadata("citizens-using-item-id", + new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId())); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks() - 1, + player.getUseItemRemainingTicks() - 1); sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), player, radius); break; @@ -50,6 +82,11 @@ public class PlayerAnimationImpl { break; case STOP_USE_ITEM: player.stopUsingItem(); + if (player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + Bukkit.getScheduler() + .cancelTask(player.getBukkitEntity().getMetadata("citizens-using-item-id").get(0).asInt()); + player.getBukkitEntity().removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin()); + } sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), player, radius); break; diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index 0eb7783ad..bee729ba7 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -246,7 +246,6 @@ import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; @@ -1240,11 +1239,16 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), handle.onGround), - new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)) }; - sendPacketsNearby(null, from.getLocation(), packets); + float oldBody = handle.getYRot(); + float oldPitch = handle.getXRot(); + handle.setYBodyRot(bodyYaw); + handle.setXRot(pitch); + sendPacketsNearby(null, from.getLocation(), new Packet[] { new ClientboundTeleportEntityPacket(handle), + // new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), + // (byte) (pitch * 256.0F / 360.0F), handle.onGround), + new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)) }); + handle.setYBodyRot(oldBody); + handle.setXRot(oldPitch); } @Override diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerAnimationImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerAnimationImpl.java index c29195f70..bbb21e2bc 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerAnimationImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerAnimationImpl.java @@ -2,10 +2,14 @@ package net.citizensnpcs.nms.v1_18_R2.util; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.scheduler.BukkitRunnable; import com.google.common.collect.Maps; +import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.util.PlayerAnimation; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; @@ -35,11 +39,39 @@ public class PlayerAnimationImpl { break; case START_USE_MAINHAND_ITEM: player.startUsingItem(InteractionHand.MAIN_HAND); + new BukkitRunnable() { + @Override + public void run() { + player.startUsingItem(InteractionHand.MAIN_HAND); + sendPacketNearby( + new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), + player, radius); + if (!player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + player.getBukkitEntity().setMetadata("citizens-using-item-id", + new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId())); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks() - 1, + player.getUseItemRemainingTicks() - 1); sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), player, radius); break; case START_USE_OFFHAND_ITEM: player.startUsingItem(InteractionHand.OFF_HAND); + new BukkitRunnable() { + @Override + public void run() { + player.startUsingItem(InteractionHand.OFF_HAND); + sendPacketNearby( + new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), + player, radius); + if (!player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + player.getBukkitEntity().setMetadata("citizens-using-item-id", + new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId())); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks() - 1, + player.getUseItemRemainingTicks() - 1); sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), player, radius); break; @@ -50,6 +82,11 @@ public class PlayerAnimationImpl { break; case STOP_USE_ITEM: player.stopUsingItem(); + if (player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + Bukkit.getScheduler() + .cancelTask(player.getBukkitEntity().getMetadata("citizens-using-item-id").get(0).asInt()); + player.getBukkitEntity().removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin()); + } sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), player, radius); break; diff --git a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/NMSImpl.java b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/NMSImpl.java index cbf670b5d..bf0a1b5f7 100644 --- a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/NMSImpl.java +++ b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/NMSImpl.java @@ -263,7 +263,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; @@ -1320,11 +1319,16 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), handle.onGround), - new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)) }; - sendPacketsNearby(null, from.getLocation(), packets); + float oldBody = handle.getYRot(); + float oldPitch = handle.getXRot(); + handle.setYBodyRot(bodyYaw); + handle.setXRot(pitch); + sendPacketsNearby(null, from.getLocation(), new Packet[] { new ClientboundTeleportEntityPacket(handle), + // new ClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), + // (byte) (pitch * 256.0F / 360.0F), handle.onGround), + new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)) }); + handle.setYBodyRot(oldBody); + handle.setXRot(oldPitch); } @Override @@ -1354,11 +1358,11 @@ public class NMSImpl implements NMSBridge { NMSImpl.sendPacket(recipient, packet); - if (VIA_ENABLED == true) { + /* if (VIA_ENABLED == true) { int version = Via.getAPI().getPlayerVersion(recipient); return version < 761; - } - return false; + }*/ + return true; } @Override diff --git a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/PlayerAnimationImpl.java b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/PlayerAnimationImpl.java index 57e7d8c02..31636dd08 100644 --- a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/PlayerAnimationImpl.java +++ b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/util/PlayerAnimationImpl.java @@ -2,10 +2,14 @@ package net.citizensnpcs.nms.v1_19_R2.util; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.scheduler.BukkitRunnable; import com.google.common.collect.Maps; +import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.util.PlayerAnimation; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundAnimatePacket; @@ -34,10 +38,34 @@ public class PlayerAnimationImpl { break; case START_USE_MAINHAND_ITEM: player.startUsingItem(InteractionHand.MAIN_HAND); + new BukkitRunnable() { + @Override + public void run() { + player.startUsingItem(InteractionHand.MAIN_HAND); + sendEntityData(radius, player); + if (!player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + player.getBukkitEntity().setMetadata("citizens-using-item-id", + new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId())); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks() - 1, + player.getUseItemRemainingTicks() - 1); sendEntityData(radius, player); break; case START_USE_OFFHAND_ITEM: player.startUsingItem(InteractionHand.OFF_HAND); + new BukkitRunnable() { + @Override + public void run() { + player.startUsingItem(InteractionHand.OFF_HAND); + sendEntityData(radius, player); + if (!player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + player.getBukkitEntity().setMetadata("citizens-using-item-id", + new FixedMetadataValue(CitizensAPI.getPlugin(), getTaskId())); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), player.getUseItemRemainingTicks() - 1, + player.getUseItemRemainingTicks() - 1); sendEntityData(radius, player); break; case STOP_SNEAKING: @@ -46,6 +74,11 @@ public class PlayerAnimationImpl { break; case STOP_USE_ITEM: player.stopUsingItem(); + if (player.getBukkitEntity().hasMetadata("citizens-using-item-id")) { + Bukkit.getScheduler() + .cancelTask(player.getBukkitEntity().getMetadata("citizens-using-item-id").get(0).asInt()); + player.getBukkitEntity().removeMetadata("citizens-using-item-id", CitizensAPI.getPlugin()); + } sendEntityData(radius, player); break; default: diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index cdb25f218..8b420ad98 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -205,7 +205,6 @@ import net.minecraft.server.v1_8_R3.NetworkManager; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation; import net.minecraft.server.v1_8_R3.PacketPlayOutBed; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutEntityLook; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow; @@ -995,11 +994,15 @@ public class NMSImpl implements NMSBridge { @Override public void sendRotationNearby(org.bukkit.entity.Entity from, float bodyYaw, float headYaw, float pitch) { Entity handle = getHandle(from); - Packet[] packets = new Packet[] { - new PacketPlayOutEntityLook(handle.getId(), (byte) (bodyYaw * 256.0F / 360.0F), - (byte) (pitch * 256.0F / 360.0F), isOnGround(from)), + float oldBody = handle.yaw; + float oldPitch = handle.pitch; + handle.yaw = bodyYaw; + handle.pitch = pitch; + Packet[] packets = new Packet[] { new PacketPlayOutEntityTeleport(handle), new PacketPlayOutEntityHeadRotation(handle, (byte) (headYaw * 256.0F / 360.0F)) }; sendPacketsNearby(null, from.getLocation(), packets); + handle.yaw = oldBody; + handle.pitch = oldPitch; } @Override