mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 01:49:30 +00:00
fix(bukkit): 阻止发送仅服务端实体包
This commit is contained in:
@@ -134,6 +134,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerNMSPacketConsumer(PacketConsumers.REMOVE_ENTITY, Reflections.clazz$ClientboundRemoveEntitiesPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SYNC_ENTITY_POSITION, Reflections.clazz$ClientboundEntityPositionSyncPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.MOVE_ENTITY, Reflections.clazz$ClientboundMoveEntityPacket$Pos);
|
||||
registerNMSPacketConsumer(PacketConsumers.MOVE_AND_ROTATION_ENTITY, Reflections.clazz$ClientboundMoveEntityPacket$PosRot);
|
||||
registerNMSPacketConsumer(PacketConsumers.ROTATE_HEAD, Reflections.clazz$ClientboundRotateHeadPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_ENTITY_MOTION, Reflections.clazz$ClientboundSetEntityMotionPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.PICK_ITEM_FROM_ENTITY, Reflections.clazz$ServerboundPickItemFromEntityPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SOUND, Reflections.clazz$ClientboundSoundPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.RENAME_ITEM, Reflections.clazz$ServerboundRenameItemPacket);
|
||||
|
||||
@@ -666,6 +666,48 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> MOVE_AND_ROTATION_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) Reflections.field$ClientboundMoveEntityPacket$entityId.get(packet);
|
||||
if (BukkitFurnitureManager.instance().isFurnitureBaseEntity(entityId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (BukkitFurnitureManager.instance().isFurnitureCollisionEntity(entityId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundMoveEntityPacket$PosRot", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> ROTATE_HEAD = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) Reflections.field$ClientboundRotateHeadPacket$entityId.get(packet);
|
||||
if (BukkitFurnitureManager.instance().isFurnitureBaseEntity(entityId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (BukkitFurnitureManager.instance().isFurnitureCollisionEntity(entityId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundRotateHeadPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_ENTITY_MOTION = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) Reflections.field$ClientboundSetEntityMotionPacket$id.get(packet);
|
||||
if (BukkitFurnitureManager.instance().isFurnitureBaseEntity(entityId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (BukkitFurnitureManager.instance().isFurnitureCollisionEntity(entityId)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSetEntityMotionPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> REMOVE_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
IntList intList = (IntList) Reflections.field$ClientboundRemoveEntitiesPacket$entityIds.get(packet);
|
||||
|
||||
@@ -5930,4 +5930,37 @@ public class Reflections {
|
||||
? ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"af"})
|
||||
: ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"getId", "aj", "ah", "af"})
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$ClientboundMoveEntityPacket$PosRot = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.game.ClientboundMoveEntityPacket$PosRot"),
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$ClientboundRotateHeadPacket = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.game.ClientboundRotateHeadPacket"),
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.game.PacketPlayOutEntityHeadRotation")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Field field$ClientboundRotateHeadPacket$entityId = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$ClientboundRotateHeadPacket, int.class, 0
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$ClientboundSetEntityMotionPacket = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.game.ClientboundSetEntityMotionPacket"),
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.game.PacketPlayOutEntityVelocity")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Field field$ClientboundSetEntityMotionPacket$id = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$ClientboundSetEntityMotionPacket, int.class, 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user