Add support for @Every and @EveryNTicks annotations to schedule periodic and tick-based method execution.
This commit is contained in:
1 parent
b10504e9af
commit
9fcde10fed
11 files changed
+632
-58
No files matched your search
@@ -240,6 +240,25 @@ void onGreeting(SomeEvent event) { ... }
|
||||
- A method that breaks these rules stops the server with every problem in the log;
|
||||
`register` throws an `IllegalArgumentException` instead.
|
||||
|
||||
### Scheduled methods
|
||||
|
||||
```java
|
||||
@Every(value = 1, unit = ChronoUnit.MINUTES) // on zf-mod-<id>; optional: initialDelay, fixedDelay = true
|
||||
void report() { ... }
|
||||
|
||||
@EveryNTicks(10) // on the main thread, every 10th frame
|
||||
void sweep() { ... }
|
||||
```
|
||||
|
||||
- They follow the rules of listener methods, with no parameters. `unit` is `MILLIS`,
|
||||
`SECONDS` (default), `MINUTES`, `HOURS`, or `DAYS`, and also applies to `initialDelay`.
|
||||
- `@Every` starts after the mod's `onServerStarted()` (also when it threw), or at once for an
|
||||
object registered later. Without `fixedDelay`, the period counts from the start of each
|
||||
run; with it, from the end. A run that throws is logged and ends the schedule.
|
||||
- `@EveryNTicks(n)` is a `TickEvent` listener for the ticks n, 2n, ...: it may touch game
|
||||
objects and must return quickly.
|
||||
- Cancelling the object's `Subscription` ends both; stopping the server ends `@Every`.
|
||||
|
||||
## Commands
|
||||
|
||||
Admin commands work wherever Project Zomboid's own commands work: in the in-game chat
|
||||
|
||||
Reference in new issue
Block a user