From 40493b997e2e79e104eccc0ed7c97517f3a53160 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Wed, 6 Sep 2023 11:51:45 +0800 Subject: [PATCH] Fix async event call --- build.gradle.kts | 2 +- .../axiom/packet/AxiomBigPayloadHandler.java | 4 ++-- .../packet/SetBlockBufferPacketListener.java | 20 ++++++++----------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c0ee842..0121061 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.moulberry.axiom" -version = "1.1.0" +version = "1.2.1" description = "Serverside component for Axiom on Paper" java { diff --git a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java index ec19e9e..10e83e2 100644 --- a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java +++ b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java @@ -26,10 +26,10 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { + int readerIndex = in.readerIndex(); try { int i = in.readableBytes(); if (i != 0) { - int readerIndex = in.readerIndex(); FriendlyByteBuf buf = new FriendlyByteBuf(in); int packetId = buf.readVarInt(); @@ -44,9 +44,9 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder { } } } - in.readerIndex(readerIndex); } } catch (Exception e) { + in.readerIndex(readerIndex); e.printStackTrace(); } diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java index bac9c25..75efc5b 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java @@ -71,16 +71,6 @@ public class SetBlockBufferPacketListener { if (server == null) return; ResourceKey worldKey = friendlyByteBuf.readResourceKey(Registries.DIMENSION); - NamespacedKey namespacedKey = new NamespacedKey(worldKey.location().getNamespace(), worldKey.location().getPath()); - World world = Bukkit.getWorld(namespacedKey); - if (world != null) { - AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(player.getBukkitEntity(), world); - Bukkit.getPluginManager().callEvent(modifyWorldEvent); - if (modifyWorldEvent.isCancelled()) return; - } else { - return; - } - friendlyByteBuf.readUUID(); // Discard, we don't need to associate buffers boolean continuation = friendlyByteBuf.readBoolean(); @@ -91,7 +81,7 @@ public class SetBlockBufferPacketListener { byte type = friendlyByteBuf.readByte(); if (type == 0) { BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf); - applyBlockBuffer(server, buffer, worldKey); + applyBlockBuffer(player, server, buffer, worldKey); } else if (type == 1) { BiomeBuffer buffer = BiomeBuffer.load(friendlyByteBuf); applyBiomeBuffer(server, buffer, worldKey); @@ -100,11 +90,17 @@ public class SetBlockBufferPacketListener { } } - private void applyBlockBuffer(MinecraftServer server, BlockBuffer buffer, ResourceKey worldKey) { + private void applyBlockBuffer(ServerPlayer player, MinecraftServer server, BlockBuffer buffer, ResourceKey worldKey) { server.execute(() -> { ServerLevel world = server.getLevel(worldKey); if (world == null) return; + // Call AxiomModifyWorldEvent event + AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(player.getBukkitEntity(), world.getWorld()); + Bukkit.getPluginManager().callEvent(modifyWorldEvent); + if (modifyWorldEvent.isCancelled()) return; + + // Allowed, apply buffer BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(); var lightEngine = world.getChunkSource().getLightEngine();