Class UniverseResources

java.lang.Object
com.hypixel.hytale.server.core.universe.resources.UniverseResources

public final class UniverseResources extends Object
Universe-scoped persistent resources, the universe sibling of per-world ECS resources.

Plugins register a resource with register(Class, String, BuilderCodec) during setup. The Universe loads every registered entry once at start through the IUniverseResourceStorage from the configured IUniverseResourceStorageProvider, and flushes all entries on a fixed cadence plus at shutdown.

A loaded resource is one shared instance that any world thread may touch. The resource owns its own thread-safety.

  • Constructor Details

    • UniverseResources

      public UniverseResources(@Nonnull IUniverseResourceStorage storage)
      Parameters:
      storage - The backing store that reads and writes the resources.
  • Method Details

    • register

      @Nonnull public static <T> UniverseResourceType<T> register(@Nonnull Class<T> typeClass, @Nonnull String id, @Nonnull BuilderCodec<T> codec)
      Registers a universe resource. Call during plugin setup, before the universe starts.
      Type Parameters:
      T - The resource type.
      Parameters:
      typeClass - The class of the resource.
      id - The unique id of the resource, also its file name on disk.
      codec - The codec that persists the resource. Its default value seeds a new universe.
      Returns:
      the token to read and flush the resource with.
    • registeredTypes

      @Nonnull public static Collection<UniverseResourceType<?>> registeredTypes()
      Returns:
      an unmodifiable view of every registered resource type.
    • load

      public void load(@Nonnull Collection<? extends UniverseResourceType<?>> types)
      Loads the given resource types from the backing store. A type without stored data yields the codec's default value.
      Parameters:
      types - The resource types to load.
    • get

      @Nonnull public <T> T get(@Nonnull UniverseResourceType<T> type)
      Returns the shared instance of the given resource.
      Type Parameters:
      T - The resource type.
      Parameters:
      type - The resource type token.
      Returns:
      the loaded resource, never null.
    • flush

      @Nonnull public CompletableFuture<Void> flush(@Nonnull UniverseResourceType<?> type)
      Writes one resource through the backing store.
      Parameters:
      type - The resource type to write.
      Returns:
      a future that completes when the write is durable.
    • flushAll

      @Nonnull public CompletableFuture<Void> flushAll()
      Writes every loaded resource through the backing store.
      Returns:
      a future that completes when all writes are done.