Add mod command integration for Build 42: command hooks, lookup extensions, registry, and validation mechanisms. Include corresponding tests and documentation.
This commit is contained in:
1 parent
22077514fe
commit
af7174e128
26 files changed
+1117
-30
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package dev.overlord.zomboidforge.api;
|
||||
|
||||
/**
|
||||
* Registration of admin commands. A registered command works wherever Project Zomboid's own
|
||||
* admin commands work: in the in-game chat ({@code /name}), the server console, and RCON. It
|
||||
* is looked up after the commands of Project Zomboid and runs on the main thread.
|
||||
*
|
||||
* <p>A command is a class of the running Project Zomboid version's command framework, so a mod
|
||||
* that registers commands declares {@code game} versions in {@code mod.toml}. In Build 42 it is
|
||||
* a public, non-abstract subclass of {@code zombie.commands.CommandBase} with:
|
||||
* <ul>
|
||||
* <li>one public constructor {@code (String username, Role role, String command, UdpConnection connection)},
|
||||
* which passes its arguments to {@code super};</li>
|
||||
* <li>at least one {@code @CommandName}; names consist of letters, digits, and {@code _}, and
|
||||
* differ (ignoring case) from every name of Project Zomboid and of other mods;</li>
|
||||
* <li>at least one {@code @RequiredCapability}; Project Zomboid refuses to run a command
|
||||
* without one;</li>
|
||||
* <li>optionally {@code @CommandArgs} (argument patterns) and {@code @CommandHelp}
|
||||
* ({@code help <name>} and the {@code help} list).</li>
|
||||
* </ul>
|
||||
* Project Zomboid creates a new instance for every use and calls its {@code Command()}, whose
|
||||
* result is the reply.
|
||||
*/
|
||||
public interface Commands
|
||||
{
|
||||
/**
|
||||
* Registers {@code command}. Only on the main thread while the mod loads: in the entry point's
|
||||
* constructor or {@link Mod#onLoad()}.
|
||||
*
|
||||
* @throws IllegalArgumentException when {@code command} does not meet the rules above, or is
|
||||
* registered already
|
||||
* @throws IllegalStateException when called later or on another thread
|
||||
*/
|
||||
void register(Class<?> command);
|
||||
}
|
||||
@@ -84,4 +84,7 @@ public abstract class Mod
|
||||
|
||||
/** The mod's tables in the world's {@code zomboidforge.db}; not on the main thread once the server runs. */
|
||||
protected final ModStorage storage() { return this.context.storage(); }
|
||||
|
||||
/** Admin command registration. */
|
||||
protected final Commands commands() { return this.context.commands(); }
|
||||
}
|
||||
@@ -42,4 +42,7 @@ public interface ModContext
|
||||
|
||||
/** The mod's tables in the world's {@code zomboidforge.db}. */
|
||||
ModStorage storage();
|
||||
|
||||
/** Admin command registration. */
|
||||
Commands commands();
|
||||
}
|
||||
Reference in new issue
Block a user