From 7b2b56e836a7758f3ab53113b7d7392fb49390ca Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 4 May 2025 17:09:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(network):=20=E4=BF=AE=E5=A4=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8via=E8=BF=9B=E6=9C=8D=E6=96=B9=E5=9D=97=E9=80=89?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/network/PacketConsumers.java | 15 +++++----- .../craftengine/bukkit/util/Reflections.java | 30 +++++++++---------- gradle.properties | 2 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index 16d0cfa9f..0b2159d8f 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -36,6 +36,7 @@ import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.plugin.network.ConnectionState; import net.momirealms.craftengine.core.plugin.network.NetWorkUser; import net.momirealms.craftengine.core.plugin.network.NetworkManager; +import net.momirealms.craftengine.core.plugin.network.ProtocolVersion; import net.momirealms.craftengine.core.util.*; import net.momirealms.craftengine.core.world.BlockHitResult; import net.momirealms.craftengine.core.world.BlockPos; @@ -1344,7 +1345,7 @@ public class PacketConsumers { // When the hotbar is full, the latest creative mode inventory can only be accessed when the player opens the inventory screen. Currently, it is not worth further handling this issue. public static final TriConsumer SET_CREATIVE_SLOT = (user, event, packet) -> { try { - if (VersionHelper.isOrAbove1_21_4()) return; + if (ProtocolVersionUtils.isVersionNewerThan(user.protocolVersion(), ProtocolVersion.V1_21_4)) return; if (!user.isOnline()) return; BukkitServerPlayer player = (BukkitServerPlayer) user; if (VersionHelper.isFolia()) { @@ -1612,6 +1613,7 @@ public class PacketConsumers { Byte displayType = container.get(displayTypeKey, PersistentDataType.BYTE); if (customTrident == null) return; Reflections.field$ClientboundAddEntityPacket$type.set(packet, Reflections.instance$EntityType$ITEM_DISPLAY); + // System.out.println(packet); List itemDisplayValues = new ArrayList<>(); Item item = BukkitItemManager.instance().createWrappedItem(Key.of(customTrident), null); ItemDisplayEntityData.InterpolationDelay.addEntityDataIfNotDefaultValue(interpolationDelay, itemDisplayValues); @@ -1637,12 +1639,11 @@ public class PacketConsumers { public static final TriConsumer SYNC_ENTITY_POSITION = (user, event, packet) -> { try { int entityId = FastNMS.INSTANCE.method$ClientboundEntityPositionSyncPacket$id(packet); - // if (user.tridentView().contains(entityId)) { - // if (!VersionHelper.isOrAbove1_21_3()) return; - // Object values = Reflections.field$ClientboundEntityPositionSyncPacket$values.get(packet); - // user.sendPacket(Reflections.constructor$ClientboundTeleportEntityPacket.newInstance(entityId, values, Set.of(), false), true); - // Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage("Sync entity position: " + values)); - // } + if (user.tridentView().containsKey(entityId)) { + if (!VersionHelper.isOrAbove1_21_3()) return; + Object values = Reflections.field$ClientboundEntityPositionSyncPacket$values.get(packet); + // Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage("Sync entity position: " + values)); + } if (BukkitFurnitureManager.instance().isFurnitureRealEntity(entityId)) { event.setCancelled(true); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java index eba11c579..632d6775d 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java @@ -6627,21 +6627,21 @@ public class Reflections { ) ); - // public static final Class clazz$PositionMoveRotation = - // ReflectionUtils.getClazz( - // BukkitReflectionUtils.assembleMCClass("world.entity.PositionMoveRotation") - // ); - // - // public static final Field field$ClientboundEntityPositionSyncPacket$values = Optional.ofNullable(clazz$ClientboundEntityPositionSyncPacket) - // .map(it -> ReflectionUtils.getInstanceDeclaredField(it, clazz$PositionMoveRotation, 0)) - // .orElse(null); - // - // public static final Class clazz$ClientboundTeleportEntityPacket = requireNonNull( - // BukkitReflectionUtils.findReobfOrMojmapClass( - // "network.protocol.game.PacketPlayOutEntityTeleport", - // "network.protocol.game.ClientboundTeleportEntityPacket" - // ) - // ); + public static final Class clazz$PositionMoveRotation = + ReflectionUtils.getClazz( + BukkitReflectionUtils.assembleMCClass("world.entity.PositionMoveRotation") + ); + + public static final Field field$ClientboundEntityPositionSyncPacket$values = Optional.ofNullable(clazz$ClientboundEntityPositionSyncPacket) + .map(it -> ReflectionUtils.getInstanceDeclaredField(it, clazz$PositionMoveRotation, 0)) + .orElse(null); + + public static final Class clazz$ClientboundTeleportEntityPacket = requireNonNull( + BukkitReflectionUtils.findReobfOrMojmapClass( + "network.protocol.game.PacketPlayOutEntityTeleport", + "network.protocol.game.ClientboundTeleportEntityPacket" + ) + ); // // /** // * 实体移动数据包 diff --git a/gradle.properties b/gradle.properties index 4783415e2..33dfae1b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,7 +40,7 @@ geantyref_version=1.3.16 zstd_version=1.5.7-2 commons_io_version=2.18.0 sparrow_nbt_version=0.7.1 -sparrow_util_version=0.39 +sparrow_util_version=0.40 fastutil_version=8.5.15 netty_version=4.1.119.Final joml_version=1.10.8