Class GameTypeBuilder
java.lang.Object
dev.itsharshxd.zentrix.api.gametype.GameTypeBuilder
Fluent builder for creating custom game types dynamically.
This builder allows addon developers to create game types that integrate with the Zentrix game type system, including scoreboards for different states.
Example Usage
GameTypeBuilder trios = new GameTypeBuilder()
.name("trios")
.teamSize(3)
.minimumPlayers(6)
.maximumPlayers(30)
.startTime(45)
.scoreboard(GameTypeState.WAITING, sb -> sb
.title("&#FFD700&lTRIOS")
.line("&#AAAAAA Map: &#FFFFFF%arena%")
.line("")
.line("&#AAAAAA Players: 7FF55%players%/%max%"))
.scoreboard(GameTypeState.PLAYING, sb -> sb
.title("&#FFD700&lTRIOS")
.line("&#AAAAAA Phase: &#FFFFFF%phase%")
.line("&#AAAAAA Alive: 7FF55%alive%")
.line("&#AAAAAA Kills: &#FF5555%kills%"))
.addonId(getAddonId());
gameTypeService.registerGameType(trios);
- Since:
- 1.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for configuring scoreboards.static classHolds the configuration for a single scoreboard. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull GameTypeBuilderSets the addon ID that owns this game type.@NotNull GameTypeBuildercopy()Creates a copy of this builder.@NotNull GameTypeBuildercustomField(@NotNull String key, @Nullable Object value) Adds a custom metadata field to this game type.@Nullable Stringintint@Nullable StringgetName()intintbooleanisValid()Checks if this builder is valid without throwing an exception.@NotNull GameTypeBuildermaximumPlayers(int max) Sets the maximum number of players allowed in a game.@NotNull GameTypeBuilderminimumPlayers(int min) Sets the minimum number of players required to start a game.@NotNull GameTypeBuilderSets the name of the game type.@NotNull GameTypeBuilderRemoves the scoreboard for a specific game state.@NotNull GameTypeBuilderscoreboard(ZentrixGameType.GameTypeState state, @NotNull Consumer<GameTypeBuilder.ScoreboardBuilder> config) Configures the scoreboard for a specific game state.@NotNull GameTypeBuilderstartTime(int seconds) Sets the start time countdown duration in seconds.@NotNull GameTypeBuilderteamSize(int size) Sets the team size for this game type.toString()voidvalidate()Validates that this builder has all required fields set correctly.
-
Constructor Details
-
GameTypeBuilder
public GameTypeBuilder()Creates a new GameTypeBuilder instance.
-
-
Method Details
-
name
Sets the name of the game type.This is the unique identifier used for selection and configuration. Must only contain lowercase letters, numbers, and underscores.
- Parameters:
name- The game type name (e.g., "trios", "solo", "duos")- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if the name is null, empty, or contains invalid characters
-
teamSize
Sets the team size for this game type.- Parameters:
size- The team size (must be at least 1)- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if size is less than 1
-
minimumPlayers
Sets the minimum number of players required to start a game.- Parameters:
min- The minimum player count (must be at least 1)- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if min is less than 1
-
maximumPlayers
Sets the maximum number of players allowed in a game.- Parameters:
max- The maximum player count (must be at least 1)- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if max is less than 1
-
startTime
Sets the start time countdown duration in seconds.- Parameters:
seconds- The start time in seconds (must be positive)- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if seconds is not positive
-
scoreboard
@NotNull public @NotNull GameTypeBuilder scoreboard(@NotNull ZentrixGameType.GameTypeState state, @NotNull @NotNull Consumer<GameTypeBuilder.ScoreboardBuilder> config) Configures the scoreboard for a specific game state.builder.scoreboard(GameTypeState.PLAYING, sb -> sb .title("&#FFD700&lGAME") .line("&#AAAAAA Alive: 7FF55%alive%") .line("&#AAAAAA Kills: &#FF5555%kills%"));- Parameters:
state- The game state for this scoreboardconfig- A consumer to configure the scoreboard- Returns:
- This builder for chaining
-
noScoreboard
Removes the scoreboard for a specific game state.- Parameters:
state- The game state to remove the scoreboard for- Returns:
- This builder for chaining
-
addonId
Sets the addon ID that owns this game type.- Parameters:
addonId- The addon identifier- Returns:
- This builder for chaining
-
customField
@NotNull public @NotNull GameTypeBuilder customField(@NotNull @NotNull String key, @Nullable @Nullable Object value) Adds a custom metadata field to this game type.- Parameters:
key- The field keyvalue- The field value (should be serializable)- Returns:
- This builder for chaining
-
getName
-
getTeamSize
public int getTeamSize() -
getMinimumPlayers
public int getMinimumPlayers() -
getMaximumPlayers
public int getMaximumPlayers() -
getStartTime
public int getStartTime() -
getScoreboards
@NotNull public @NotNull Map<ZentrixGameType.GameTypeState,GameTypeBuilder.ScoreboardConfig> getScoreboards() -
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 GameTypeBuilder with the same configuration
-
toString
-