Class GameTypeBuilder

java.lang.Object
dev.itsharshxd.zentrix.api.gametype.GameTypeBuilder

public class GameTypeBuilder extends Object
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: &#55FF55%players%/%max%"))
     .scoreboard(GameTypeState.PLAYING, sb -> sb
         .title("&#FFD700&lTRIOS")
         .line("&#AAAAAA Phase: &#FFFFFF%phase%")
         .line("&#AAAAAA Alive: &#55FF55%alive%")
         .line("&#AAAAAA Kills: &#FF5555%kills%"))
     .addonId(getAddonId());

 gameTypeService.registerGameType(trios);
 
Since:
1.1.0
See Also:
  • Constructor Details

    • GameTypeBuilder

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

    • name

      @NotNull public @NotNull GameTypeBuilder name(@NotNull @NotNull String 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

      @NotNull public @NotNull GameTypeBuilder teamSize(int size)
      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

      @NotNull public @NotNull GameTypeBuilder minimumPlayers(int min)
      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

      @NotNull public @NotNull GameTypeBuilder maximumPlayers(int max)
      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

      @NotNull public @NotNull GameTypeBuilder startTime(int seconds)
      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: &#55FF55%alive%")
           .line("&#AAAAAA Kills: &#FF5555%kills%"));
       
      Parameters:
      state - The game state for this scoreboard
      config - A consumer to configure the scoreboard
      Returns:
      This builder for chaining
    • noScoreboard

      @NotNull public @NotNull GameTypeBuilder noScoreboard(@NotNull ZentrixGameType.GameTypeState state)
      Removes the scoreboard for a specific game state.
      Parameters:
      state - The game state to remove the scoreboard for
      Returns:
      This builder for chaining
    • addonId

      @NotNull public @NotNull GameTypeBuilder addonId(@NotNull @NotNull String 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 key
      value - The field value (should be serializable)
      Returns:
      This builder for chaining
    • getName

      @Nullable public @Nullable String 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

      @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 GameTypeBuilder copy()
      Creates a copy of this builder.
      Returns:
      A new GameTypeBuilder with the same configuration
    • toString

      public String toString()
      Overrides:
      toString in class Object