From 88d9602428964ae13e847ac08c51976478605de9 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Wed, 6 Mar 2024 16:16:23 +0800 Subject: [PATCH] Add version independent method for sending custom payload --- .../java/com/moulberry/axiom/VersionHelper.java | 14 ++++++++++++++ .../axiom/blueprint/ServerBlueprintManager.java | 9 +++------ .../packet/BlueprintRequestPacketListener.java | 4 ++-- .../packet/RequestChunkDataPacketListener.java | 1 + 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/moulberry/axiom/VersionHelper.java diff --git a/src/main/java/com/moulberry/axiom/VersionHelper.java b/src/main/java/com/moulberry/axiom/VersionHelper.java new file mode 100644 index 0000000..2729968 --- /dev/null +++ b/src/main/java/com/moulberry/axiom/VersionHelper.java @@ -0,0 +1,14 @@ +package com.moulberry.axiom; + +import com.moulberry.axiom.packet.CustomByteArrayPayload; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; + +public class VersionHelper { + + public static void sendCustomPayload(ServerPlayer serverPlayer, ResourceLocation id, byte[] data) { + serverPlayer.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(id, data))); + } + +} diff --git a/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java b/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java index dd61107..5d0fa96 100644 --- a/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java +++ b/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java @@ -1,10 +1,9 @@ package com.moulberry.axiom.blueprint; import com.moulberry.axiom.AxiomPaper; -import com.moulberry.axiom.packet.CustomByteArrayPayload; +import com.moulberry.axiom.VersionHelper; import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; @@ -55,9 +54,8 @@ public class ServerBlueprintManager { buf.writeUtf(""); byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); - var payload = new CustomByteArrayPayload(PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes); for (ServerPlayer serverPlayer : sendTo) { - serverPlayer.connection.send(new ClientboundCustomPayloadPacket(payload)); + VersionHelper.sendCustomPayload(serverPlayer, PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes); } // Continue @@ -69,9 +67,8 @@ public class ServerBlueprintManager { buf.writeUtf(""); byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); - var payload = new CustomByteArrayPayload(PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes); for (ServerPlayer serverPlayer : sendTo) { - serverPlayer.connection.send(new ClientboundCustomPayloadPacket(payload)); + VersionHelper.sendCustomPayload(serverPlayer, PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes); } } } diff --git a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java index 9012b6a..760f94e 100644 --- a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java @@ -1,6 +1,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; +import com.moulberry.axiom.VersionHelper; import com.moulberry.axiom.blueprint.RawBlueprint; import com.moulberry.axiom.blueprint.ServerBlueprintManager; import com.moulberry.axiom.blueprint.ServerBlueprintRegistry; @@ -54,8 +55,7 @@ public class BlueprintRequestPacketListener implements PluginMessageListener { byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); - var payload = new CustomByteArrayPayload(RESPONSE_PACKET_IDENTIFIER, bytes); - ((CraftPlayer)player).getHandle().connection.send(new ClientboundCustomPayloadPacket(payload)); + VersionHelper.sendCustomPayload(((CraftPlayer)player).getHandle(), RESPONSE_PACKET_IDENTIFIER, bytes); } } diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java index de8ea5c..14870ff 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -2,6 +2,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomConstants; import com.moulberry.axiom.AxiomPaper; +import com.moulberry.axiom.VersionHelper; import com.moulberry.axiom.buffer.CompressedBlockEntity; import com.moulberry.axiom.event.AxiomModifyWorldEvent; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;