Interface ModStorage


@NonExtendable public interface ModStorage
The mod's tables in zomboidforge.db, next to the world's save. Every table belongs to the mod; this interface gives no access to the tables of other mods. It is not a security boundary: mod code runs with the server's privileges and can open the file directly.

A record declares a table's columns: String, long/int, double/float, boolean, byte[], UUID, Instant, and enums. Primitive components cannot be null. Table and column names are snake_case (lastPaid is stored as last_paid).

Calls block. On the main thread they are only allowed during startup (onLoad); once the server runs they throw an IllegalStateException, so database I/O never costs tick time. Use modThread() or async().

  • Method Details

    • table

      @Blocking <R extends Record> Table<R> table(String name, Class<R> type)
      Opens the table name with the schema version and migrations that type declares with Schema and Migrate; without them, version 1 and no migrations.
      Throws:
      IllegalArgumentException - when the name, or a Schema or Migrate of type, is invalid
    • define

      <R extends Record> TableDefinition<R> define(String name, Class<R> type)
      A table to open with a schema version and migrations, starting from those of Schema and Migrate on type; see TableDefinition.
      Throws:
      IllegalArgumentException - when the name, or a Schema or Migrate of type, is invalid
    • transaction

      @Blocking void transaction(Runnable work)
      Runs work in one transaction: writes of this thread inside it are committed together, or not at all when work throws.

      Storage of every mod waits while work runs, so work must not wait for other threads, for example with main().submit(...).join(). A backup waits at most 10 seconds for it and then runs without pausing storage.

    • transaction

      @Blocking <T> T transaction(Supplier<T> work)
      Like transaction(Runnable), returning the result of work.