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

Fix async event call

Dieser Commit ist enthalten in:
Moulberry 2023-09-06 11:51:45 +08:00
Ursprung 88932668b4
Commit 40493b997e
3 geänderte Dateien mit 11 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -8,7 +8,7 @@ plugins {
} }
group = "com.moulberry.axiom" group = "com.moulberry.axiom"
version = "1.1.0" version = "1.2.1"
description = "Serverside component for Axiom on Paper" description = "Serverside component for Axiom on Paper"
java { java {

Datei anzeigen

@ -26,10 +26,10 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder {
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
int readerIndex = in.readerIndex();
try { try {
int i = in.readableBytes(); int i = in.readableBytes();
if (i != 0) { if (i != 0) {
int readerIndex = in.readerIndex();
FriendlyByteBuf buf = new FriendlyByteBuf(in); FriendlyByteBuf buf = new FriendlyByteBuf(in);
int packetId = buf.readVarInt(); int packetId = buf.readVarInt();
@ -44,9 +44,9 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder {
} }
} }
} }
in.readerIndex(readerIndex);
} }
} catch (Exception e) { } catch (Exception e) {
in.readerIndex(readerIndex);
e.printStackTrace(); e.printStackTrace();
} }

Datei anzeigen

@ -71,16 +71,6 @@ public class SetBlockBufferPacketListener {
if (server == null) return; if (server == null) return;
ResourceKey<Level> worldKey = friendlyByteBuf.readResourceKey(Registries.DIMENSION); ResourceKey<Level> 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 friendlyByteBuf.readUUID(); // Discard, we don't need to associate buffers
boolean continuation = friendlyByteBuf.readBoolean(); boolean continuation = friendlyByteBuf.readBoolean();
@ -91,7 +81,7 @@ public class SetBlockBufferPacketListener {
byte type = friendlyByteBuf.readByte(); byte type = friendlyByteBuf.readByte();
if (type == 0) { if (type == 0) {
BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf); BlockBuffer buffer = BlockBuffer.load(friendlyByteBuf);
applyBlockBuffer(server, buffer, worldKey); applyBlockBuffer(player, server, buffer, worldKey);
} else if (type == 1) { } else if (type == 1) {
BiomeBuffer buffer = BiomeBuffer.load(friendlyByteBuf); BiomeBuffer buffer = BiomeBuffer.load(friendlyByteBuf);
applyBiomeBuffer(server, buffer, worldKey); applyBiomeBuffer(server, buffer, worldKey);
@ -100,11 +90,17 @@ public class SetBlockBufferPacketListener {
} }
} }
private void applyBlockBuffer(MinecraftServer server, BlockBuffer buffer, ResourceKey<Level> worldKey) { private void applyBlockBuffer(ServerPlayer player, MinecraftServer server, BlockBuffer buffer, ResourceKey<Level> worldKey) {
server.execute(() -> { server.execute(() -> {
ServerLevel world = server.getLevel(worldKey); ServerLevel world = server.getLevel(worldKey);
if (world == null) return; 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(); BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
var lightEngine = world.getChunkSource().getLightEngine(); var lightEngine = world.getChunkSource().getLightEngine();