diff --git a/build.gradle.kts b/build.gradle.kts index 5bcdbc5..f6732f2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.moulberry.axiom" -version = "4.0.1" +version = "4.0.2" description = "Serverside component for Axiom on Paper" java { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 47af617..0e0fdce 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,12 +7,12 @@ paper = "1.21.1-R0.1-SNAPSHOT" plotsquared = "7.3.9-20240513.192211-13" reflection-remapper = "0.1.2-20240315.033304-2" viaversion-api = "5.0.1" -worldguard-bukkit = "7.1.0-20240503.180049-12" +worldguard-bukkit = "7.0.9-SNAPSHOT" zstd-jni = "1.5.5-4" # Plugins -paperweight-userdev = "1.7.1" -run-paper = "2.2.4" +paperweight-userdev = "1.7.2" +run-paper = "2.3.0" shadow = "8.1.7" [libraries] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c30b486..171d876 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index 7708303..bf5e09e 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -9,6 +9,25 @@ import com.moulberry.axiom.event.AxiomModifyWorldEvent; import com.moulberry.axiom.integration.coreprotect.CoreProtectIntegration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.packet.*; +import com.moulberry.axiom.packet.impl.BlueprintRequestPacketListener; +import com.moulberry.axiom.packet.impl.DeleteEntityPacketListener; +import com.moulberry.axiom.packet.impl.HelloPacketListener; +import com.moulberry.axiom.packet.impl.ManipulateEntityPacketListener; +import com.moulberry.axiom.packet.impl.MarkerNbtRequestPacketListener; +import com.moulberry.axiom.packet.impl.RequestChunkDataPacketListener; +import com.moulberry.axiom.packet.impl.SetBlockBufferPacketListener; +import com.moulberry.axiom.packet.impl.SetBlockPacketListener; +import com.moulberry.axiom.packet.impl.SetEditorViewsPacketListener; +import com.moulberry.axiom.packet.impl.SetFlySpeedPacketListener; +import com.moulberry.axiom.packet.impl.SetGamemodePacketListener; +import com.moulberry.axiom.packet.impl.SetHotbarSlotPacketListener; +import com.moulberry.axiom.packet.impl.SetTimePacketListener; +import com.moulberry.axiom.packet.impl.SetWorldPropertyListener; +import com.moulberry.axiom.packet.impl.SpawnEntityPacketListener; +import com.moulberry.axiom.packet.impl.SwitchActiveHotbarPacketListener; +import com.moulberry.axiom.packet.impl.TeleportPacketListener; +import com.moulberry.axiom.packet.impl.UpdateAnnotationPacketListener; +import com.moulberry.axiom.packet.impl.UploadBlueprintPacketListener; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -111,67 +130,34 @@ public class AxiomPaper extends JavaPlugin implements Listener { msg.registerOutgoingPluginChannel(this, "axiom:marker_nbt_response"); msg.registerOutgoingPluginChannel(this, "axiom:annotation_update"); - if (configuration.getBoolean("packet-handlers.hello")) { - msg.registerIncomingPluginChannel(this, "axiom:hello", new HelloPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-gamemode")) { - msg.registerIncomingPluginChannel(this, "axiom:set_gamemode", new SetGamemodePacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-fly-speed")) { - msg.registerIncomingPluginChannel(this, "axiom:set_fly_speed", new SetFlySpeedPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-world-time")) { - msg.registerIncomingPluginChannel(this, "axiom:set_world_time", new SetTimePacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-world-property")) { - msg.registerIncomingPluginChannel(this, "axiom:set_world_property", new SetWorldPropertyListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-single-block")) { - msg.registerIncomingPluginChannel(this, "axiom:set_block", new SetBlockPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-hotbar-slot")) { - msg.registerIncomingPluginChannel(this, "axiom:set_hotbar_slot", new SetHotbarSlotPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.switch-active-hotbar")) { - msg.registerIncomingPluginChannel(this, "axiom:switch_active_hotbar", new SwitchActiveHotbarPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.teleport")) { - msg.registerIncomingPluginChannel(this, "axiom:teleport", new TeleportPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.set-editor-views")) { - msg.registerIncomingPluginChannel(this, "axiom:set_editor_views", new SetEditorViewsPacketListener(this)); - } - if (!allowLargeChunkDataRequest) { - if (configuration.getBoolean("packet-handlers.request-chunk-data")) { - msg.registerIncomingPluginChannel(this, "axiom:request_chunk_data", new RequestChunkDataPacketListener(this)); - } - } - if (configuration.getBoolean("packet-handlers.spawn-entity")) { - msg.registerIncomingPluginChannel(this, "axiom:spawn_entity", new SpawnEntityPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.manipulate-entity")) { - msg.registerIncomingPluginChannel(this, "axiom:manipulate_entity", new ManipulateEntityPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.delete-entity")) { - msg.registerIncomingPluginChannel(this, "axiom:delete_entity", new DeleteEntityPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.marker-nbt-request")) { - msg.registerIncomingPluginChannel(this, "axiom:marker_nbt_request", new MarkerNbtRequestPacketListener(this)); - } - if (configuration.getBoolean("packet-handlers.blueprint-request")) { - msg.registerIncomingPluginChannel(this, "axiom:request_blueprint", new BlueprintRequestPacketListener(this)); - } + Map largePayloadHandlers = new HashMap<>(); - if (configuration.getBoolean("packet-handlers.set-buffer")) { - SetBlockBufferPacketListener setBlockBufferPacketListener = new SetBlockBufferPacketListener(this); - UploadBlueprintPacketListener uploadBlueprintPacketListener = new UploadBlueprintPacketListener(this); - UpdateAnnotationPacketListener updateAnnotationPacketListener = new UpdateAnnotationPacketListener(this); - RequestChunkDataPacketListener requestChunkDataPacketListener = allowLargeChunkDataRequest ? - new RequestChunkDataPacketListener(this) : null; + registerPacketHandler("hello", new HelloPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_gamemode", new SetGamemodePacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_fly_speed", new SetFlySpeedPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_world_time", new SetTimePacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_world_property", new SetWorldPropertyListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_block", new SetBlockPacketListener(this), msg, largePayloadHandlers); // set-single-block + registerPacketHandler("set_hotbar_slot", new SetHotbarSlotPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("switch_active_hotbar", new SwitchActiveHotbarPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("teleport", new TeleportPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_editor_views", new SetEditorViewsPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("request_chunk_data", new RequestChunkDataPacketListener(this, + !configuration.getBoolean("packet-handlers.request-chunk-data")), msg, largePayloadHandlers); + registerPacketHandler("spawn_entity", new SpawnEntityPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("manipulate_entity", new ManipulateEntityPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("delete_entity", new DeleteEntityPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("marker_nbt_request", new MarkerNbtRequestPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("request_blueprint", new BlueprintRequestPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("set_buffer", new SetBlockBufferPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("upload_blueprint", new UploadBlueprintPacketListener(this), msg, largePayloadHandlers); + registerPacketHandler("annotation_update", new UpdateAnnotationPacketListener(this), msg, largePayloadHandlers); + + if (!largePayloadHandlers.isEmpty()) { // Hack to figure out the id of the CustomPayload packet ProtocolInfo protocol = GameProtocols.SERVERBOUND_TEMPLATE.bind(k -> new RegistryFriendlyByteBuf(k, - MinecraftServer.getServer().registryAccess())); + MinecraftServer.getServer().registryAccess())); RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), MinecraftServer.getServer().registryAccess()); protocol.codec().encode(friendlyByteBuf, new ServerboundCustomPayloadPacket(new DiscardedPayload(VersionHelper.createResourceLocation("dummy"), Unpooled.buffer()))); int payloadId = friendlyByteBuf.readVarInt(); @@ -181,8 +167,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { public void afterInitChannel(@NonNull Channel channel) { Connection connection = (Connection) channel.pipeline().get("packet_handler"); channel.pipeline().addBefore("decoder", "axiom-big-payload-handler", - new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener, - uploadBlueprintPacketListener, updateAnnotationPacketListener, requestChunkDataPacketListener)); + new AxiomBigPayloadHandler(payloadId, connection, largePayloadHandlers)); } }); } @@ -314,6 +299,35 @@ public class AxiomPaper extends JavaPlugin implements Listener { } } + private void registerPacketHandler(String name, PacketHandler handler, Messenger messenger, Map largePayloadHandlers) { + String configEntry = "packet-handlers." + name.replace("_", "-"); + if (name.equals("set_block")) { + configEntry = "packet-handlers.set-single-block"; + } else if (name.equals("request_blueprint")) { + configEntry = "packet-handlers.blueprint-request"; + } + if (name.equals("request-chunk-data") || this.configuration.getBoolean(configEntry, true)) { + boolean isLargePayload = false; + + if (name.equals("hello")) { // Hello must use normal system, as non-Axiom players can't send large payloads + isLargePayload = false; + } else if (this.configuration.getBoolean("allow-large-payload-for-all-packets")) { + isLargePayload = true; + } else if (name.equals("set_buffer") || name.equals("upload_blueprint") || name.equals("annotation_update")) { + isLargePayload = true; + } else if (name.equals("request_chunk_data") && this.configuration.getBoolean("allow-large-chunk-data-request")) { + isLargePayload = true; + } + + if (isLargePayload) { + largePayloadHandlers.put("axiom:"+name, handler); + messenger.registerIncomingPluginChannel(this, "axiom:"+name, new DummyPacketListener()); + } else { + messenger.registerIncomingPluginChannel(this, "axiom:"+name, new WrapperPacketListener(handler)); + } + } + } + private int calculateAllowedCapabilities() { Set allowed = new HashSet<>(this.configuration.getStringList("allow-capabilities")); if (allowed.contains("all")) { diff --git a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java index e1c4557..bedf17b 100644 --- a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java +++ b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java @@ -2,42 +2,36 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.VersionHelper; +import com.moulberry.axiom.packet.impl.RequestChunkDataPacketListener; +import com.moulberry.axiom.packet.impl.SetBlockBufferPacketListener; +import com.moulberry.axiom.packet.impl.UpdateAnnotationPacketListener; +import com.moulberry.axiom.packet.impl.UploadBlueprintPacketListener; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandler; +import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder; import io.papermc.paper.network.ConnectionEvent; +import net.kyori.adventure.text.Component; import net.minecraft.network.Connection; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import org.bukkit.entity.Player; import java.io.IOException; import java.util.List; +import java.util.Map; public class AxiomBigPayloadHandler extends MessageToMessageDecoder { - 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 UPDATE_ANNOTATIONS = VersionHelper.createResourceLocation("axiom", "annotation_update"); - private static final ResourceLocation REQUEST_CHUNK_DATA = VersionHelper.createResourceLocation("axiom", "request_chunk_data"); private final int payloadId; private final Connection connection; - private final SetBlockBufferPacketListener setBlockBuffer; - private final UploadBlueprintPacketListener uploadBlueprint; - private final UpdateAnnotationPacketListener updateAnnotation; - private final RequestChunkDataPacketListener requestChunkDataPacketListener; + private final Map packetHandlers; - public AxiomBigPayloadHandler(int payloadId, Connection connection, SetBlockBufferPacketListener setBlockBuffer, - UploadBlueprintPacketListener uploadBlueprint, UpdateAnnotationPacketListener updateAnnotation, - RequestChunkDataPacketListener requestChunkDataPacketListener) { + public AxiomBigPayloadHandler(int payloadId, Connection connection, Map packetHandlers) { this.payloadId = payloadId; this.connection = connection; - this.setBlockBuffer = setBlockBuffer; - this.uploadBlueprint = uploadBlueprint; - this.updateAnnotation = updateAnnotation; - this.requestChunkDataPacketListener = requestChunkDataPacketListener; + this.packetHandlers = packetHandlers; } @Override @@ -67,47 +61,29 @@ public class AxiomBigPayloadHandler extends MessageToMessageDecoder { int packetId = buf.readVarInt(); if (packetId == payloadId) { - ResourceLocation identifier = buf.readResourceLocation(); - if (identifier.equals(SET_BUFFER)) { - setBlockBuffer.onReceive(player, buf); - success = true; - if (in.readableBytes() > 0) { - throw new IOException("Axiom packet " + identifier + " was larger than I expected, found " + in.readableBytes() + - " bytes extra whilst reading packet"); - } - return; - } else if (identifier.equals(UPLOAD_BLUEPRINT)) { - uploadBlueprint.onReceive(player, buf); - success = true; - if (in.readableBytes() > 0) { - throw new IOException("Axiom packet " + identifier + " was larger than I expected, found " + in.readableBytes() + - " bytes extra whilst reading packet"); - } - return; - } else if (identifier.equals(UPDATE_ANNOTATIONS)) { - updateAnnotation.onReceive(player, buf); - success = true; - if (in.readableBytes() > 0) { - throw new IOException("Axiom packet " + identifier + " was larger than I expected, found " + in.readableBytes() + - " bytes extra whilst reading packet"); - } - return; - } else if (requestChunkDataPacketListener != null && identifier.equals(REQUEST_CHUNK_DATA)) { - byte[] bytes = new byte[buf.writerIndex() - buf.readerIndex()]; - buf.getBytes(buf.readerIndex(), bytes); + String identifier = buf.readUtf(32767); + PacketHandler handler = this.packetHandlers.get(identifier); + if (handler != null) { + if (handler.handleAsync()) { + handler.onReceive(player.getBukkitEntity(), buf); + success = true; + } else { + byte[] bytes = new byte[buf.writerIndex() - buf.readerIndex()]; + buf.getBytes(buf.readerIndex(), bytes); + Player bukkitPlayer = player.getBukkitEntity(); - player.getServer().execute(() -> { - try { - requestChunkDataPacketListener.onPluginMessageReceived( - identifier.toString(), player.getBukkitEntity(), bytes); - } catch (Throwable t) { - player.getBukkitEntity().kick(net.kyori.adventure.text.Component.text( - "An error occured while requesting chunk data: " + t.getMessage())); - } - }); + player.getServer().execute(() -> { + FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes)); + try { + handler.onReceive(bukkitPlayer, friendlyByteBuf); + } catch (Throwable t) { + bukkitPlayer.kick(Component.text("Error while processing packet " + identifier + ": " + t.getMessage())); + } + }); - success = true; - in.skipBytes(in.readableBytes()); + success = true; + in.readerIndex(in.writerIndex()); + } return; } } @@ -134,7 +110,7 @@ public class AxiomBigPayloadHandler extends MessageToMessageDecoder { if (evt == ConnectionEvent.COMPRESSION_THRESHOLD_SET || evt == ConnectionEvent.COMPRESSION_DISABLED) { ctx.channel().pipeline().remove("axiom-big-payload-handler"); ctx.channel().pipeline().addBefore("decoder", "axiom-big-payload-handler", - new AxiomBigPayloadHandler(payloadId, connection, setBlockBuffer, uploadBlueprint, updateAnnotation, requestChunkDataPacketListener)); + new AxiomBigPayloadHandler(payloadId, connection, packetHandlers)); } super.userEventTriggered(ctx, evt); } diff --git a/src/main/java/com/moulberry/axiom/packet/DummyPacketListener.java b/src/main/java/com/moulberry/axiom/packet/DummyPacketListener.java new file mode 100644 index 0000000..edfdb02 --- /dev/null +++ b/src/main/java/com/moulberry/axiom/packet/DummyPacketListener.java @@ -0,0 +1,18 @@ +package com.moulberry.axiom.packet; + +import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; +import net.minecraft.network.FriendlyByteBuf; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; +import org.jetbrains.annotations.NotNull; + +public class DummyPacketListener implements PluginMessageListener { + + public DummyPacketListener() { + } + + @Override + public void onPluginMessageReceived(@NotNull String s, @NotNull Player player, @NotNull byte[] bytes) { + } +} diff --git a/src/main/java/com/moulberry/axiom/packet/PacketHandler.java b/src/main/java/com/moulberry/axiom/packet/PacketHandler.java new file mode 100644 index 0000000..9fe0bb6 --- /dev/null +++ b/src/main/java/com/moulberry/axiom/packet/PacketHandler.java @@ -0,0 +1,15 @@ +package com.moulberry.axiom.packet; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.entity.Player; + +public interface PacketHandler { + + default boolean handleAsync() { + return false; + } + + void onReceive(Player player, FriendlyByteBuf friendlyByteBuf); + +} diff --git a/src/main/java/com/moulberry/axiom/packet/WrapperPacketListener.java b/src/main/java/com/moulberry/axiom/packet/WrapperPacketListener.java new file mode 100644 index 0000000..9868826 --- /dev/null +++ b/src/main/java/com/moulberry/axiom/packet/WrapperPacketListener.java @@ -0,0 +1,27 @@ +package com.moulberry.axiom.packet; + +import io.netty.buffer.Unpooled; +import net.kyori.adventure.text.Component; +import net.minecraft.network.FriendlyByteBuf; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; +import org.jetbrains.annotations.NotNull; + +public class WrapperPacketListener implements PluginMessageListener { + + private final PacketHandler packetHandler; + + public WrapperPacketListener(PacketHandler packetHandler) { + this.packetHandler = packetHandler; + } + + @Override + public void onPluginMessageReceived(@NotNull String s, @NotNull Player player, @NotNull byte[] bytes) { + FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes)); + try { + this.packetHandler.onReceive(player, friendlyByteBuf); + } catch (Throwable t) { + player.kick(Component.text("Error while processing packet " + s + ": " + t.getMessage())); + } + } +} diff --git a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/BlueprintRequestPacketListener.java similarity index 76% rename from src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/BlueprintRequestPacketListener.java index 98c7b51..1690edc 100644 --- a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/BlueprintRequestPacketListener.java @@ -1,10 +1,11 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; 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; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.SharedConstants; @@ -15,9 +16,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -public class BlueprintRequestPacketListener implements PluginMessageListener { +public class BlueprintRequestPacketListener implements PacketHandler { private final AxiomPaper plugin; public BlueprintRequestPacketListener(AxiomPaper plugin) { @@ -27,15 +26,7 @@ public class BlueprintRequestPacketListener implements PluginMessageListener { private static final ResourceLocation RESPONSE_PACKET_IDENTIFIER = VersionHelper.createResourceLocation("axiom:response_blueprint"); @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.blueprint.request")) { return; } @@ -45,7 +36,6 @@ public class BlueprintRequestPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); String path = friendlyByteBuf.readUtf(); ServerBlueprintRegistry registry = ServerBlueprintManager.getRegistry(); diff --git a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/DeleteEntityPacketListener.java similarity index 76% rename from src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/DeleteEntityPacketListener.java index b74a0e4..8e15906 100644 --- a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/DeleteEntityPacketListener.java @@ -1,8 +1,8 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.integration.Integration; -import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -public class DeleteEntityPacketListener implements PluginMessageListener { +public class DeleteEntityPacketListener implements PacketHandler { private final AxiomPaper plugin; public DeleteEntityPacketListener(AxiomPaper plugin) { @@ -26,15 +26,7 @@ public class DeleteEntityPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.entity.delete", true)) { return; } @@ -43,7 +35,6 @@ public class DeleteEntityPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); List delete = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), buf -> buf.readUUID()); diff --git a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/HelloPacketListener.java similarity index 92% rename from src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/HelloPacketListener.java index e074170..19608c5 100644 --- a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/HelloPacketListener.java @@ -1,15 +1,14 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.google.common.util.concurrent.RateLimiter; import com.moulberry.axiom.*; -import com.moulberry.axiom.annotations.ServerAnnotations; import com.moulberry.axiom.blueprint.ServerBlueprintManager; import com.moulberry.axiom.event.AxiomHandshakeEvent; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.persistence.ItemStackDataType; import com.moulberry.axiom.persistence.UUIDDataType; import com.moulberry.axiom.viaversion.ViaVersionHelper; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; @@ -30,13 +29,11 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.plugin.messaging.PluginMessageListener; -import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.UUID; -public class HelloPacketListener implements PluginMessageListener { +public class HelloPacketListener implements PacketHandler { private final AxiomPaper plugin; @@ -45,20 +42,11 @@ public class HelloPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.hasAxiomPermission(player)) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); int apiVersion = friendlyByteBuf.readVarInt(); if (apiVersion != AxiomConstants.API_VERSION) { diff --git a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/ManipulateEntityPacketListener.java similarity index 93% rename from src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/ManipulateEntityPacketListener.java index 7cab623..14c10b8 100644 --- a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/ManipulateEntityPacketListener.java @@ -1,12 +1,11 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.NbtSanitization; import com.moulberry.axiom.event.AxiomManipulateEntityEvent; import com.moulberry.axiom.integration.Integration; -import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.viaversion.UnknownVersionHelper; -import com.moulberry.axiom.viaversion.ViaVersionHelper; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; @@ -34,7 +33,7 @@ import java.util.List; import java.util.Set; import java.util.UUID; -public class ManipulateEntityPacketListener implements PluginMessageListener { +public class ManipulateEntityPacketListener implements PacketHandler { private final AxiomPaper plugin; public ManipulateEntityPacketListener(AxiomPaper plugin) { @@ -82,15 +81,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { private static final Rotation[] ROTATION_VALUES = Rotation.values(); @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate", true)) { return; } @@ -99,7 +90,6 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); List entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), buf -> ManipulateEntry.read(buf, player)); diff --git a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/MarkerNbtRequestPacketListener.java similarity index 72% rename from src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/MarkerNbtRequestPacketListener.java index 0902d2c..4b1fec3 100644 --- a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/MarkerNbtRequestPacketListener.java @@ -1,7 +1,8 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.marker.MarkerData; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.nbt.CompoundTag; @@ -16,7 +17,7 @@ import org.jetbrains.annotations.NotNull; import java.util.UUID; -public class MarkerNbtRequestPacketListener implements PluginMessageListener { +public class MarkerNbtRequestPacketListener implements PacketHandler { private final AxiomPaper plugin; public MarkerNbtRequestPacketListener(AxiomPaper plugin) { @@ -24,15 +25,7 @@ public class MarkerNbtRequestPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate", true)) { return; } @@ -41,7 +34,6 @@ public class MarkerNbtRequestPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); UUID uuid = friendlyByteBuf.readUUID(); ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle(); diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/RequestChunkDataPacketListener.java similarity index 93% rename from src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/RequestChunkDataPacketListener.java index aeece54..98d24a9 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/RequestChunkDataPacketListener.java @@ -1,10 +1,11 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; 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.integration.plotsquared.PlotSquaredIntegration; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.longs.*; import net.kyori.adventure.text.Component; @@ -32,30 +33,23 @@ import org.jetbrains.annotations.NotNull; import java.io.ByteArrayOutputStream; -public class RequestChunkDataPacketListener implements PluginMessageListener { +public class RequestChunkDataPacketListener implements PacketHandler { private static final ResourceLocation RESPONSE_ID = VersionHelper.createResourceLocation("axiom:response_chunk_data"); private final AxiomPaper plugin; - public RequestChunkDataPacketListener(AxiomPaper plugin) { + private final boolean forceFail; + public RequestChunkDataPacketListener(AxiomPaper plugin, boolean forceFail) { this.plugin = plugin; + this.forceFail = forceFail; } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player bukkitPlayer, byte[] message) { + public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) { ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle(); - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); long id = friendlyByteBuf.readLong(); - if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.chunk.request") || this.plugin.isMismatchedDataVersion(bukkitPlayer.getUniqueId())) { + if (this.forceFail || !this.plugin.canUseAxiom(bukkitPlayer, "axiom.chunk.request") || this.plugin.isMismatchedDataVersion(bukkitPlayer.getUniqueId())) { // We always send an 'empty' response in order to make the client happy sendEmptyResponse(player, id); return; diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetBlockBufferPacketListener.java similarity index 91% rename from src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetBlockBufferPacketListener.java index 86b5e03..a26a43b 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetBlockBufferPacketListener.java @@ -1,4 +1,4 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.google.common.util.concurrent.RateLimiter; import com.moulberry.axiom.AxiomPaper; @@ -9,6 +9,7 @@ import com.moulberry.axiom.buffer.CompressedBlockEntity; import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.SectionPermissionChecker; import com.moulberry.axiom.integration.coreprotect.CoreProtectIntegration; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.viaversion.UnknownVersionHelper; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; @@ -41,6 +42,8 @@ import net.minecraft.world.level.chunk.PalettedContainer; import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.lighting.LightEngine; import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; import xyz.jpenilla.reflectionremapper.ReflectionRemapper; import java.lang.reflect.InvocationTargetException; @@ -48,11 +51,10 @@ import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; -public class SetBlockBufferPacketListener { +public class SetBlockBufferPacketListener implements PacketHandler { private final AxiomPaper plugin; private final Method updateBlockEntityTicker; - private final WeakHashMap packetRateLimiter = new WeakHashMap<>(); public SetBlockBufferPacketListener(AxiomPaper plugin) { this.plugin = plugin; @@ -69,8 +71,14 @@ public class SetBlockBufferPacketListener { } } - public void onReceive(ServerPlayer player, FriendlyByteBuf friendlyByteBuf) { - MinecraftServer server = player.getServer(); + @Override + public boolean handleAsync() { + return true; + } + + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { + ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle(); + MinecraftServer server = serverPlayer.getServer(); if (server == null) return; ResourceKey worldKey = friendlyByteBuf.readResourceKey(Registries.DIMENSION); @@ -78,42 +86,42 @@ public class SetBlockBufferPacketListener { boolean continuation = friendlyByteBuf.readBoolean(); if (!continuation) { - UnknownVersionHelper.skipTagUnknown(friendlyByteBuf, player.getBukkitEntity()); + UnknownVersionHelper.skipTagUnknown(friendlyByteBuf, serverPlayer.getBukkitEntity()); } - RateLimiter rateLimiter = this.plugin.getBlockBufferRateLimiter(player.getUUID()); + RateLimiter rateLimiter = this.plugin.getBlockBufferRateLimiter(serverPlayer.getUUID()); byte type = friendlyByteBuf.readByte(); if (type == 0) { AtomicBoolean reachedRateLimit = new AtomicBoolean(false); - BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf, rateLimiter, reachedRateLimit, this.plugin.getBlockRegistry(player.getUUID())); + BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf, rateLimiter, reachedRateLimit, this.plugin.getBlockRegistry(serverPlayer.getUUID())); if (reachedRateLimit.get()) { - player.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second") + serverPlayer.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second") .withStyle(ChatFormatting.RED)); } if (this.plugin.logLargeBlockBufferChanges()) { - this.plugin.getLogger().info("Player " + player.getUUID() + " modified " + buffer.entrySet().size() + " chunk sections (blocks)"); + this.plugin.getLogger().info("Player " + serverPlayer.getUUID() + " modified " + buffer.entrySet().size() + " chunk sections (blocks)"); if (buffer.getTotalBlockEntities() > 0) { - this.plugin.getLogger().info("Player " + player.getUUID() + " modified " + buffer.getTotalBlockEntities() + " block entities, compressed bytes = " + + this.plugin.getLogger().info("Player " + serverPlayer.getUUID() + " modified " + buffer.getTotalBlockEntities() + " block entities, compressed bytes = " + buffer.getTotalBlockEntityBytes()); } } - applyBlockBuffer(player, server, buffer, worldKey); + applyBlockBuffer(serverPlayer, server, buffer, worldKey); } else if (type == 1) { AtomicBoolean reachedRateLimit = new AtomicBoolean(false); BiomeBuffer buffer = BiomeBuffer.load(friendlyByteBuf, rateLimiter, reachedRateLimit); if (reachedRateLimit.get()) { - player.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second") + serverPlayer.sendSystemMessage(Component.literal("[Axiom] Exceeded server rate-limit of " + (int)rateLimiter.getRate() + " sections per second") .withStyle(ChatFormatting.RED)); } if (this.plugin.logLargeBlockBufferChanges()) { - this.plugin.getLogger().info("Player " + player.getUUID() + " modified " + buffer.size() + " chunk sections (biomes)"); + this.plugin.getLogger().info("Player " + serverPlayer.getUUID() + " modified " + buffer.size() + " chunk sections (biomes)"); } - applyBiomeBuffer(player, server, buffer, worldKey); + applyBiomeBuffer(serverPlayer, server, buffer, worldKey); } else { throw new RuntimeException("Unknown buffer type: " + type); } diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetBlockPacketListener.java similarity index 96% rename from src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetBlockPacketListener.java index 3c56f1a..6fc5f4c 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetBlockPacketListener.java @@ -1,9 +1,10 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.google.common.collect.Maps; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.coreprotect.CoreProtectIntegration; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; @@ -54,7 +55,7 @@ import java.util.Objects; import java.util.Optional; import java.util.function.IntFunction; -public class SetBlockPacketListener implements PluginMessageListener { +public class SetBlockPacketListener implements PacketHandler { private final AxiomPaper plugin; private final Method updateBlockEntityTicker; @@ -74,22 +75,14 @@ public class SetBlockPacketListener implements PluginMessageListener { } } - @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - public static class AxiomPlacingCraftBlockState extends CraftBlockState { public AxiomPlacingCraftBlockState(@Nullable World world, BlockPos blockPosition, BlockState blockData) { super(world, blockPosition, blockData); } } - private void process(Player bukkitPlayer, byte[] message) { + @Override + public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.build.place")) { return; } @@ -99,7 +92,6 @@ public class SetBlockPacketListener implements PluginMessageListener { } // Read packet - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); IntFunction> mapFunction = FriendlyByteBuf.limitValue(Maps::newLinkedHashMapWithExpectedSize, 512); IdMapper registry = this.plugin.getBlockRegistry(bukkitPlayer.getUniqueId()); Map blocks = friendlyByteBuf.readMap(mapFunction, diff --git a/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetEditorViewsPacketListener.java similarity index 74% rename from src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetEditorViewsPacketListener.java index e718080..01e1a56 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetEditorViewsPacketListener.java @@ -1,9 +1,10 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.google.common.collect.Lists; import com.moulberry.axiom.AxiomConstants; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.View; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.persistence.UUIDDataType; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; @@ -18,7 +19,7 @@ import java.util.List; import java.util.UUID; import java.util.function.IntFunction; -public class SetEditorViewsPacketListener implements PluginMessageListener { +public class SetEditorViewsPacketListener implements PacketHandler { private final AxiomPaper plugin; public SetEditorViewsPacketListener(AxiomPaper plugin) { @@ -26,20 +27,11 @@ public class SetEditorViewsPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.editor.views")) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); UUID uuid = friendlyByteBuf.readUUID(); IntFunction> listFunction = FriendlyByteBuf.limitValue(Lists::newArrayListWithCapacity, 64); List views = friendlyByteBuf.readCollection(listFunction, View::read); diff --git a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetFlySpeedPacketListener.java similarity index 64% rename from src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetFlySpeedPacketListener.java index 421e745..5d8683c 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetFlySpeedPacketListener.java @@ -1,7 +1,8 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomFlySpeedChangeEvent; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; @@ -11,7 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class SetFlySpeedPacketListener implements PluginMessageListener { +public class SetFlySpeedPacketListener implements PacketHandler { private final AxiomPaper plugin; public SetFlySpeedPacketListener(AxiomPaper plugin) { @@ -19,20 +20,11 @@ public class SetFlySpeedPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.player.speed")) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); float flySpeed = friendlyByteBuf.readFloat(); // Call event diff --git a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetGamemodePacketListener.java similarity index 66% rename from src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetGamemodePacketListener.java index de1c535..85025a8 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetGamemodePacketListener.java @@ -1,7 +1,8 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomGameModeChangeEvent; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; @@ -13,7 +14,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class SetGamemodePacketListener implements PluginMessageListener { +public class SetGamemodePacketListener implements PacketHandler { private final AxiomPaper plugin; public SetGamemodePacketListener(AxiomPaper plugin) { @@ -21,20 +22,11 @@ public class SetGamemodePacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.player.gamemode")) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); GameType gameType = GameType.byId(friendlyByteBuf.readByte()); // Call event diff --git a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetHotbarSlotPacketListener.java similarity index 71% rename from src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetHotbarSlotPacketListener.java index f8a1a67..9a20d5c 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetHotbarSlotPacketListener.java @@ -1,9 +1,9 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomConstants; import com.moulberry.axiom.AxiomPaper; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.persistence.ItemStackDataType; -import com.viaversion.viaversion.api.Via; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; @@ -18,7 +18,7 @@ import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class SetHotbarSlotPacketListener implements PluginMessageListener { +public class SetHotbarSlotPacketListener implements PacketHandler { private final AxiomPaper plugin; public SetHotbarSlotPacketListener(AxiomPaper plugin) { @@ -26,20 +26,11 @@ public class SetHotbarSlotPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { return; } - RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(message), ((CraftPlayer)player).getHandle().registryAccess()); int index = friendlyByteBuf.readByte(); if (index < 0 || index >= 9*9) return; net.minecraft.world.item.ItemStack nmsStack = ItemStack.OPTIONAL_STREAM_CODEC.decode(friendlyByteBuf); diff --git a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetTimePacketListener.java similarity index 78% rename from src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetTimePacketListener.java index f1bca47..fbc9eb4 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetTimePacketListener.java @@ -1,8 +1,9 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomTimeChangeEvent; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.core.registries.Registries; @@ -17,7 +18,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class SetTimePacketListener implements PluginMessageListener { +public class SetTimePacketListener implements PacketHandler { private final AxiomPaper plugin; public SetTimePacketListener(AxiomPaper plugin) { @@ -25,20 +26,11 @@ public class SetTimePacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.world.time")) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); ResourceKey key = friendlyByteBuf.readResourceKey(Registries.DIMENSION); Integer time = friendlyByteBuf.readNullable(FriendlyByteBuf::readInt); Boolean freezeTime = friendlyByteBuf.readNullable(FriendlyByteBuf::readBoolean); diff --git a/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SetWorldPropertyListener.java similarity index 78% rename from src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SetWorldPropertyListener.java index 73bd459..6352ac6 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SetWorldPropertyListener.java @@ -1,7 +1,8 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; import com.moulberry.axiom.world_properties.server.ServerWorldPropertyHolder; import io.netty.buffer.Unpooled; @@ -12,7 +13,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class SetWorldPropertyListener implements PluginMessageListener { +public class SetWorldPropertyListener implements PacketHandler { private final AxiomPaper plugin; public SetWorldPropertyListener(AxiomPaper plugin) { @@ -20,20 +21,11 @@ public class SetWorldPropertyListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.world.property")) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); ResourceLocation id = friendlyByteBuf.readResourceLocation(); int type = friendlyByteBuf.readVarInt(); byte[] data = friendlyByteBuf.readByteArray(); diff --git a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SpawnEntityPacketListener.java similarity index 87% rename from src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SpawnEntityPacketListener.java index 90543ee..fddadc4 100644 --- a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SpawnEntityPacketListener.java @@ -1,11 +1,10 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.NbtSanitization; import com.moulberry.axiom.integration.Integration; -import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.viaversion.UnknownVersionHelper; -import com.moulberry.axiom.viaversion.ViaVersionHelper; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; @@ -32,7 +31,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; -public class SpawnEntityPacketListener implements PluginMessageListener { +public class SpawnEntityPacketListener implements PacketHandler { private final AxiomPaper plugin; public SpawnEntityPacketListener(AxiomPaper plugin) { @@ -46,15 +45,7 @@ public class SpawnEntityPacketListener implements PluginMessageListener { private static final Rotation[] ROTATION_VALUES = Rotation.values(); @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.entity.spawn", true)) { return; } @@ -63,7 +54,6 @@ public class SpawnEntityPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); List entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), buf -> new SpawnEntry(buf.readUUID(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readFloat(), buf.readFloat(), diff --git a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/SwitchActiveHotbarPacketListener.java similarity index 80% rename from src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/SwitchActiveHotbarPacketListener.java index f1056ef..b84e549 100644 --- a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/SwitchActiveHotbarPacketListener.java @@ -1,7 +1,8 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomConstants; import com.moulberry.axiom.AxiomPaper; +import com.moulberry.axiom.packet.PacketHandler; import com.moulberry.axiom.persistence.ItemStackDataType; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; @@ -19,7 +20,7 @@ import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class SwitchActiveHotbarPacketListener implements PluginMessageListener { +public class SwitchActiveHotbarPacketListener implements PacketHandler { private final AxiomPaper plugin; public SwitchActiveHotbarPacketListener(AxiomPaper plugin) { @@ -27,20 +28,11 @@ public class SwitchActiveHotbarPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { return; } - RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(message), ((CraftPlayer)player).getHandle().registryAccess()); int oldHotbarIndex = friendlyByteBuf.readByte(); int activeHotbarIndex = friendlyByteBuf.readByte(); diff --git a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/TeleportPacketListener.java similarity index 81% rename from src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/TeleportPacketListener.java index dfbeb82..859b752 100644 --- a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/TeleportPacketListener.java @@ -1,8 +1,9 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomUnknownTeleportEvent; import com.moulberry.axiom.event.AxiomTeleportEvent; +import com.moulberry.axiom.packet.PacketHandler; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.core.registries.Registries; @@ -16,7 +17,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; -public class TeleportPacketListener implements PluginMessageListener { +public class TeleportPacketListener implements PacketHandler { private final AxiomPaper plugin; public TeleportPacketListener(AxiomPaper plugin) { @@ -24,20 +25,11 @@ public class TeleportPacketListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - try { - this.process(player, message); - } catch (Throwable t) { - player.kick(Component.text("Error while processing packet " + channel + ": " + t.getMessage())); - } - } - - private void process(Player player, byte[] message) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { if (!this.plugin.canUseAxiom(player, "axiom.world.teleport")) { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); ResourceKey resourceKey = friendlyByteBuf.readResourceKey(Registries.DIMENSION); double x = friendlyByteBuf.readDouble(); double y = friendlyByteBuf.readDouble(); diff --git a/src/main/java/com/moulberry/axiom/packet/UpdateAnnotationPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/UpdateAnnotationPacketListener.java similarity index 67% rename from src/main/java/com/moulberry/axiom/packet/UpdateAnnotationPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/UpdateAnnotationPacketListener.java index 774a3e5..3c12f56 100644 --- a/src/main/java/com/moulberry/axiom/packet/UpdateAnnotationPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/UpdateAnnotationPacketListener.java @@ -1,38 +1,36 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.annotations.AnnotationUpdateAction; import com.moulberry.axiom.annotations.ServerAnnotations; -import com.moulberry.axiom.blueprint.BlueprintIo; -import com.moulberry.axiom.blueprint.RawBlueprint; -import com.moulberry.axiom.blueprint.ServerBlueprintManager; -import com.moulberry.axiom.blueprint.ServerBlueprintRegistry; -import net.minecraft.SharedConstants; +import com.moulberry.axiom.packet.PacketHandler; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -public class UpdateAnnotationPacketListener { +public class UpdateAnnotationPacketListener implements PacketHandler { private final AxiomPaper plugin; public UpdateAnnotationPacketListener(AxiomPaper plugin) { this.plugin = plugin; } - public void onReceive(ServerPlayer serverPlayer, FriendlyByteBuf friendlyByteBuf) { - if (!this.plugin.allowAnnotations || !this.plugin.canUseAxiom(serverPlayer.getBukkitEntity(), "axiom.annotation.create")) { + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { + if (!this.plugin.allowAnnotations || !this.plugin.canUseAxiom(player, "axiom.annotation.create")) { friendlyByteBuf.writerIndex(friendlyByteBuf.readerIndex()); return; } + if (!this.plugin.canModifyWorld(player, player.getWorld())) { + return; + } + + ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle(); + // Read actions int length = friendlyByteBuf.readVarInt(); List actions = new ArrayList<>(Math.min(256, length)); diff --git a/src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java b/src/main/java/com/moulberry/axiom/packet/impl/UploadBlueprintPacketListener.java similarity index 84% rename from src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java rename to src/main/java/com/moulberry/axiom/packet/impl/UploadBlueprintPacketListener.java index d950c5a..e667ab2 100644 --- a/src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/impl/UploadBlueprintPacketListener.java @@ -1,14 +1,17 @@ -package com.moulberry.axiom.packet; +package com.moulberry.axiom.packet.impl; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.blueprint.BlueprintIo; import com.moulberry.axiom.blueprint.RawBlueprint; import com.moulberry.axiom.blueprint.ServerBlueprintManager; import com.moulberry.axiom.blueprint.ServerBlueprintRegistry; +import com.moulberry.axiom.packet.PacketHandler; import net.minecraft.SharedConstants; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; import java.io.BufferedOutputStream; import java.io.IOException; @@ -16,19 +19,26 @@ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; -public class UploadBlueprintPacketListener { +public class UploadBlueprintPacketListener implements PacketHandler { private final AxiomPaper plugin; public UploadBlueprintPacketListener(AxiomPaper plugin) { this.plugin = plugin; } - public void onReceive(ServerPlayer serverPlayer, FriendlyByteBuf friendlyByteBuf) { - if (!this.plugin.canUseAxiom(serverPlayer.getBukkitEntity(), "axiom.blueprint.upload")) { + @Override + public boolean handleAsync() { + return true; + } + + public void onReceive(Player player, FriendlyByteBuf friendlyByteBuf) { + if (!this.plugin.canUseAxiom(player, "axiom.blueprint.upload")) { friendlyByteBuf.writerIndex(friendlyByteBuf.readerIndex()); return; } + ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle(); + if (this.plugin.isMismatchedDataVersion(serverPlayer.getUUID())) { serverPlayer.sendSystemMessage(Component.literal("Axiom+ViaVersion: This feature isn't supported. Switch your client version to " + SharedConstants.VERSION_STRING + " to use this")); return; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f8f2b7f..dac5f8c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -17,6 +17,9 @@ blueprint-sharing: false # Allow large chunk data requests, not recommended for public servers allow-large-chunk-data-request: false +# Raise the size limit for *all* packets to 2mb instead of 32kb. NOT RECOMMENDED FOR PUBLIC SERVERS +allow-large-payload-for-all-packets: false + # Action to take when a user with an incompatible Minecraft version or Axiom version joins # Valid actions are 'kick' and 'warn' # 'warn' will give the player a warning and disable Axiom @@ -97,4 +100,5 @@ packet-handlers: manipulate-entity: true delete-entity: true marker-nbt-request: true - blueprint-request: true + upload-blueprint: true + annotation-update: true