Package com.ohacd.matchbox.api
Class SessionCreationResult
java.lang.Object
com.ohacd.matchbox.api.SessionCreationResult
Result object for session creation operations that provides detailed success/failure information.
This class enhances error reporting compared to simple Optional returns, allowing developers to understand exactly why a session creation failed.
Example usage:
SessionCreationResult result = MatchboxAPI.createSessionBuilder("arena1")
.withPlayers(players)
.withSpawnPoints(spawns)
.startWithResult();
if (result.isSuccess()) {
ApiGameSession session = result.getSession();
// Use session
} else {
SessionCreationResult.ErrorType error = result.getErrorType();
String message = result.getErrorMessage();
logger.warning("Failed to create session: " + error + " - " + message);
}
- Since:
- 0.9.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of possible error types during session creation. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic @NotNull SessionCreationResultfailure(@NotNull SessionCreationResult.ErrorType errorType, @Nullable String errorMessage) Creates a failure result.Gets the error message if the creation failed.@NotNull Optional<SessionCreationResult.ErrorType> Gets the error type if the creation failed.@NotNull Optional<ApiGameSession> Gets the created session if successful.inthashCode()booleanGets whether the session creation failed.booleanGets whether the session creation was successful.static @NotNull SessionCreationResultsuccess(@NotNull ApiGameSession session) Creates a successful result.@NotNull Optional<ApiGameSession> Deprecated.toString()
-
Method Details
-
success
@NotNull public static @NotNull SessionCreationResult success(@NotNull @NotNull ApiGameSession session) Creates a successful result.- Parameters:
session- the created session- Returns:
- a successful result
-
failure
@NotNull public static @NotNull SessionCreationResult failure(@NotNull @NotNull SessionCreationResult.ErrorType errorType, @Nullable @Nullable String errorMessage) Creates a failure result.- Parameters:
errorType- the type of error that occurrederrorMessage- detailed error message (can be null for default message)- Returns:
- a failure result
-
isSuccess
public boolean isSuccess()Gets whether the session creation was successful.- Returns:
- true if successful, false otherwise
-
isFailure
public boolean isFailure()Gets whether the session creation failed.- Returns:
- true if failed, false otherwise
-
getSession
Gets the created session if successful.- Returns:
- Optional containing the session if successful, empty otherwise
-
getErrorType
Gets the error type if the creation failed.- Returns:
- Optional containing the error type if failed, empty otherwise
-
getErrorMessage
Gets the error message if the creation failed.- Returns:
- Optional containing the error message if failed, empty otherwise
-
toOptional
Deprecated.UsegetSession()for more detailed informationConverts this result to the legacy Optional format for backward compatibility.- Returns:
- Optional containing the session if successful, empty otherwise
-
equals
-
hashCode
public int hashCode() -
toString
-
getSession()for more detailed information