Class BroadcastBuilder
java.lang.Object
dev.itsharshxd.zentrix.api.broadcast.BroadcastBuilder
Fluent builder for creating custom broadcasts dynamically.
This builder allows addon developers to create broadcasts that integrate with the Zentrix broadcast system, supporting CHAT, TITLE, and ACTIONBAR types.
Example Usage - Chat 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);
Example Usage - Title Broadcast
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull BroadcastBuilderSets the message for an ACTIONBAR type broadcast.@NotNull BroadcastBuilderaddMessage(@NotNull String message) Adds a message to the CHAT type broadcast.@NotNull BroadcastBuilderSets the addon ID that owns this broadcast.@NotNull BroadcastBuilderAdds game states to show this broadcast in.@NotNull BroadcastBuildercopy()Creates a copy of this builder.@NotNull BroadcastBuildercustomField(@NotNull String key, @Nullable Object value) Adds a custom metadata field to this broadcast.@NotNull BroadcastBuilderenabled(boolean enabled) Sets whether this broadcast is enabled.@Nullable String@Nullable Stringintint@Nullable StringgetId()intintgetStay()@Nullable String@Nullable StringgetTitle()@NotNull BroadcastTypegetType()@NotNull BroadcastBuilderSets the unique identifier for this broadcast.@NotNull BroadcastBuilderinterval(int seconds) Sets the interval between broadcasts in seconds.booleanbooleanisValid()Checks if this builder is valid without throwing an exception.@NotNull BroadcastBuilderSets the messages for a CHAT type broadcast.@NotNull BroadcastBuilderSets the game states in which this broadcast should be shown.@NotNull BroadcastBuilderSets the subtitle for a TITLE type broadcast.@NotNull BroadcastBuilderSets the title for a TITLE type broadcast.@NotNull BroadcastBuildertitleTiming(int fadeIn, int stay, int fadeOut) Sets the timing for a TITLE type broadcast.toString()@NotNull BroadcastBuildertype(@NotNull BroadcastType type) Sets the broadcast type.voidvalidate()Validates that this builder has all required fields set correctly.
-
Constructor Details
-
BroadcastBuilder
public BroadcastBuilder()Creates a new BroadcastBuilder instance.
-
-
Method Details
-
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
Sets whether this broadcast is enabled.- Parameters:
enabled-trueto enable the broadcast- Returns:
- This builder for chaining
-
interval
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
Sets the game states in which this broadcast should be shown.- Parameters:
states- The game states (varargs)- Returns:
- This builder for chaining
-
addShowIn
Adds game states to show this broadcast in.- Parameters:
state- The game state to add- Returns:
- This builder for chaining
-
type
Sets the broadcast type.- Parameters:
type- The broadcast type (CHAT, TITLE, or ACTIONBAR)- Returns:
- This builder for chaining
-
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
Adds a message to the CHAT type broadcast.- Parameters:
message- The message to add (supports color codes)- Returns:
- This builder for chaining
-
title
Sets the title for a TITLE type broadcast.- Parameters:
title- The title text (supports color codes)- Returns:
- This builder for chaining
-
subtitle
Sets the subtitle for a TITLE type broadcast.- Parameters:
subtitle- The subtitle text (supports color codes)- Returns:
- This builder for chaining
-
titleTiming
Sets the timing for a TITLE type broadcast.- Parameters:
fadeIn- Fade in time in ticksstay- Stay time in ticksfadeOut- Fade out time in ticks- Returns:
- This builder for chaining
-
actionBar
Sets the message for an ACTIONBAR type broadcast.- Parameters:
message- The action bar message (supports color codes)- Returns:
- This builder for chaining
-
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 keyvalue- The field value (should be serializable)- Returns:
- This builder for chaining
-
getId
-
isEnabled
public boolean isEnabled() -
getInterval
public int getInterval() -
getShowIn
-
getType
-
getMessages
-
getTitle
-
getSubtitle
-
getFadeIn
public int getFadeIn() -
getStay
public int getStay() -
getFadeOut
public int getFadeOut() -
getActionBar
-
getAddonId
-
getCustomFields
-
validate
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:
trueif the builder has all required fields
-
copy
Creates a copy of this builder.- Returns:
- A new BroadcastBuilder with the same configuration
-
toString
-