From d13351f7c097035626fee96c9efa669032a7bd2b Mon Sep 17 00:00:00 2001 From: AoElite <20812471+AoElite@users.noreply.github.com> Date: Sat, 20 Jan 2024 22:34:00 -0500 Subject: [PATCH] don't queue tasks to be run on netty thread when on the netty thread --- .../ac/grim/grimac/events/bukkit/PistonEvent.java | 4 ++-- .../ac/grim/grimac/utils/latency/LatencyUtils.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/ac/grim/grimac/events/bukkit/PistonEvent.java b/src/main/java/ac/grim/grimac/events/bukkit/PistonEvent.java index 2c4402d884..19f04e1e84 100644 --- a/src/main/java/ac/grim/grimac/events/bukkit/PistonEvent.java +++ b/src/main/java/ac/grim/grimac/events/bukkit/PistonEvent.java @@ -58,7 +58,7 @@ public void onPistonPushEvent(BlockPistonExtendEvent event) { for (GrimPlayer player : GrimAPI.INSTANCE.getPlayerDataManager().getEntries()) { if (player.compensatedWorld.isChunkLoaded(event.getBlock().getX() >> 4, event.getBlock().getZ() >> 4)) { PistonData data = new PistonData(BlockFaceHelper.fromBukkitFace(event.getDirection()), boxes, player.lastTransactionSent.get(), true, hasSlimeBlock, hasHoneyBlock); - player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.compensatedWorld.activePistons.add(data)); + player.latencyUtils.addRealTimeTaskAsync(player.lastTransactionSent.get(), () -> player.compensatedWorld.activePistons.add(data)); } } } @@ -111,7 +111,7 @@ public void onPistonRetractEvent(BlockPistonRetractEvent event) { for (GrimPlayer player : GrimAPI.INSTANCE.getPlayerDataManager().getEntries()) { if (player.compensatedWorld.isChunkLoaded(event.getBlock().getX() >> 4, event.getBlock().getZ() >> 4)) { PistonData data = new PistonData(BlockFaceHelper.fromBukkitFace(event.getDirection()), boxes, player.lastTransactionSent.get(), false, hasSlimeBlock, hasHoneyBlock); - player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.compensatedWorld.activePistons.add(data)); + player.latencyUtils.addRealTimeTaskAsync(player.lastTransactionSent.get(), () -> player.compensatedWorld.activePistons.add(data)); } } } diff --git a/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java b/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java index 2487512978..05bdad1f68 100644 --- a/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java +++ b/src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java @@ -16,8 +16,20 @@ public LatencyUtils(GrimPlayer player) { } public void addRealTimeTask(int transaction, Runnable runnable) { + addRealTimeTask(transaction, false, runnable); + } + + public void addRealTimeTaskAsync(int transaction, Runnable runnable) { + addRealTimeTask(transaction, true, runnable); + } + + public void addRealTimeTask(int transaction, boolean async, Runnable runnable) { if (player.lastTransactionReceived.get() >= transaction) { // If the player already responded to this transaction - ChannelHelper.runInEventLoop(player.user.getChannel(), runnable); // Run it sync to player channel + if (async) { + ChannelHelper.runInEventLoop(player.user.getChannel(), runnable); // Run it sync to player channel + } else { + runnable.run(); + } return; } synchronized (this) {