Package com.ohacd.matchbox.api
Class MatchboxAPI
java.lang.Object
com.ohacd.matchbox.api.MatchboxAPI
Main API class for interacting with the Matchbox plugin.
This class provides static methods for managing game sessions, players, and event listeners. It serves as the primary entry point for external plugins to interact with Matchbox functionality.
All methods are thread-safe and handle null inputs gracefully.
- Since:
- 0.9.5
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddEventListener(@NotNull MatchboxEventListener listener) Adds an event listener to receive game events.static booleanclearChatProcessors(@NotNull String sessionName) Unregisters all custom chat processors from a specific session.static @NotNull SessionBuildercreateSessionBuilder(@NotNull String name) Creates a new session builder for the specified session name.static intEnds all active game sessions gracefully.static booleanendSession(@Nullable String name) Ends a game session gracefully.static @NotNull Collection<ApiGameSession> Gets all active game sessions.static @NotNull Optional<com.ohacd.matchbox.game.utils.GamePhase> getCurrentPhase(@Nullable String sessionName) Gets the current game phase for a session.static @NotNull Set<MatchboxEventListener> Gets all registered event listeners.static @NotNull Optional<com.ohacd.matchbox.game.utils.Role> getPlayerRole(@Nullable org.bukkit.entity.Player player) Gets the current role of a player if they are in an active game.static @NotNull Optional<ApiGameSession> getPlayerSession(@Nullable org.bukkit.entity.Player player) Gets the session a player is currently in.static @NotNull Optional<ApiGameSession> getSession(@Nullable String name) Gets an existing game session by name.static booleanregisterChatProcessor(@NotNull String sessionName, @NotNull ChatProcessor processor) Registers a custom chat processor for a specific session.static booleanremoveEventListener(@Nullable MatchboxEventListener listener) Removes an event listener.static booleanunregisterChatProcessor(@NotNull String sessionName, @NotNull ChatProcessor processor) Unregisters a custom chat processor from a specific session.
-
Method Details
-
createSessionBuilder
Creates a new session builder for the specified session name.- Parameters:
name- the unique name for the session- Returns:
- a new SessionBuilder instance
- Throws:
IllegalArgumentException- if name is null or empty
-
getSession
@NotNull public static @NotNull Optional<ApiGameSession> getSession(@Nullable @Nullable String name) Gets an existing game session by name.- Parameters:
name- the session name (case-insensitive)- Returns:
- Optional containing the session if found, empty otherwise
-
getAllSessions
Gets all active game sessions.- Returns:
- a collection of all active sessions
-
endSession
Ends a game session gracefully.- Parameters:
name- the session name to end- Returns:
- true if the session was found and ended, false otherwise
-
endAllSessions
public static int endAllSessions()Ends all active game sessions gracefully.- Returns:
- the number of sessions that were ended
-
getPlayerSession
@NotNull public static @NotNull Optional<ApiGameSession> getPlayerSession(@Nullable @Nullable org.bukkit.entity.Player player) Gets the session a player is currently in.- Parameters:
player- the player to check- Returns:
- Optional containing the session if the player is in one, empty otherwise
-
getPlayerRole
@NotNull public static @NotNull Optional<com.ohacd.matchbox.game.utils.Role> getPlayerRole(@Nullable @Nullable org.bukkit.entity.Player player) Gets the current role of a player if they are in an active game.- Parameters:
player- the player to check- Returns:
- Optional containing the player's role if in a game, empty otherwise
-
getCurrentPhase
@NotNull public static @NotNull Optional<com.ohacd.matchbox.game.utils.GamePhase> getCurrentPhase(@Nullable @Nullable String sessionName) Gets the current game phase for a session.- Parameters:
sessionName- the session name- Returns:
- Optional containing the current phase if session exists, empty otherwise
-
addEventListener
Adds an event listener to receive game events.- Parameters:
listener- the listener to add- Throws:
IllegalArgumentException- if listener is null
-
removeEventListener
Removes an event listener.- Parameters:
listener- the listener to remove- Returns:
- true if the listener was removed, false if it wasn't found
-
getListeners
Gets all registered event listeners.- Returns:
- an unmodifiable copy of all registered listeners
-
registerChatProcessor
@Experimental public static boolean registerChatProcessor(@NotNull @NotNull String sessionName, @NotNull @NotNull ChatProcessor processor) Registers a custom chat processor for a specific session. The processor will be called for all chat messages in that session.- Parameters:
sessionName- the session name to register the processor forprocessor- the chat processor to register- Returns:
- true if the processor was registered, false if session not found
- Throws:
IllegalArgumentException- if sessionName or processor is null- Since:
- 0.9.5
-
unregisterChatProcessor
@Experimental public static boolean unregisterChatProcessor(@NotNull @NotNull String sessionName, @NotNull @NotNull ChatProcessor processor) Unregisters a custom chat processor from a specific session.- Parameters:
sessionName- the session name to unregister the processor fromprocessor- the chat processor to unregister- Returns:
- true if the processor was unregistered, false if not found
- Throws:
IllegalArgumentException- if sessionName or processor is null- Since:
- 0.9.5
-
clearChatProcessors
Unregisters all custom chat processors from a specific session.- Parameters:
sessionName- the session name to clear processors from- Returns:
- true if processors were cleared, false if session not found
- Throws:
IllegalArgumentException- if sessionName is null- Since:
- 0.9.5
-