Contents
Class UniverseResources
java.lang.Object
com.hypixel.hytale.server.core.universe.resources.UniverseResources
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionflush(UniverseResourceType<?> type) Writes one resource through the backing store.flushAll()Writes every loaded resource through the backing store.<T> Tget(UniverseResourceType<T> type) Returns the shared instance of the given resource.voidload(Collection<? extends UniverseResourceType<?>> types) Loads the given resource types from the backing store.static <T> UniverseResourceType<T> register(Class<T> typeClass, String id, BuilderCodec<T> codec) Registers a universe resource.static Collection<UniverseResourceType<?>>
-
Constructor Details
-
UniverseResources
- 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
- Returns:
- an unmodifiable view of every registered resource type.
-
load
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
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
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
Writes every loaded resource through the backing store.- Returns:
- a future that completes when all writes are done.
-