package NET.worlds.console; import NET.worlds.core.Std; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; public abstract class BlackBoxCommand { int commandType; long startTime; BlackBoxCallback callback; boolean waiting = false; void timestamp(long basetime) { this.startTime = Std.getFastTime() - basetime; } public boolean execute(BlackBoxCallback c) { if (this.waiting) { return false; } else { this.callback = c; if (c != null) { this.waiting = true; } return this.execute(); } } abstract boolean execute(); void save(DataOutputStream dos) throws IOException { dos.writeInt(this.commandType); dos.writeLong(this.startTime); } void load(DataInputStream dis) throws IOException { this.startTime = dis.readLong(); } void doCallback(boolean ok) { if (this.callback != null) { this.waiting = false; this.callback.commandCompleted(this, ok); } } }