VitalMinigameInstanceService

open class VitalMinigameInstanceService(vitalMinigameInstanceRepository: VitalMinigameInstanceRepository, plugin: SpigotPlugin)

The global minigame instance manager to use when creating multiple minigames on the same game server. Each minigame will run in its own capsulated instance, which can have n-amount of states. A state may also have n-amount of event handlers mapped to it. Each event handler will only be active when the state is also active.

E.g. "StartingState" -> JoinEvent -> Event handler will only be active when the starting state is active. Once you switch to a different state, like "IngameState", the event handlers from "StartingState" will no longer fire.

Constructors

Link copied to clipboard
constructor(vitalMinigameInstanceRepository: VitalMinigameInstanceRepository, plugin: SpigotPlugin)

Functions

Link copied to clipboard
fun loadTemplateWorld(templateWorldName: String, action: Consumer<World?> = Consumer {})

Loads a new instance world by the given templateWorldName. This function will copy all world files from the templateWorldName to a new world that can be used for a new VitalMinigameInstance, e.g. "VitalMinigameInstance.id_templateWorldName", and will then immediately return. An action function can be provided to perform an action on the newly loaded world.

Link copied to clipboard
fun loadWorld(name: String): World?

Loads the world by the given name with settings to reduce lag-spikes on the server's main-thread.

Link copied to clipboard
fun <T : VitalMinigameInstance> registerInstance(instance: T, afterRegisterAction: Consumer<T> = Consumer {})

Registers a new game instance on this service. An instance may perform custom logic during registration via VitalMinigameInstance.onRegister. Additionally, an afterRegisterAction function can be provided to perform an action right after instance registration, but before VitalMinigameInstance.onRegister is called.

Link copied to clipboard
fun unregisterAllInstances(beforeDeleteAction: Consumer<VitalMinigameInstance> = Consumer {}, afterDeleteAction: Consumer<VitalMinigameInstance> = Consumer {})

Unregisters all existing game instances by calling unregisterInstance for every one.

Link copied to clipboard
fun <T : VitalMinigameInstance> unregisterInstance(instance: T, beforeDeleteAction: Consumer<T> = Consumer {}, afterDeleteAction: Consumer<T> = Consumer {})

Unregisters an existing game instance. An instance may perform custom logic during unregistration via VitalMinigameInstance.onUnregister. Additionally, an beforeDeleteAction function can be provided to perform an action right after instance unregistration, but before VitalMinigameInstance.onUnregister is called and before the world is deleted. An afterDeleteAction function can also be provided to perform an action right after the world unloaded and deleted from the file system.

inline fun <T : VitalMinigameInstance> unregisterInstance(id: UUID, beforeDeleteAction: Consumer<T> = Consumer {}, afterDeleteAction: Consumer<T> = Consumer {})

Unregisters an existing game instance by its id, fails if no instance with the given id exists. Once unregistered, the instance's world will be unloaded and then deleted. Additionally, an beforeDeleteAction function can be provided to perform an action right after instance unregistration, but before VitalMinigameInstance.onUnregister is called and before the world is deleted. An afterDeleteAction function can also be provided to perform an action right after the world unloaded and deleted from the file system.