Class SessionBuilder

java.lang.Object
com.ohacd.matchbox.api.SessionBuilder

public class SessionBuilder extends Object
Builder class for creating and configuring game sessions.

Provides a fluent interface for setting up game sessions with custom configurations, players, spawn points, and other settings.

Example usage:


 // Enhanced error handling
 SessionCreationResult result = MatchboxAPI.createSessionBuilder("arena1")
     .withPlayers(arena.getPlayers())
     .withSpawnPoints(arena.getSpawnPoints())
     .withDiscussionLocation(arena.getDiscussionArea())
     .withSeatLocations(seatMap)
     .startWithResult();
 
 if (result.isSuccess()) {
     ApiGameSession session = result.getSession().get();
     // Use session
 } else {
     logger.warning("Failed to create session: " + result.getErrorMessage());
 }
 
 // Legacy approach
 ApiGameSession session = MatchboxAPI.createSessionBuilder("arena1")
     .withPlayers(arena.getPlayers())
     .withSpawnPoints(arena.getSpawnPoints())
     .start()
     .orElseThrow(() -> new RuntimeException("Failed to create session"));
 
Since:
0.9.5
  • Constructor Details

    • SessionBuilder

      public SessionBuilder(@NotNull @NotNull String sessionName)
      Creates a new session builder with the specified session name.
      Parameters:
      sessionName - the unique name for the session
      Throws:
      IllegalArgumentException - if sessionName is null or empty
  • Method Details

    • withPlayers

      @NotNull public @NotNull SessionBuilder withPlayers(@Nullable @Nullable Collection<org.bukkit.entity.Player> players)
      Sets the players for this session.
      Parameters:
      players - the players to include in the session
      Returns:
      this builder instance for method chaining
    • withPlayers

      @NotNull public @NotNull SessionBuilder withPlayers(@Nullable @Nullable org.bukkit.entity.Player... players)
      Sets the players for this session.
      Parameters:
      players - the players to include in the session
      Returns:
      this builder instance for method chaining
    • withSpawnPoints

      @NotNull public @NotNull SessionBuilder withSpawnPoints(@Nullable @Nullable List<org.bukkit.Location> spawnPoints)
      Sets the spawn points for players.
      Parameters:
      spawnPoints - list of spawn locations
      Returns:
      this builder instance for method chaining
    • withSpawnPoints

      @NotNull public @NotNull SessionBuilder withSpawnPoints(@Nullable @Nullable org.bukkit.Location... spawnPoints)
      Sets the spawn points for players.
      Parameters:
      spawnPoints - array of spawn locations
      Returns:
      this builder instance for method chaining
    • withDiscussionLocation

      @NotNull public @NotNull SessionBuilder withDiscussionLocation(@Nullable @Nullable org.bukkit.Location discussionLocation)
      Sets the discussion location for the session.
      Parameters:
      discussionLocation - the location where discussions take place
      Returns:
      this builder instance for method chaining
    • withSeatLocations

      @NotNull public @NotNull SessionBuilder withSeatLocations(@Nullable @Nullable Map<Integer,org.bukkit.Location> seatLocations)
      Sets the seat locations for the discussion phase.
      Parameters:
      seatLocations - map of seat numbers to locations
      Returns:
      this builder instance for method chaining
    • withCustomConfig

      @NotNull public @NotNull SessionBuilder withCustomConfig(@Nullable @Nullable GameConfig gameConfig)
      Sets custom game configuration for the session.
      Parameters:
      gameConfig - the game configuration to use
      Returns:
      this builder instance for method chaining
    • withConfig

      @NotNull public @NotNull SessionBuilder withConfig(@Nullable @Nullable GameConfig gameConfig)
      Sets custom game configuration for the session.
      Parameters:
      gameConfig - the game configuration to use
      Returns:
      this builder instance for method chaining
    • validate

      @NotNull public @NotNull Optional<String> validate()
      Validates the current builder configuration.
      Returns:
      Optional containing validation error, empty if valid
    • start

      @NotNull public @NotNull Optional<ApiGameSession> start()
      Creates and starts the game session with the configured settings.
      Returns:
      Optional containing the created session, empty if creation failed
    • createSessionOnly

      @NotNull @Experimental public @NotNull Optional<ApiGameSession> createSessionOnly()
      Creates the game session without starting the game. This is useful for testing scenarios where you need a configured session but don't want to trigger full game initialization.
      Returns:
      Optional containing the created session, empty if creation failed
      Since:
      0.9.5 (experimental)
    • startWithResult

      @NotNull public @NotNull SessionCreationResult startWithResult()
      Creates and starts the game session with detailed error reporting.
      Returns:
      SessionCreationResult containing success/failure information
    • configBuilder

      @NotNull public static GameConfig.Builder configBuilder()
      Creates a GameConfig builder for this session.
      Returns:
      a new GameConfig.Builder instance