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 Details

    • registerBroadcast

      boolean registerBroadcast(@NotNull @NotNull BroadcastBuilder builder)
      Registers a custom broadcast from a builder.

      This method performs in-memory registration only.

      Parameters:
      builder - The broadcast builder with configuration
      Returns:
      true if 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 true if successful
      Throws:
      IllegalArgumentException - if the builder is invalid
    • unregisterBroadcast

      boolean unregisterBroadcast(@NotNull @NotNull String broadcastId)
      Unregisters a broadcast by ID.

      This method performs in-memory removal only.

      Parameters:
      broadcastId - The ID of the broadcast to unregister
      Returns:
      true if the broadcast was found and removed
    • updateBroadcast

      boolean updateBroadcast(@NotNull @NotNull BroadcastBuilder builder)
      Updates an existing broadcast with new configuration.

      The broadcast must already exist.

      Parameters:
      builder - The broadcast builder with updated configuration
      Returns:
      true if the broadcast was found and updated
    • getBroadcast

      @NotNull @NotNull Optional<ZentrixBroadcast> getBroadcast(@NotNull @NotNull String broadcastId)
      Gets a broadcast by its ID.
      Parameters:
      broadcastId - The broadcast ID
      Returns:
      Optional containing the broadcast, or empty if not found
    • getAllBroadcasts

      @NotNull @NotNull Collection<ZentrixBroadcast> 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

      boolean broadcastExists(@NotNull @NotNull String broadcastId)
      Checks if a broadcast exists with the given ID.
      Parameters:
      broadcastId - The broadcast ID to check
      Returns:
      true if the broadcast exists
    • enableBroadcast

      boolean enableBroadcast(@NotNull @NotNull String broadcastId)
      Enables a broadcast.
      Parameters:
      broadcastId - The broadcast ID to enable
      Returns:
      true if the broadcast was found and enabled
    • disableBroadcast

      boolean disableBroadcast(@NotNull @NotNull String broadcastId)
      Disables a broadcast.
      Parameters:
      broadcastId - The broadcast ID to disable
      Returns:
      true if 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 trigger
      state - The game state context for the broadcast
      Returns:
      true if the broadcast was found and triggered
    • resetBroadcastTimer

      void resetBroadcastTimer(@NotNull @NotNull String broadcastId)
      Resets the timer for a broadcast.

      The next broadcast will occur after the full interval.

      Parameters:
      broadcastId - The broadcast ID
    • createBroadcastBuilder

      @NotNull default @NotNull BroadcastBuilder createBroadcastBuilder()
      Creates a new BroadcastBuilder instance.
      Returns:
      A new BroadcastBuilder