From efd0003576cdb84ff503783d3ff96844a15198e6 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Wed, 19 Apr 2023 21:56:51 -0400 Subject: [PATCH] Improve command core --- .../chipmunk/chipmunkbot/plugins/CommandCore.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandCore.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandCore.java index 3b46c13..bd36690 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandCore.java @@ -39,6 +39,7 @@ public class CommandCore extends SessionAdapter { // TODO: Make it configurable @Getter private final BlockArea relativeArea = new BlockArea(Vector3i.from(0, 0, 0), Vector3i.from(15, 0, 15)); @Getter @Setter private Vector3i currentBlockRelative; + private Timer refillTimer; @Getter private List listeners = new ArrayList<>(); @@ -58,6 +59,7 @@ public class CommandCore extends SessionAdapter { for (Listener listener : listeners) listener.ready(); } + final Vector3i oldOrigin = origin; origin = Vector3i.from( ((int) packet.getX() / 16) * 16, 0, // TODO: Use the actual bottom of the world instead of hardcoding to 0 @@ -65,7 +67,11 @@ public class CommandCore extends SessionAdapter { ); if (currentBlockRelative == null) currentBlockRelative = Vector3i.from(relativeArea.start()); - refill(); + if (!origin.equals(oldOrigin)) refill(); + + final TimerTask refillTask = new TimerTask () { @Override public void run () { refill(); } }; + refillTimer = new Timer(); + refillTimer.schedule(refillTask, 60L * 1000L, 60L * 1000L); } public void refill () { @@ -178,6 +184,10 @@ public class CommandCore extends SessionAdapter { origin = null; currentBlockRelative = null; ready = false; + + refillTimer.cancel(); + refillTimer.purge(); + refillTimer = null; } public static class Listener {