diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/BlackBoxCommand.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/BlackBoxCommand.java')
| -rw-r--r-- | NET/worlds/console/BlackBoxCommand.java | 48 |
1 files changed, 48 insertions, 0 deletions
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); + } + } +} |