3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-17 05:40:06 +01:00

Use MessageToMessageDecoder instead of ByteToMessageDecoder

Dieser Commit ist enthalten in:
Moulberry 2024-06-27 02:44:54 +08:00
Ursprung a077e31295
Commit 0ed74d0d92

Datei anzeigen

@ -3,8 +3,10 @@ package com.moulberry.axiom.packet;
import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.VersionHelper; import com.moulberry.axiom.VersionHelper;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.papermc.paper.network.ConnectionEvent; import io.papermc.paper.network.ConnectionEvent;
import net.minecraft.network.Connection; import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
@ -14,7 +16,7 @@ import net.minecraft.server.level.ServerPlayer;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
public class AxiomBigPayloadHandler extends ByteToMessageDecoder { public class AxiomBigPayloadHandler extends MessageToMessageDecoder<ByteBuf> {
private static final ResourceLocation SET_BUFFER = VersionHelper.createResourceLocation("axiom", "set_buffer"); private static final ResourceLocation SET_BUFFER = VersionHelper.createResourceLocation("axiom", "set_buffer");
private static final ResourceLocation UPLOAD_BLUEPRINT = VersionHelper.createResourceLocation("axiom", "upload_blueprint"); private static final ResourceLocation UPLOAD_BLUEPRINT = VersionHelper.createResourceLocation("axiom", "upload_blueprint");
@ -44,20 +46,13 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder {
// Don't handle if player doesn't have permission to use Axiom // Don't handle if player doesn't have permission to use Axiom
ServerPlayer player = connection.getPlayer(); ServerPlayer player = connection.getPlayer();
if (player == null || !AxiomPaper.PLUGIN.canUseAxiom(player.getBukkitEntity())) { if (player == null || !AxiomPaper.PLUGIN.canUseAxiom(player.getBukkitEntity())) {
ctx.fireChannelRead(in.retain()); out.add(in.retain());
// Skip remaining bytes
if (in.readableBytes() > 0) {
in.skipBytes(in.readableBytes());
}
return; return;
} }
// Don't process if channel isn't active // Don't process if channel isn't active
if (!ctx.channel().isActive()) { if (!ctx.channel().isActive()) {
if (in.readableBytes() > 0) {
in.skipBytes(in.readableBytes()); in.skipBytes(in.readableBytes());
}
return; return;
} }
@ -100,9 +95,7 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder {
}); });
success = true; success = true;
if (in.readableBytes() > 0) {
in.skipBytes(in.readableBytes()); in.skipBytes(in.readableBytes());
}
return; return;
} }
} }
@ -110,9 +103,7 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder {
if (!(t instanceof IndexOutOfBoundsException)) { if (!(t instanceof IndexOutOfBoundsException)) {
// Skip remaining bytes // Skip remaining bytes
success = true; success = true;
if (in.readableBytes() > 0) {
in.skipBytes(in.readableBytes()); in.skipBytes(in.readableBytes());
}
// Throw error, will disconnect client // Throw error, will disconnect client
throw t; throw t;
@ -123,12 +114,7 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder {
} }
} }
ctx.fireChannelRead(in.retain()); out.add(in.retain());
// Skip remaining bytes
if (in.readableBytes() > 0) {
in.skipBytes(in.readableBytes());
}
} }
@Override @Override