Interface PhaseService
This service provides access to phase configurations, current phase state, and phase-related queries for active games.
Example Usage
PhaseService phaseService = ZentrixProvider.get().getPhaseService();
// Get all configured phases
Collection<GamePhase> phases = phaseService.getAllPhases();
// Get current phase for a game
Optional<GamePhase> currentPhase = phaseService.getCurrentPhase(game);
currentPhase.ifPresent(phase -> {
String name = phase.getName();
int timeLeft = phaseService.getTimeRemaining(game);
player.sendMessage("Phase: " + name + " - Time left: " + timeLeft + "s");
});
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull PhaseBuilderCreates a new PhaseBuilder instance.@NotNull Collection<GamePhase> Gets all configured game phases.getCurrentPhase(@NotNull ZentrixGame game) Gets the current active phase for a game.intgetCurrentPhaseIndex(@NotNull ZentrixGame game) Gets the index of the current phase for a game (0-based).getNextPhase(@NotNull ZentrixGame game) Gets the next phase after the current one for a game.Gets a phase by its name.getPhaseByIndex(int index) Gets a phase by its index (0-based).intGets the total number of configured phases.@NotNull Collection<GamePhase> getPhasesByAddon(@NotNull String addonId) Gets all phases registered by a specific addon.getPreviousPhase(@NotNull ZentrixGame game) Gets the previous phase before the current one for a game.doublegetTargetBorderSize(@NotNull ZentrixGame game) Gets the target border size for the current phase.intgetTimeElapsed(@NotNull ZentrixGame game) Gets the elapsed time in the current phase, in seconds.intgetTimeRemaining(@NotNull ZentrixGame game) Gets the time remaining in the current phase, in seconds.intGets the total duration of all phases combined, in seconds.booleanhasBorderShrinkage(@NotNull ZentrixGame game) Checks if the current phase for a game has border shrinkage enabled.booleanhasCompletedAllPhases(@NotNull ZentrixGame game) Checks if a game has completed all phases.booleanisInPhase(@NotNull ZentrixGame game, @NotNull String phaseName) Checks if a game is currently in a specific phase.booleanisPaused(@NotNull ZentrixGame game) Checks if phase system is paused for a game.booleanregisterPhase(@NotNull PhaseBuilder builder) Registers a custom phase from a builder.@NotNull CompletableFuture<Boolean> registerPhaseAsync(@NotNull PhaseBuilder builder) Registers a custom phase asynchronously with persistence.booleanregisterPhaseAt(@NotNull PhaseBuilder builder, int index) Registers a custom phase at a specific index in the phase sequence.booleanunregisterPhase(@NotNull String phaseName) Unregisters a phase by name.@NotNull CompletableFuture<Boolean> unregisterPhaseAndDelete(@NotNull String phaseName) Unregisters a phase and removes it from the configuration file.booleanupdatePhase(@NotNull PhaseBuilder builder) Updates an existing phase with new configuration.
-
Method Details
-
getAllPhases
Gets all configured game phases.These are the phases defined in the phases.yml configuration file. The collection is ordered by phase sequence.
- Returns:
- An unmodifiable collection of all phases (never null, may be empty)
-
getPhase
Gets a phase by its name.- Parameters:
phaseName- The phase name (case-insensitive)- Returns:
- Optional containing the phase, or empty if not found
-
getCurrentPhase
Gets the current active phase for a game.Returns empty if the game hasn't started or has ended.
- Parameters:
game- The game- Returns:
- Optional containing the current phase, or empty if not in a phase
-
getCurrentPhaseIndex
Gets the index of the current phase for a game (0-based).Returns -1 if no phase is active.
- Parameters:
game- The game- Returns:
- The phase index, or -1 if not in a phase
-
getTimeRemaining
Gets the time remaining in the current phase, in seconds.Returns 0 if no phase is active.
- Parameters:
game- The game- Returns:
- Seconds remaining in current phase
-
getTimeElapsed
Gets the elapsed time in the current phase, in seconds.Returns 0 if no phase is active.
- Parameters:
game- The game- Returns:
- Seconds elapsed in current phase
-
getPhaseCount
int getPhaseCount()Gets the total number of configured phases.- Returns:
- The phase count
-
getNextPhase
Gets the next phase after the current one for a game.Returns empty if there is no next phase (current is the last) or if no phase is active.
- Parameters:
game- The game- Returns:
- Optional containing the next phase, or empty if none
-
getPreviousPhase
Gets the previous phase before the current one for a game.Returns empty if there is no previous phase (current is the first) or if no phase is active.
- Parameters:
game- The game- Returns:
- Optional containing the previous phase, or empty if none
-
isInPhase
Checks if a game is currently in a specific phase.- Parameters:
game- The gamephaseName- The phase name to check- Returns:
trueif the game is in the specified phase
-
hasCompletedAllPhases
Checks if a game has completed all phases.Returns true if the game has finished its last phase.
- Parameters:
game- The game- Returns:
trueif all phases are complete
-
isPaused
Checks if phase system is paused for a game.- Parameters:
game- The game- Returns:
trueif phases are paused
-
getTotalPhaseDuration
int getTotalPhaseDuration()Gets the total duration of all phases combined, in seconds.- Returns:
- Total phase duration
-
getPhaseByIndex
Gets a phase by its index (0-based).- Parameters:
index- The phase index- Returns:
- Optional containing the phase, or empty if index is out of bounds
-
hasBorderShrinkage
Checks if the current phase for a game has border shrinkage enabled.- Parameters:
game- The game- Returns:
trueif current phase has border shrinkage
-
getTargetBorderSize
Gets the target border size for the current phase.Returns 0 if no phase is active or no border config exists.
- Parameters:
game- The game- Returns:
- The target border size, or 0 if not applicable
-
registerPhase
Registers a custom phase from a builder.The phase is added at the end of the phase sequence. This method performs in-memory registration only.
- Parameters:
builder- The phase builder with configuration- Returns:
trueif registration was successful- Throws:
IllegalArgumentException- if the builder is invalid- Since:
- 1.1.0
-
registerPhaseAsync
@NotNull @NotNull CompletableFuture<Boolean> registerPhaseAsync(@NotNull @NotNull PhaseBuilder builder) Registers a custom phase asynchronously with persistence.The phase is added at the end of the phase sequence and saved to the phases.yml configuration file.
- Parameters:
builder- The phase builder with configuration- Returns:
- A future that completes with
trueif successful - Throws:
IllegalArgumentException- if the builder is invalid- Since:
- 1.1.0
-
registerPhaseAt
Registers a custom phase at a specific index in the phase sequence.This method performs in-memory registration only.
- Parameters:
builder- The phase builder with configurationindex- The index to insert at (0-based)- Returns:
trueif registration was successful- Throws:
IllegalArgumentException- if the builder is invalid or index is out of bounds- Since:
- 1.1.0
-
unregisterPhase
Unregisters a phase by name.This method performs in-memory removal only.
- Parameters:
phaseName- The name of the phase to unregister- Returns:
trueif the phase was found and removed- Since:
- 1.1.0
-
unregisterPhaseAndDelete
@NotNull @NotNull CompletableFuture<Boolean> unregisterPhaseAndDelete(@NotNull @NotNull String phaseName) Unregisters a phase and removes it from the configuration file.- Parameters:
phaseName- The name of the phase to unregister- Returns:
- A future that completes with
trueif successful - Since:
- 1.1.0
-
updatePhase
Updates an existing phase with new configuration.The phase must already exist. This replaces the phase configuration while maintaining its position in the sequence.
- Parameters:
builder- The phase builder with updated configuration- Returns:
trueif the phase was found and updated- Since:
- 1.1.0
-
getPhasesByAddon
Gets all phases registered by a specific addon.- Parameters:
addonId- The addon identifier- Returns:
- Collection of phases registered by the addon (never null, may be empty)
- Since:
- 1.1.0
-
createPhaseBuilder
Creates a new PhaseBuilder instance.Convenience method for creating builders.
- Returns:
- A new PhaseBuilder
- Since:
- 1.1.0
-