Interface ScenarioContext
A context belongs to exactly one scenario in exactly one game. Every scheduled task, event listener, gameplay override, tracked block, entity and dropped item registered through it is owned by that pair and released automatically when the scenario is deactivated, the match ends, the match is cancelled, or the server shuts down. That is what keeps two simultaneous matches — even two running the same scenario — completely independent, and what guarantees the world is handed back the way Zentrix expects it.
The context is not a place to hold long-lived state: use store() for anything the
scenario needs to remember for the length of the match. Everything in the store is discarded
during cleanup.
All methods are safe to call from the server main thread. Scheduling helpers may be called from any thread.
- Since:
- 1.6.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidcancelTask(int taskId) Cancels one task started through this context.@NotNull ScenarioDescriptorThe scenario this context belongs to.<R,V> HookOutcome <V> dispatch(@NotNull GameplayHook<R, V> hook, R request) Asks every scenario active in this match about a decision point, in priority order.@NotNull org.bukkit.entity.EntitydropItem(@NotNull org.bukkit.Location location, @NotNull org.bukkit.inventory.ItemStack item) Drops an item that belongs to this scenario and removes it during cleanup if it is still lying around.@NotNull ZentrixGamegame()The match this context belongs to.booleanisActive()Whether the scenario is still active in this match.booleanisInScope(@Nullable org.bukkit.Location location) Whether a location lies in one of the match's worlds.booleanisInScope(@Nullable org.bukkit.World world) Whether a world belongs to this match.booleanisInScope(@Nullable org.bukkit.entity.Entity entity) Whether an entity belongs to one of the match's worlds.booleanisParticipant(@Nullable org.bukkit.entity.Player player) Whether a player is a living participant of this match.<R,V> @NotNull HookHandle override(@NotNull GameplayHook<R, V> hook, @NotNull GameplayHookHandler<R, V> handler) Takes part in one of Zentrix's gameplay decisions for the length of this match.org.bukkit.plugin.Pluginowner()The plugin that registered this scenario.participantId(@Nullable org.bukkit.entity.Player player) A player's UUID as this match knows it, for convenience in listeners.@NotNull Collection<org.bukkit.entity.Player> The living participants of this match.voidregisterListener(@NotNull org.bukkit.event.Listener listener) Registers a Bukkit listener for the length of this match.voidreportFailure(@NotNull String message, @Nullable Throwable cause) Reports a recoverable problem against this scenario.voidRuns a task on the main thread, skipped if the match ended first.intrunTaskAsync(@NotNull Runnable task) Runs a task off the main thread, cancelled if the match ends first.intrunTaskLater(@NotNull Runnable task, long delayTicks) Runs a task on the main thread after a delay, cancelled if the match ends first.intrunTaskTimer(@NotNull Runnable task, long delayTicks, long periodTicks) Runs a repeating main-thread task, cancelled when the match ends.@NotNull StringThe runtimegame-*identifier of the match.@NotNull ScenarioSettingssettings()The settings of this scenario as they apply to this match.The source arena the match was copied from, when known.@NotNull ScenarioStorestore()A scratch space private to this scenario and this match.voidtrackBlock(@NotNull org.bukkit.block.Block block) Records a block this scenario is about to change so its original state is restored during cleanup.voidtrackEntity(@NotNull org.bukkit.entity.Entity entity) Records an entity this scenario spawned so it is removed during cleanup.voidunregisterListener(@NotNull org.bukkit.event.Listener listener) Unregisters a listener registered throughregisterListener(Listener).@NotNull Optional<org.bukkit.World> world(@NotNull GameWorldType type) One of the match's worlds, empty when it does not exist for this match.@NotNull Collection<org.bukkit.World> worlds()Every world that belongs to this match: arena, waiting lobby, Nether, End, deathmatch.@NotNull Optional<GameWorldType> worldType(@Nullable org.bukkit.World world) The role a world plays in this match, empty when it belongs to another match or to none.
-
Method Details
-
descriptor
The scenario this context belongs to. -
game
The match this context belongs to. -
runtimeId
The runtimegame-*identifier of the match. -
sourceArenaName
The source arena the match was copied from, when known. -
owner
@NotNull org.bukkit.plugin.Plugin owner()The plugin that registered this scenario. -
settings
The settings of this scenario as they apply to this match. -
isActive
boolean isActive()Whether the scenario is still active in this match. -
worlds
Every world that belongs to this match: arena, waiting lobby, Nether, End, deathmatch. -
world
One of the match's worlds, empty when it does not exist for this match. -
isInScope
boolean isInScope(@Nullable @Nullable org.bukkit.World world) Whether a world belongs to this match. -
worldType
The role a world plays in this match, empty when it belongs to another match or to none.The inverse of
world(GameWorldType), and what a listener uses to tell an arena apart from that match's Nether copy or deathmatch arena without hard-coding world names. -
isInScope
boolean isInScope(@Nullable @Nullable org.bukkit.Location location) Whether a location lies in one of the match's worlds. -
isParticipant
boolean isParticipant(@Nullable @Nullable org.bukkit.entity.Player player) Whether a player is a living participant of this match.Spectators are excluded, which is the check a listener needs before touching anything a player did.
-
isInScope
boolean isInScope(@Nullable @Nullable org.bukkit.entity.Entity entity) Whether an entity belongs to one of the match's worlds. -
participants
The living participants of this match. -
override
@NotNull <R,V> @NotNull HookHandle override(@NotNull @NotNull GameplayHook<R, V> hook, @NotNull @NotNull GameplayHookHandler<R, V> handler) Takes part in one of Zentrix's gameplay decisions for the length of this match.Handlers are consulted in descending scenario priority. The returned handle is released automatically during cleanup; releasing it earlier restores Zentrix's own behaviour immediately.
- Parameters:
hook- the decision point, fromGameplayHooksor the scenario's ownhandler- what this scenario decides- Returns:
- a handle for dropping the override early
-
dispatch
@NotNull <R,V> HookOutcome<V> dispatch(@NotNull @NotNull GameplayHook<R, V> hook, @NotNull R request) Asks every scenario active in this match about a decision point, in priority order.This is how a scenario dispatches a hook it defined itself, so mechanics Zentrix never anticipated stay composable between scenarios.
- Parameters:
hook- the decision pointrequest- the request handed to the handlers- Returns:
- the first non-passing outcome, or
passwhen nobody took the decision
-
registerListener
void registerListener(@NotNull @NotNull org.bukkit.event.Listener listener) Registers a Bukkit listener for the length of this match.The listener is unregistered during cleanup. It still receives server-wide events, so use
isParticipant(Player)orisInScope(World)to ignore anything happening outside this match. -
unregisterListener
void unregisterListener(@NotNull @NotNull org.bukkit.event.Listener listener) Unregisters a listener registered throughregisterListener(Listener). -
runTask
Runs a task on the main thread, skipped if the match ended first. -
runTaskLater
Runs a task on the main thread after a delay, cancelled if the match ends first. -
runTaskTimer
Runs a repeating main-thread task, cancelled when the match ends. -
runTaskAsync
Runs a task off the main thread, cancelled if the match ends first. -
cancelTask
void cancelTask(int taskId) Cancels one task started through this context. -
trackBlock
void trackBlock(@NotNull @NotNull org.bukkit.block.Block block) Records a block this scenario is about to change so its original state is restored during cleanup.Call this before changing the block. Tracking the same block twice keeps the first snapshot, so the block always returns to what the arena template had.
-
trackEntity
void trackEntity(@NotNull @NotNull org.bukkit.entity.Entity entity) Records an entity this scenario spawned so it is removed during cleanup. -
dropItem
@NotNull @NotNull org.bukkit.entity.Entity dropItem(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull org.bukkit.inventory.ItemStack item) Drops an item that belongs to this scenario and removes it during cleanup if it is still lying around. -
store
A scratch space private to this scenario and this match. -
reportFailure
Reports a recoverable problem against this scenario.The message is logged with the scenario's ID. Repeated failures may lead Zentrix to deactivate the scenario for this match so the rest of the game keeps running.
-
participantId
@NotNull default @NotNull Optional<UUID> participantId(@Nullable @Nullable org.bukkit.entity.Player player) A player's UUID as this match knows it, for convenience in listeners.
-