Improve command core

This commit is contained in:
Chipmunk 2023-04-19 21:56:51 -04:00
parent d488e865ee
commit efd0003576

View file

@ -39,6 +39,7 @@ public class CommandCore extends SessionAdapter {
// TODO: Make it configurable // TODO: Make it configurable
@Getter private final BlockArea relativeArea = new BlockArea(Vector3i.from(0, 0, 0), Vector3i.from(15, 0, 15)); @Getter private final BlockArea relativeArea = new BlockArea(Vector3i.from(0, 0, 0), Vector3i.from(15, 0, 15));
@Getter @Setter private Vector3i currentBlockRelative; @Getter @Setter private Vector3i currentBlockRelative;
private Timer refillTimer;
@Getter private List<Listener> listeners = new ArrayList<>(); @Getter private List<Listener> listeners = new ArrayList<>();
@ -58,6 +59,7 @@ public class CommandCore extends SessionAdapter {
for (Listener listener : listeners) listener.ready(); for (Listener listener : listeners) listener.ready();
} }
final Vector3i oldOrigin = origin;
origin = Vector3i.from( origin = Vector3i.from(
((int) packet.getX() / 16) * 16, ((int) packet.getX() / 16) * 16,
0, // TODO: Use the actual bottom of the world instead of hardcoding to 0 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()); 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 () { public void refill () {
@ -178,6 +184,10 @@ public class CommandCore extends SessionAdapter {
origin = null; origin = null;
currentBlockRelative = null; currentBlockRelative = null;
ready = false; ready = false;
refillTimer.cancel();
refillTimer.purge();
refillTimer = null;
} }
public static class Listener { public static class Listener {