Class BroadcastBuilder

java.lang.Object
dev.itsharshxd.zentrix.api.broadcast.BroadcastBuilder

public class BroadcastBuilder extends Object
Fluent builder for creating custom broadcasts.

Use it to define CHAT, TITLE, and ACTIONBAR broadcasts for Zentrix.

Chat broadcast example


 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);
 

Title broadcast example


 BroadcastBuilder alert = new BroadcastBuilder()
     .id("phase-reminder")
     .type(BroadcastType.TITLE)
     .interval(60)
     .showIn(GameState.PLAYING)
     .title("&#FF5555Stay Alert!")
     .subtitle("&#AAAAAA The border is shrinking!")
     .titleTiming(5, 40, 10)
     .addonId(getAddonId());

 broadcastService.registerBroadcast(alert);
 
Since:
1.1.0
See Also:
  • Constructor Details

    • BroadcastBuilder

      public BroadcastBuilder()
      Creates a new BroadcastBuilder instance.
  • Method Details

    • id

      @NotNull public @NotNull BroadcastBuilder id(@NotNull @NotNull String id)
      Sets the unique identifier for this broadcast.

      Broadcast IDs must only contain lowercase letters, numbers, hyphens, and underscores.

      Parameters:
      id - The broadcast ID (e.g., "gameplay-tips", "phase_warning")
      Returns:
      This builder for chaining
      Throws:
      IllegalArgumentException - if the ID is null, empty, or contains invalid characters
    • enabled

      @NotNull public @NotNull BroadcastBuilder enabled(boolean enabled)
      Sets whether this broadcast is enabled.
      Parameters:
      enabled - true to enable the broadcast
      Returns:
      This builder for chaining
    • interval

      @NotNull public @NotNull BroadcastBuilder interval(int seconds)
      Sets the interval between broadcasts in seconds.
      Parameters:
      seconds - The interval in seconds (must be positive)
      Returns:
      This builder for chaining
      Throws:
      IllegalArgumentException - if interval is not positive
    • showIn

      @NotNull public @NotNull BroadcastBuilder showIn(@NotNull @NotNull GameState... states)
      Sets the game states in which this broadcast should be shown.
      Parameters:
      states - The game states (varargs)
      Returns:
      This builder for chaining
    • addShowIn

      @NotNull public @NotNull BroadcastBuilder addShowIn(@NotNull @NotNull GameState state)
      Adds game states to show this broadcast in.
      Parameters:
      state - The game state to add
      Returns:
      This builder for chaining
    • type

      @NotNull public @NotNull BroadcastBuilder type(@NotNull @NotNull BroadcastType type)
      Sets the broadcast type.
      Parameters:
      type - The broadcast type (CHAT, TITLE, or ACTIONBAR)
      Returns:
      This builder for chaining
    • messages

      @NotNull public @NotNull BroadcastBuilder messages(@NotNull @NotNull String... messages)
      Sets the messages for a CHAT type broadcast.

      Replaces any previously set messages.

      Parameters:
      messages - The messages (varargs, supports color codes)
      Returns:
      This builder for chaining
    • addMessage

      @NotNull public @NotNull BroadcastBuilder addMessage(@NotNull @NotNull String message)
      Adds a message to the CHAT type broadcast.
      Parameters:
      message - The message to add (supports color codes)
      Returns:
      This builder for chaining
    • title

      @NotNull public @NotNull BroadcastBuilder title(@NotNull @NotNull String title)
      Sets the title for a TITLE type broadcast.
      Parameters:
      title - The title text (supports color codes)
      Returns:
      This builder for chaining
    • subtitle

      @NotNull public @NotNull BroadcastBuilder subtitle(@Nullable @Nullable String subtitle)
      Sets the subtitle for a TITLE type broadcast.
      Parameters:
      subtitle - The subtitle text (supports color codes)
      Returns:
      This builder for chaining
    • titleTiming

      @NotNull public @NotNull BroadcastBuilder titleTiming(int fadeIn, int stay, int fadeOut)
      Sets the timing for a TITLE type broadcast.
      Parameters:
      fadeIn - Fade in time in ticks
      stay - Stay time in ticks
      fadeOut - Fade out time in ticks
      Returns:
      This builder for chaining
    • actionBar

      @NotNull public @NotNull BroadcastBuilder actionBar(@NotNull @NotNull String message)
      Sets the message for an ACTIONBAR type broadcast.
      Parameters:
      message - The action bar message (supports color codes)
      Returns:
      This builder for chaining
    • addonId

      @NotNull public @NotNull BroadcastBuilder addonId(@NotNull @NotNull String addonId)
      Sets the addon ID that owns this broadcast.
      Parameters:
      addonId - The addon identifier
      Returns:
      This builder for chaining
    • customField

      @NotNull public @NotNull BroadcastBuilder customField(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      Adds a custom metadata field to this broadcast.
      Parameters:
      key - The field key
      value - The field value (should be serializable)
      Returns:
      This builder for chaining
    • getId

      @Nullable public @Nullable String getId()
    • isEnabled

      public boolean isEnabled()
    • getInterval

      public int getInterval()
    • getShowIn

      @NotNull public @NotNull Set<GameState> getShowIn()
    • getType

      @NotNull public @NotNull BroadcastType getType()
    • getMessages

      @NotNull public @NotNull List<String> getMessages()
    • getTitle

      @Nullable public @Nullable String getTitle()
    • getSubtitle

      @Nullable public @Nullable String getSubtitle()
    • getFadeIn

      public int getFadeIn()
    • getStay

      public int getStay()
    • getFadeOut

      public int getFadeOut()
    • getActionBar

      @Nullable public @Nullable String getActionBar()
    • getAddonId

      @Nullable public @Nullable String getAddonId()
    • getCustomFields

      @NotNull public @NotNull Map<String,Object> getCustomFields()
    • validate

      public void validate() throws IllegalStateException
      Validates that this builder has all required fields set correctly.
      Throws:
      IllegalStateException - if the builder is not valid
    • isValid

      public boolean isValid()
      Checks if this builder is valid without throwing an exception.
      Returns:
      true if the builder has all required fields
    • copy

      @NotNull public @NotNull BroadcastBuilder copy()
      Copies this builder.
      Returns:
      A new BroadcastBuilder with the same configuration
    • toString

      public String toString()
      Overrides:
      toString in class Object