Package com.ohacd.matchbox.api
Class SessionBuilder
java.lang.Object
com.ohacd.matchbox.api.SessionBuilder
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 Summary
ConstructorsConstructorDescriptionSessionBuilder(@NotNull String sessionName) Creates a new session builder with the specified session name. -
Method Summary
Modifier and TypeMethodDescriptionstatic GameConfig.BuilderCreates a GameConfig builder for this session.@NotNull Optional<ApiGameSession> Creates the game session without starting the game.@NotNull Optional<ApiGameSession> start()Creates and starts the game session with the configured settings.@NotNull SessionCreationResultCreates and starts the game session with detailed error reporting.validate()Validates the current builder configuration.@NotNull SessionBuilderwithConfig(@Nullable GameConfig gameConfig) Sets custom game configuration for the session.@NotNull SessionBuilderwithCustomConfig(@Nullable GameConfig gameConfig) Sets custom game configuration for the session.@NotNull SessionBuilderwithDiscussionLocation(@Nullable org.bukkit.Location discussionLocation) Sets the discussion location for the session.@NotNull SessionBuilderwithPlayers(@Nullable Collection<org.bukkit.entity.Player> players) Sets the players for this session.@NotNull SessionBuilderwithPlayers(@Nullable org.bukkit.entity.Player... players) Sets the players for this session.@NotNull SessionBuilderwithSeatLocations(@Nullable Map<Integer, org.bukkit.Location> seatLocations) Sets the seat locations for the discussion phase.@NotNull SessionBuilderwithSpawnPoints(@Nullable List<org.bukkit.Location> spawnPoints) Sets the spawn points for players.@NotNull SessionBuilderwithSpawnPoints(@Nullable org.bukkit.Location... spawnPoints) Sets the spawn points for players.
-
Constructor Details
-
SessionBuilder
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
Sets custom game configuration for the session.- Parameters:
gameConfig- the game configuration to use- Returns:
- this builder instance for method chaining
-
withConfig
Sets custom game configuration for the session.- Parameters:
gameConfig- the game configuration to use- Returns:
- this builder instance for method chaining
-
validate
Validates the current builder configuration.- Returns:
- Optional containing validation error, empty if valid
-
start
Creates and starts the game session with the configured settings.- Returns:
- Optional containing the created session, empty if creation failed
-
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
Creates and starts the game session with detailed error reporting.- Returns:
- SessionCreationResult containing success/failure information
-
configBuilder
Creates a GameConfig builder for this session.- Returns:
- a new GameConfig.Builder instance
-