mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 01:19:24 +00:00
处理空包异常
This commit is contained in:
@@ -560,9 +560,20 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
}
|
||||
if (byteBuf.isReadable()) {
|
||||
list.add(byteBuf.retain());
|
||||
} else {
|
||||
throw CancelPacketException.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
if (ExceptionUtils.hasException(cause, CancelPacketException.INSTANCE)) {
|
||||
return;
|
||||
}
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
|
||||
private boolean handleCompression(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
if (this.handledCompression) return false;
|
||||
int compressIndex = ctx.pipeline().names().indexOf("compress");
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.network;
|
||||
|
||||
public class CancelPacketException extends RuntimeException {
|
||||
|
||||
public static final CancelPacketException INSTANCE = new CancelPacketException();
|
||||
}
|
||||
@@ -1275,13 +1275,13 @@ public class PacketConsumers {
|
||||
if (!user.isOnline()) return;
|
||||
BukkitServerPlayer player = (BukkitServerPlayer) user;
|
||||
if (VersionHelper.isFolia()) {
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
player.platformPlayer().getScheduler().run(BukkitCraftEngine.instance().bootstrap(), (t) -> {
|
||||
try {
|
||||
handleSetCreativeSlotPacketOnMainThread(player, packet);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundSetCreativeModeSlotPacket", e);
|
||||
}
|
||||
}, (World) player.world().platformWorld(), (MCUtils.fastFloor(player.x())) >> 4, (MCUtils.fastFloor(player.z())) >> 4);
|
||||
}, () -> {});
|
||||
} else {
|
||||
handleSetCreativeSlotPacketOnMainThread(player, packet);
|
||||
}
|
||||
@@ -1413,16 +1413,13 @@ public class PacketConsumers {
|
||||
Player player = (Player) user.platformPlayer();
|
||||
if (player == null) return;
|
||||
if (VersionHelper.isFolia()) {
|
||||
Location location = player.getLocation();
|
||||
int x = location.getBlockX();
|
||||
int z = location.getBlockZ();
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
player.getScheduler().run(BukkitCraftEngine.instance().bootstrap(), (t) -> {
|
||||
try {
|
||||
handlePickItemFromEntityOnMainThread(player, furniture);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromEntityPacket", e);
|
||||
}
|
||||
}, player.getWorld(), x >> 4, z >> 4);
|
||||
}, () -> {});
|
||||
} else {
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
public final class ExceptionUtils {
|
||||
private ExceptionUtils() {}
|
||||
|
||||
public static boolean hasException(Throwable t, Exception e) {
|
||||
while (t != null) {
|
||||
if (t == e) {
|
||||
return true;
|
||||
}
|
||||
t = t.getCause();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user