Add stopwatch command and execute if stopwatch

Adds the stopwatches store saved in data/minecraft/stopwatches.dat, the /stopwatch create, query, restart and remove commands, and the execute if stopwatch condition, with the parse tree and parse fixture updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-10 06:20:08 +02:00
parent 5a5bdf6a9b
commit abb21704dd
10 changed files with 234 additions and 0 deletions
@@ -21,6 +21,7 @@ pub fn register(d: &mut Dispatcher, root: usize) {
item(d, root);
bossbar(d, root);
function(d, root);
stopwatch(d, root);
// return <value> | fail | run <command>
let ret = d.literal(root, "return");
@@ -255,3 +256,32 @@ fn function(d: &mut Dispatcher, root: usize) {
d.executes(path, "function");
}
}
/// stopwatch create <id> | query <id> [<scale>] | restart <id> | remove <id>
fn stopwatch(d: &mut Dispatcher, root: usize) {
let sw = d.literal(root, "stopwatch");
d.requires(sw, GAMEMASTERS);
let create = d.literal(sw, "create");
let id = d.argument(create, "id", ArgType::Id("none"));
d.executes(id, "stopwatch.create");
let query = d.literal(sw, "query");
let id = d.argument(query, "id", ArgType::Id("stopwatches"));
d.executes(id, "stopwatch.query");
let scale = d.argument(
id,
"scale",
ArgType::Double {
min: f64::MIN,
max: f64::MAX,
},
);
d.executes(scale, "stopwatch.query");
for (name, command) in [
("restart", "stopwatch.restart"),
("remove", "stopwatch.remove"),
] {
let l = d.literal(sw, name);
let id = d.argument(l, "id", ArgType::Id("stopwatches"));
d.executes(id, command);
}
}