Interface BroadcastService
public interface BroadcastService
Service for managing broadcasts within Zentrix.
Broadcasts are periodic messages sent to players in specific game states. This service allows registration, querying, and control of broadcasts.
Example Usage
BroadcastService broadcastService = ZentrixAPI.get().getBroadcastService();
// Register a new broadcast
BroadcastBuilder tips = new BroadcastBuilder()
.id("gameplay-tips")
.type(BroadcastType.CHAT)
.interval(180)
.showIn(GameState.PLAYING)
.messages(
"&#FFD700[TIP] Use sneak to reduce knockback!",
"&#FFD700[TIP] Golden apples give absorption!"
)
.addonId(getAddonId());
broadcastService.registerBroadcast(tips);
// Query broadcasts
Collection<ZentrixBroadcast> playingBroadcasts =
broadcastService.getBroadcastsForState(GameState.PLAYING);
- Since:
- 1.1.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanbroadcastExists(@NotNull String broadcastId) Checks if a broadcast exists with the given ID.default @NotNull BroadcastBuilderCreates a new BroadcastBuilder instance.booleandisableBroadcast(@NotNull String broadcastId) Disables a broadcast.booleanenableBroadcast(@NotNull String broadcastId) Enables a broadcast.@NotNull Collection<ZentrixBroadcast> Gets all registered broadcasts.@NotNull Optional<ZentrixBroadcast> getBroadcast(@NotNull String broadcastId) Gets a broadcast by its ID.@NotNull Collection<ZentrixBroadcast> getBroadcastsByAddon(@NotNull String addonId) Gets all broadcasts registered by a specific addon.@NotNull Collection<ZentrixBroadcast> getBroadcastsForState(@NotNull GameState state) Gets all broadcasts that should be shown in a specific game state.booleanregisterBroadcast(@NotNull BroadcastBuilder builder) Registers a custom broadcast from a builder.@NotNull CompletableFuture<Boolean> registerBroadcastAsync(@NotNull BroadcastBuilder builder) Registers a custom broadcast asynchronously with persistence.voidresetBroadcastTimer(@NotNull String broadcastId) Resets the timer for a broadcast.booleantriggerBroadcastNow(@NotNull String broadcastId, @NotNull GameState state) Triggers a broadcast immediately for the given game state.booleanunregisterBroadcast(@NotNull String broadcastId) Unregisters a broadcast by ID.booleanupdateBroadcast(@NotNull BroadcastBuilder builder) Updates an existing broadcast with new configuration.
-
Method Details
-
registerBroadcast
Registers a custom broadcast from a builder.This method performs in-memory registration only.
- Parameters:
builder- The broadcast builder with configuration- Returns:
trueif registration was successful- Throws:
IllegalArgumentException- if the builder is invalid
-
registerBroadcastAsync
@NotNull @NotNull CompletableFuture<Boolean> registerBroadcastAsync(@NotNull @NotNull BroadcastBuilder builder) Registers a custom broadcast asynchronously with persistence.The broadcast is registered and saved to the broadcasts.yml configuration file.
- Parameters:
builder- The broadcast builder with configuration- Returns:
- A future that completes with
trueif successful - Throws:
IllegalArgumentException- if the builder is invalid
-
unregisterBroadcast
Unregisters a broadcast by ID.This method performs in-memory removal only.
- Parameters:
broadcastId- The ID of the broadcast to unregister- Returns:
trueif the broadcast was found and removed
-
updateBroadcast
Updates an existing broadcast with new configuration.The broadcast must already exist.
- Parameters:
builder- The broadcast builder with updated configuration- Returns:
trueif the broadcast was found and updated
-
getBroadcast
Gets a broadcast by its ID.- Parameters:
broadcastId- The broadcast ID- Returns:
- Optional containing the broadcast, or empty if not found
-
getAllBroadcasts
Gets all registered broadcasts.- Returns:
- An unmodifiable collection of all broadcasts (never null, may be empty)
-
getBroadcastsForState
@NotNull @NotNull Collection<ZentrixBroadcast> getBroadcastsForState(@NotNull @NotNull GameState state) Gets all broadcasts that should be shown in a specific game state.- Parameters:
state- The game state to filter by- Returns:
- Collection of broadcasts for that state (never null, may be empty)
-
getBroadcastsByAddon
@NotNull @NotNull Collection<ZentrixBroadcast> getBroadcastsByAddon(@NotNull @NotNull String addonId) Gets all broadcasts registered by a specific addon.- Parameters:
addonId- The addon identifier- Returns:
- Collection of broadcasts registered by the addon (never null, may be empty)
-
broadcastExists
Checks if a broadcast exists with the given ID.- Parameters:
broadcastId- The broadcast ID to check- Returns:
trueif the broadcast exists
-
enableBroadcast
Enables a broadcast.- Parameters:
broadcastId- The broadcast ID to enable- Returns:
trueif the broadcast was found and enabled
-
disableBroadcast
Disables a broadcast.- Parameters:
broadcastId- The broadcast ID to disable- Returns:
trueif the broadcast was found and disabled
-
triggerBroadcastNow
boolean triggerBroadcastNow(@NotNull @NotNull String broadcastId, @NotNull @NotNull GameState state) Triggers a broadcast immediately for the given game state.This bypasses the normal interval timer and sends the broadcast now.
- Parameters:
broadcastId- The broadcast ID to triggerstate- The game state context for the broadcast- Returns:
trueif the broadcast was found and triggered
-
resetBroadcastTimer
Resets the timer for a broadcast.The next broadcast will occur after the full interval.
- Parameters:
broadcastId- The broadcast ID
-
createBroadcastBuilder
Creates a new BroadcastBuilder instance.- Returns:
- A new BroadcastBuilder
-