Skip to content

Commit

Permalink
Move clearing updated blocks logic into an async loop; new ClearRecen…
Browse files Browse the repository at this point in the history
…tlyUpdatedBlocks() class
  • Loading branch information
Axionize committed Nov 25, 2024
1 parent df89d15 commit 97afbd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void onBlockPlace(final BlockPlace place) {
if (iterator.hasNext()) {
StateType stateType = iterator.next().getOldBlockContents().getType();
if (!(stateType.isAir() || Materials.isNoPlaceLiquid(stateType))) {
player.blockHistory.cleanup(currentTick - 2);
return;
}
}
Expand All @@ -67,7 +66,6 @@ public void onBlockPlace(final BlockPlace place) {
place.resync();
}
}
player.blockHistory.cleanup(currentTick - 2);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ac/grim/grimac/manager/TickManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ac.grim.grimac.manager;

import ac.grim.grimac.manager.tick.Tickable;
import ac.grim.grimac.manager.tick.impl.ClearRecentlyUpdatedBlocks;
import ac.grim.grimac.manager.tick.impl.ClientVersionSetter;
import ac.grim.grimac.manager.tick.impl.ResetTick;
import ac.grim.grimac.manager.tick.impl.TickInventory;
Expand All @@ -22,6 +23,7 @@ public TickManager() {
asyncTick = new ImmutableClassToInstanceMap.Builder<Tickable>()
.put(ClientVersionSetter.class, new ClientVersionSetter()) // Async because permission lookups might take a while, depending on the plugin
.put(TickInventory.class, new TickInventory()) // Async because I've never gotten an exception from this. It's probably safe.
.put(ClearRecentlyUpdatedBlocks.class, new ClearRecentlyUpdatedBlocks())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ac.grim.grimac.manager.tick.impl;

import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.manager.TickManager;
import ac.grim.grimac.manager.tick.Tickable;
import ac.grim.grimac.player.GrimPlayer;

public class ClearRecentlyUpdatedBlocks implements Tickable {

private static final TickManager tickManager = GrimAPI.INSTANCE.getTickManager();
private static final int maxTickAge = 2;

@Override
public void tick() {
for (GrimPlayer player : GrimAPI.INSTANCE.getPlayerDataManager().getEntries()) {
player.blockHistory.cleanup(tickManager.currentTick - maxTickAge);
}
}
}

0 comments on commit 97afbd8

Please sign in to comment.