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

Add version independent method for sending custom payload

Dieser Commit ist enthalten in:
Moulberry 2024-03-06 16:16:23 +08:00
Ursprung 51b6ae7010
Commit 90c22fb586
4 geänderte Dateien mit 26 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -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)));
}
}

Datei anzeigen

@ -1,10 +1,9 @@
package com.moulberry.axiom.blueprint; package com.moulberry.axiom.blueprint;
import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.packet.CustomByteArrayPayload; import com.moulberry.axiom.VersionHelper;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
@ -55,9 +54,8 @@ public class ServerBlueprintManager {
buf.writeUtf(""); buf.writeUtf("");
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
var payload = new CustomByteArrayPayload(PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes);
for (ServerPlayer serverPlayer : sendTo) { for (ServerPlayer serverPlayer : sendTo) {
serverPlayer.connection.send(new ClientboundCustomPayloadPacket(payload)); VersionHelper.sendCustomPayload(serverPlayer, PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes);
} }
// Continue // Continue
@ -69,9 +67,8 @@ public class ServerBlueprintManager {
buf.writeUtf(""); buf.writeUtf("");
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
var payload = new CustomByteArrayPayload(PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes);
for (ServerPlayer serverPlayer : sendTo) { for (ServerPlayer serverPlayer : sendTo) {
serverPlayer.connection.send(new ClientboundCustomPayloadPacket(payload)); VersionHelper.sendCustomPayload(serverPlayer, PACKET_BLUEPRINT_MANIFEST_IDENTIFIER, bytes);
} }
} }
} }

Datei anzeigen

@ -1,6 +1,7 @@
package com.moulberry.axiom.packet; package com.moulberry.axiom.packet;
import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.VersionHelper;
import com.moulberry.axiom.blueprint.RawBlueprint; import com.moulberry.axiom.blueprint.RawBlueprint;
import com.moulberry.axiom.blueprint.ServerBlueprintManager; import com.moulberry.axiom.blueprint.ServerBlueprintManager;
import com.moulberry.axiom.blueprint.ServerBlueprintRegistry; import com.moulberry.axiom.blueprint.ServerBlueprintRegistry;
@ -54,8 +55,7 @@ public class BlueprintRequestPacketListener implements PluginMessageListener {
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
var payload = new CustomByteArrayPayload(RESPONSE_PACKET_IDENTIFIER, bytes); VersionHelper.sendCustomPayload(((CraftPlayer)player).getHandle(), RESPONSE_PACKET_IDENTIFIER, bytes);
((CraftPlayer)player).getHandle().connection.send(new ClientboundCustomPayloadPacket(payload));
} }
} }

Datei anzeigen

@ -2,6 +2,7 @@ package com.moulberry.axiom.packet;
import com.moulberry.axiom.AxiomConstants; import com.moulberry.axiom.AxiomConstants;
import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.VersionHelper;
import com.moulberry.axiom.buffer.CompressedBlockEntity; import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.event.AxiomModifyWorldEvent; import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
@ -179,7 +180,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener {
buf.writeBoolean(false); buf.writeBoolean(false);
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
player.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(RESPONSE_ID, bytes))); VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
// Continuation packet // Continuation packet
buf = new FriendlyByteBuf(Unpooled.buffer()); buf = new FriendlyByteBuf(Unpooled.buffer());
@ -199,7 +200,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener {
buf.writeBoolean(false); buf.writeBoolean(false);
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
player.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(RESPONSE_ID, bytes))); VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
// Continuation packet // Continuation packet
buf = new FriendlyByteBuf(Unpooled.buffer()); buf = new FriendlyByteBuf(Unpooled.buffer());
@ -235,7 +236,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener {
buf.writeBoolean(false); buf.writeBoolean(false);
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
player.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(RESPONSE_ID, bytes))); VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
// Continuation packet // Continuation packet
buf = new FriendlyByteBuf(Unpooled.buffer()); buf = new FriendlyByteBuf(Unpooled.buffer());
@ -255,7 +256,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener {
buf.writeBoolean(false); buf.writeBoolean(false);
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
player.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(RESPONSE_ID, bytes))); VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
// Continuation packet // Continuation packet
buf = new FriendlyByteBuf(Unpooled.buffer()); buf = new FriendlyByteBuf(Unpooled.buffer());
@ -275,7 +276,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener {
buf.writeBoolean(true); buf.writeBoolean(true);
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
player.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(RESPONSE_ID, bytes))); VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
} }
private void sendEmptyResponse(ServerPlayer player, long id) { private void sendEmptyResponse(ServerPlayer player, long id) {
@ -287,7 +288,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener {
byte[] bytes = new byte[buf.writerIndex()]; byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes); buf.getBytes(0, bytes);
player.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(RESPONSE_ID, bytes))); VersionHelper.sendCustomPayload(player, RESPONSE_ID, bytes);
} }
} }