PluginBase
PluginBase
Section titled “PluginBase”Package: com.hypixel.hytale.server.core.plugin
public abstract class PluginBase implements CommandOwnerThe base class for all Hytale server plugins. Every plugin extends PluginBase and uses it as the entry point for registering events, commands, tasks, block states, entities, codecs, assets, and other game systems. The server manages the plugin lifecycle by calling setup(), start(), and shutdown() in order.
Lifecycle
Section titled “Lifecycle”Plugins progress through a defined state machine managed by PluginState:
| State | Description |
|---|---|
NONE | Initial state before any lifecycle method has been called. |
SETUP | Entered when setup0() is called. The plugin’s setup() override runs in this state. |
START | Entered when start0() is called, immediately before start() runs. |
ENABLED | Set after start() completes successfully. The plugin is fully operational. |
SHUTDOWN | Entered when shutdown0() is called. The plugin’s shutdown() override runs in this state. |
DISABLED | Set after shutdown completes or if setup()/start() throws an exception. |
State Transitions
Section titled “State Transitions”NONE --> SETUP --> START --> ENABLED --> SHUTDOWN --> DISABLED | | +-- (exception) +-- (exception) | | v vDISABLED DISABLEDIf setup() or start() throws an exception, the plugin transitions directly to DISABLED. The SHUTDOWN state is only reached during normal server-initiated shutdown of an enabled plugin.
Lifecycle Methods
Section titled “Lifecycle Methods”Override these methods to define your plugin’s behavior. Do not call them directly.
protected void setup()Called during the setup phase. Use this to register events, commands, and other resources. All registry accessors are available. If this method throws, the plugin transitions to DISABLED.
protected void start()Called after setup completes. Use this for initialization that depends on the server being ready. If this method throws, the plugin transitions to DISABLED.
protected void shutdown()Called when the plugin is being unloaded. Use this for custom cleanup. After this method returns (or throws), all registrations are automatically cleaned up via the internal cleanup() mechanism.
Pre-load
Section titled “Pre-load”@Nullablepublic CompletableFuture<Void> preLoad()Loads all configs registered with withConfig(). Returns null if no configs exist. Called by the server before setup0().
Constructor
Section titled “Constructor”public PluginBase(@Nonnull PluginInit init)Constructs the plugin base from a PluginInit provided by the server. Sets up the logger, data directory, identifier, manifest, and base permission string. Plugins do not call this directly — the server framework instantiates plugins.
Registry Accessors
Section titled “Registry Accessors”These methods provide plugin-scoped registries. All registrations made through these registries are automatically cleaned up when the plugin shuts down. Each registry enforces a precondition: the plugin must be in an active state (SETUP, START, or ENABLED). Calling registration methods when the plugin is NONE, DISABLED, or SHUTDOWN throws IllegalStateException.
| Registry | Method | Returns |
|---|---|---|
| Events | getEventRegistry() | EventRegistry |
| Commands | getCommandRegistry() | CommandRegistry |
| Block States | getBlockStateRegistry() | BlockStateRegistry |
| Entities | getEntityRegistry() | EntityRegistry |
| Tasks | getTaskRegistry() | TaskRegistry |
| Entity Store Components | getEntityStoreRegistry() | ComponentRegistryProxy<EntityStore> |
| Chunk Store Components | getChunkStoreRegistry() | ComponentRegistryProxy<ChunkStore> |
| Assets | getAssetRegistry() | AssetRegistry |
| Client Features | getClientFeatureRegistry() | ClientFeatureRegistry |
Events
Section titled “Events”@Nonnullpublic EventRegistry getEventRegistry()Returns the plugin-scoped EventRegistry for subscribing to server events. Delegates to the server’s EventBus.
See also: EventRegistry, EventRegistration
Commands
Section titled “Commands”@Nonnullpublic CommandRegistry getCommandRegistry()Returns the plugin-scoped CommandRegistry for registering slash commands.
See also: CommandRegistry, CommandRegistration
Block States
Section titled “Block States”@Nonnullpublic BlockStateRegistry getBlockStateRegistry()Returns the plugin-scoped BlockStateRegistry for registering custom block states.
Entities
Section titled “Entities”@Nonnullpublic EntityRegistry getEntityRegistry()Returns the plugin-scoped EntityRegistry for registering custom entity types.
@Nonnullpublic TaskRegistry getTaskRegistry()Returns the plugin-scoped TaskRegistry for scheduling recurring or delayed tasks.
Entity Store Components
Section titled “Entity Store Components”@Nonnullpublic ComponentRegistryProxy<EntityStore> getEntityStoreRegistry()Returns the plugin-scoped ComponentRegistryProxy for registering ECS components on entity stores. Delegates to EntityStore.REGISTRY.
Chunk Store Components
Section titled “Chunk Store Components”@Nonnullpublic ComponentRegistryProxy<ChunkStore> getChunkStoreRegistry()Returns the plugin-scoped ComponentRegistryProxy for registering ECS components on chunk stores. Delegates to ChunkStore.REGISTRY.
Assets
Section titled “Assets”@Nonnullpublic AssetRegistry getAssetRegistry()Returns the plugin-scoped AssetRegistry for registering custom asset types.
Client Features
Section titled “Client Features”@Nonnullpublic ClientFeatureRegistry getClientFeatureRegistry()Returns the plugin-scoped ClientFeatureRegistry for registering features that affect client behavior.
Codec Registries
Section titled “Codec Registries”Three overloads are provided for registering codec mappings, each returning a plugin-scoped registry backed by the corresponding codec map type:
@Nonnullpublic <T, C extends Codec<? extends T>> CodecMapRegistry<T, C> getCodecRegistry(@Nonnull StringCodecMapCodec<T, C> mapCodec)Returns (or creates) a CodecMapRegistry for a string-keyed codec map.
@Nonnullpublic <K, T extends JsonAsset<K>> CodecMapRegistry.Assets<T, ?> getCodecRegistry(@Nonnull AssetCodecMapCodec<K, T> mapCodec)Returns (or creates) a CodecMapRegistry.Assets for an asset codec map.
@Nonnullpublic <V> MapKeyMapRegistry<V> getCodecRegistry(@Nonnull MapKeyMapCodec<V> mapCodec)Returns (or creates) a MapKeyMapRegistry for a map-key codec map.
Codec registries are created lazily and cached in a ConcurrentHashMap. All are cleaned up on shutdown.
Configuration
Section titled “Configuration”@Nonnullprotected final <T> Config<T> withConfig(@Nonnull BuilderCodec<T> configCodec)Registers a config file named "config" using the given codec. Must be called before setup() (i.e., while the plugin state is NONE). Throws IllegalStateException if called after setup begins.
@Nonnullprotected final <T> Config<T> withConfig(@Nonnull String name, @Nonnull BuilderCodec<T> configCodec)Registers a config file with the specified name. Same timing constraint as the single-argument overload.
The returned Config<T> object is loaded asynchronously during preLoad() from the plugin’s data directory.
Identity and Metadata
Section titled “Identity and Metadata”@Nonnullpublic PluginIdentifier getIdentifier()Returns the plugin’s unique identifier, constructed from the PluginManifest.
@Nonnullpublic PluginManifest getManifest()Returns the plugin’s manifest metadata.
@Nonnull@Overridepublic String getName()Returns the string representation of the plugin identifier. Implements CommandOwner.getName().
@Nonnullpublic Path getDataDirectory()Returns the file-system path to the plugin’s private data directory. Used for config files and persistent storage.
@Nonnullpublic final String getBasePermission()Returns the base permission node for this plugin, computed as (group + "." + name).toLowerCase() from the manifest. Used as a prefix for permission checks.
@Nonnullpublic HytaleLogger getLogger()Returns the plugin’s logger instance. The logger tag includes the plugin name and a suffix indicating whether it is a plugin (|P) or addon (|A).
State Queries
Section titled “State Queries”public boolean isEnabled()Returns true if the plugin is in an active state (not NONE, DISABLED, or SHUTDOWN).
public boolean isDisabled()Returns true if the plugin is in NONE, DISABLED, or SHUTDOWN state.
@Nonnullpublic PluginState getState()Returns the current PluginState.
Abstract Methods
Section titled “Abstract Methods”@Nonnullpublic abstract PluginType getType()Returns whether this is a PLUGIN or ADDON. Implemented by concrete subclasses.
Cleanup
Section titled “Cleanup”When a plugin shuts down, the internal cleanup() method runs in this order:
commandRegistry.shutdown()eventRegistry.shutdown()clientFeatureRegistry.shutdown()blockStateRegistry.shutdown()taskRegistry.shutdown()entityStoreRegistry.shutdown()chunkStoreRegistry.shutdown()- All codec map registries are shut down.
assetRegistry.shutdown()- All shutdown tasks are executed in reverse order (LIFO).
This ensures all registrations are removed and resources released, even if the plugin’s shutdown() override does not explicitly unregister them.
Example
Section titled “Example”public class MyPlugin extends PluginBase {
private final Config<MyConfig> config;
public MyPlugin(PluginInit init) { super(init); // Config must be registered before setup() this.config = withConfig(MyConfig.CODEC); }
@Override public PluginType getType() { return PluginType.PLUGIN; }
@Override protected void setup() { // Register an event listener getEventRegistry().register(BootEvent.class, event -> { getLogger().info("Server booted!"); });
// Register a command getCommandRegistry().registerCommand(new MyCommand());
// Register an entity store component getEntityStoreRegistry().register(MyComponent.class, MyComponent::new); }
@Override protected void start() { getLogger().info("Plugin started: " + getIdentifier()); getLogger().info("Config value: " + config.get().someValue()); }
@Override protected void shutdown() { getLogger().info("Plugin shutting down."); // Explicit cleanup is optional -- all registrations are // automatically removed by the framework. }}Related Types
Section titled “Related Types”- EventRegistry — plugin-scoped event registration
- CommandRegistry — plugin-scoped command registration
- Registry — generic base class for plugin-scoped registries
- Registration — base handle for individual registrations
- Registry System Overview — how registries work
PluginState— lifecycle state enumPluginManifest— plugin metadata from the manifest filePluginIdentifier— unique plugin identityComponentRegistryProxy— ECS component registration proxyBlockStateRegistry— block state registrationEntityRegistry— entity type registrationTaskRegistry— task scheduling registrationAssetRegistry— asset registrationClientFeatureRegistry— client feature registrationCodecMapRegistry— codec mapping registrationConfig— typed configuration file loading