Skip to content

Commit

Permalink
don't queue tasks to be run on netty thread when on the netty thread
Browse files Browse the repository at this point in the history
  • Loading branch information
AoElite committed Jan 21, 2024
1 parent 1827672 commit d13351f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ac/grim/grimac/events/bukkit/PistonEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/ac/grim/grimac/utils/latency/LatencyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d13351f

Please sign in to comment.