diff --git a/MOD_DEVELOPMENT.md b/MOD_DEVELOPMENT.md index 3e3eac5..3054fdb 100644 --- a/MOD_DEVELOPMENT.md +++ b/MOD_DEVELOPMENT.md @@ -313,6 +313,16 @@ this.events().onMain(ClientCommandEvent.class, event -> }); ``` +The same as an annotated listener method (see [Events](#events)), which filters and cancels: + +```java +@OnClientCommand(module = "Shop", command = "buy", cancel = true) // command optional: every command of the module +void buy(ClientCommandEvent event) { ... } +``` + +`cancel = true` cancels the event before the method runs, so Lua does not receive the command +even when the method throws. + Server to client: `clientCommands().send(player, ...)` and `sendToAll(...)`; the Lua mod receives them in `Events.OnServerCommand`. diff --git a/api/src/main/java/dev/overlord/zomboidforge/api/Events.java b/api/src/main/java/dev/overlord/zomboidforge/api/Events.java index 1a7c137..04bcfea 100644 --- a/api/src/main/java/dev/overlord/zomboidforge/api/Events.java +++ b/api/src/main/java/dev/overlord/zomboidforge/api/Events.java @@ -1,5 +1,6 @@ package dev.overlord.zomboidforge.api; +import dev.overlord.zomboidforge.api.annotations.OnClientCommand; import dev.overlord.zomboidforge.api.annotations.OnMain; import dev.overlord.zomboidforge.api.annotations.OnModThread; @@ -29,18 +30,19 @@ public interface Events Subscription onModThread(Class type, Consumer listener); /** - * Registers the methods of {@code listener} annotated with {@link OnMain} or - * {@link OnModThread}, as {@link #onMain} and {@link #onModThread} do. ZomboidForge registers - * the mod's entry point this way after its constructor and before {@link Mod#onLoad()}; other - * objects opt in through this method. + * Registers the methods of {@code listener} annotated with {@link OnMain}, + * {@link OnModThread}, or {@link OnClientCommand}, as {@link #onMain} and {@link #onModThread} + * do. ZomboidForge registers the mod's entry point this way after its constructor and before + * {@link Mod#onLoad()}; other objects opt in through this method. * *

Each annotated method: *