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
@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<Listener> 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 {