From c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 12 Feb 2026 22:33:32 -0800 Subject: Initial commit --- NET/worlds/console/BlackBoxCommand.java | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 NET/worlds/console/BlackBoxCommand.java (limited to 'NET/worlds/console/BlackBoxCommand.java') diff --git a/NET/worlds/console/BlackBoxCommand.java b/NET/worlds/console/BlackBoxCommand.java new file mode 100644 index 0000000..bfafc43 --- /dev/null +++ b/NET/worlds/console/BlackBoxCommand.java @@ -0,0 +1,48 @@ +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); + } + } +} -- cgit v1.2.3