Interface ModStorage


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

      <R extends Record> Table<R> table(String name, Class<R> type)
      Opens the table name with schema version 1 and no migrations.
    • define

      <R extends Record> TableDefinition<R> define(String name, Class<R> type)
      A table with a schema version and migrations; see TableDefinition.
    • transaction

      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

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