Add register listener methods annotated with @OnMain and @OnModThread; validate methods before mod loading.
This commit is contained in:
1 parent
7ac442c4f6
commit
b4d70c3d3a
15 files changed
+605
-13
No files matched your search
+24
-2
@@ -21,7 +21,7 @@ pluginManagement {
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
maven("https://git.security-command.org/api/packages/overlord/maven")
|
||||
mavenCentral()
|
||||
mavenCentral() // the API depends on org.jetbrains:annotations
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +218,28 @@ Listeners are matched by the event's exact class. Events that carry live game ob
|
||||
removed after ten failures; both `onMain` and `onModThread` return a `Subscription` to remove
|
||||
it earlier.
|
||||
|
||||
The same listeners as annotated methods (`dev.overlord.zomboidforge.api.annotations`):
|
||||
|
||||
```java
|
||||
@OnMain
|
||||
void onTick(TickEvent event) { ... }
|
||||
|
||||
@OnModThread
|
||||
void onGreeting(SomeEvent event) { ... }
|
||||
```
|
||||
|
||||
- **The entry point's methods** are registered after its constructor and before `onLoad()`, so
|
||||
they run before the listeners that `onLoad()` registers for the same event. Other objects
|
||||
opt in with `this.events().register(object)`, which returns one `Subscription` for all of
|
||||
their methods. Registering an object twice throws; the entry point is registered already.
|
||||
- **A listener method** returns `void` and has one parameter: the event class, not an
|
||||
interface or an abstract class. It may be static or private, and may be declared in a
|
||||
superclass. An override listens only when it carries the annotation itself.
|
||||
- **Order:** superclass methods first, the methods of one class by name. When two listeners of
|
||||
one event need a specific order, register them with `onMain` instead.
|
||||
- A method that breaks these rules stops the server with every problem in the log;
|
||||
`register` throws an `IllegalArgumentException` instead.
|
||||
|
||||
## Commands
|
||||
|
||||
Admin commands work wherever Project Zomboid's own commands work: in the in-game chat
|
||||
@@ -413,4 +435,4 @@ file system it can reach anything the server can, including other mods' data in
|
||||
|
||||
Main-thread tasks and event listener calls appear in JFR recordings as the event
|
||||
`zomboidforge.ModTask`, with the mod's id and the kind of work (`task`, or `listener` and the
|
||||
event class).
|
||||
event class, followed by `#<method>` for a listener method).
|
||||
Reference in new issue
Block a user