Prior to any states that make the plugin visible, the plugin loader first sorts through the available plugins, determines if all dependencies are present, and sorts plugins by dependency order. Lifecycle events are given to plugins in this order. For example, plugin A containing «[required-]after:B» will get each event after plugin B has completed work for the given state. Additionally, lifecycle states are global. This means that all plugins visible to each other must be transitioned through all states at once.
Server object is not always available. Availability can be checked using the method
There are three categories of state events:
- Initialization: When Sponge and plugins are loading, before the actual game has started. Initialization states only occur once.
- Running: When the game and world are loading. Running states may occur multiple times.
- Stopping: When the game is shutting down. Stopping states, like initialization states, only occur once.
Initialization states only occur once during a single run.
The GameConstructionEvent is triggered.
During this state, the
@Plugin class instance for each plugin is triggered.
The GamePreInitializationEvent is triggered. During this state, the plugin gets ready for initialization. Access to a default logger instance and access to information regarding preferred configuration file locations is available.
The GameInitializationEvent is triggered. During this state, the plugin should finish any work needed in order to be functional. Global event handlers should get registered in this stage.
The GamePostInitializationEvent is triggered. By this state, inter-plugin communication should be ready to occur. Plugins providing an API should be ready to accept basic requests.
The GameLoadCompleteEvent is triggered. By this state, all plugin initialization should be completed.
Running States can occur multiple times during a single run.
SERVER_ABOUT_TO_START may follow
SERVER_STOPPED may occur at any point during the process if there is an error.
The GameAboutToStartServerEvent event is triggered. The server instance exists, but worlds are not yet loaded.
The GameStartingServerEvent is triggered. The server instance exists, and worlds are loaded. Command registration is handled during this state.
The GameStartedServerEvent event is triggered. The server instance exists, and worlds are loaded.
The GameStoppingServerEvent is triggered. This state occurs immediately before the final tick, before the worlds are saved.
The GameStoppedServerEvent is triggered. During this state, no players are connected and no changes to worlds are saved.
Stopping states never occur more than once during a single run. They occur when the game stops normally. (On Servers:
/stop command is typed. On Clients: The «Close» button or the «Quit Game» button are clicked)
Stopping states are not guaranteed to be run during shutdown. They may not fire if the game is force-stopped via Ctrl-C, Task Manager, a computer crash, or similar situations.
The GameStoppingServerEvent is triggered.
This state occurs immediately before
GAME_STOPPED. Plugins providing an API should still be capable of accepting
The GameStoppedServerEvent is triggered. Once this event has finished executing, Minecraft will shut down. No further interaction with the game or other plugins should be attempted at this point.