Multiplayer API Logo

Multiplayer API

Java SDK for
Multiplayer Games

Java SDK

Java SDK Download

View on GitHub
Repository

Java API Documentation

Client

Constructor
public Client(
    String apiToken, 
    String apiPrivateToken, 
    String baseUrl,
    Logger logger
)

Initializes the SDK with API tokens and optional custom base URL. Uses Jackson Databind for JSON serialization.

Player Management

Players.registerPlayer
public static <T> PlayerRegisterResponse registerPlayer(
    Client client,
    String name, 
    T playerData
) throws IOException

Registers a new player with optional custom data. Uses generic type for player data with Jackson serialization.

Players.authenticatePlayer
public static <T> PlayerAuthResponse<T> authenticatePlayer(
    Client client,
    String playerToken
) throws IOException

Authenticates a player using their private token. Returns player information with typed data support.

Players.getAllPlayers
public static PlayerListResponse getAllPlayers(
    Client client
) throws IOException

Retrieves a list of all players (requires private API token).

Players.sendPlayerHeartbeat
public static PlayerHeartbeatResponse sendPlayerHeartbeat(
    Client client,
    String playerToken
) throws IOException

Updates player heartbeat to maintain online status. Call every 30-60 seconds.

Players.logoutPlayer
public static PlayerLogoutResponse logoutPlayer(
    Client client,
    String playerToken
) throws IOException

Logs out a player and updates their last logout timestamp.

Players.renamePlayer
public static PlayerRenameResponse renamePlayer(
    Client client,
    String playerToken,
    String newName
) throws IOException

Renames a player to a new name. Validates name length (2-50 characters) and requires player authentication.

Players.banPlayer
public static PlayerBanResponse banPlayer(
    Client client,
    int playerId,
    BanTime banDuration,
    String banReason
) throws IOException

Bans a player from the game with specified duration (HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, FOREVER) and optional reason. Requires private API token.

Players.unbanPlayer
public static PlayerUnbanResponse unbanPlayer(
    Client client,
    int playerId
) throws IOException

Unbans a previously banned player. Requires private API token.

Players.isBanned
public static boolean isBanned(ApiResponse response)

Checks if an API response indicates the player is banned. Returns true if the error message contains "You are banned".

Game Data

Games.getGameData
public static <T> GameDataResponse<T> getGameData(
    Client client
) throws IOException

Retrieves global game data with Jackson compatible nested objects.

Games.updateGameData
public static <T> SuccessResponse updateGameData(
    Client client,
    T data
) throws IOException

Updates global game data (requires private API token). Uses generic type for type safety.

Games.getPlayerData
public static <T> PlayerDataResponse<T> getPlayerData(
    Client client,
    String playerToken
) throws IOException

Retrieves a specific player's data using their authentication token with typed support.

Games.updatePlayerData
public static <T> SuccessResponse updatePlayerData(
    Client client,
    String playerToken,
    T data
) throws IOException

Updates a specific player's data like level, score, and inventory with generic type support.

Time Management

Time.getServerTime
public static ServerTimeResponse getServerTime(
    Client client
) throws IOException

Retrieves current server time in multiple formats including UTC timestamp.

Time.getServerTimeWithOffset
public static ServerTimeWithOffsetResponse getServerTimeWithOffset(
    Client client,
    int utcOffset
) throws IOException

Retrieves server time with specified UTC offset adjustment.

Room Management

Rooms.createRoom
public static <T> RoomCreateResponse createRoom(
    Client client,
    String playerToken,
    String roomName,
    int maxPlayers,
    String password,
    boolean hostSwitch,
    boolean canLeaveRoom,
    T rules,
    T playerData
) throws IOException

Creates a new game room for multiplayer sessions with typed rules support, host switching, and player data. Max players: 2-16.

Rooms.getRooms
public static RoomListResponse getRooms(
    Client client,
    String search,
    Integer limit
) throws IOException

Retrieves a list of all available game rooms with typed rules support. Supports search and limit parameters (limit: 1-50).

Rooms.joinRoom
public static <T> RoomJoinResponse joinRoom(
    Client client,
    String playerToken,
    String roomId,
    String password,
    T playerData
) throws IOException

Joins an existing game room with optional password and player data.

Rooms.leaveRoom
public static RoomLeaveResponse leaveRoom(
    Client client,
    String playerToken
) throws IOException

Leaves the current game room.

Rooms.getRoomPlayers
public static RoomPlayersResponse getRoomPlayers(
    Client client,
    String playerToken
) throws IOException

Retrieves a list of all players in the current room.

Rooms.sendRoomHeartbeat
public static HeartbeatResponse sendRoomHeartbeat(
    Client client,
    String playerToken
) throws IOException

Sends heartbeat to maintain connection in game room.

Rooms.getCurrentRoom
public static <T> CurrentRoomResponse<T> getCurrentRoom(
    Client client,
    String playerToken
) throws IOException

Gets comprehensive room state including player lists and pending actions with typed support.

Rooms.stopRoom
public static SuccessResponse stopRoom(
    Client client,
    String playerToken
) throws IOException

Stops the current game room (Host Only). Completely removes the room and all associated data.

Rooms.kickPlayer
public static RoomKickResponse kickPlayer(
    Client client,
    String playerToken,
    int playerId
) throws IOException

Kicks a player from the game room (Host Only). Cannot kick yourself.

Rooms.updateRoomPassword
public static SuccessResponse updateRoomPassword(
    Client client,
    String playerToken,
    String password
) throws IOException

Updates the room password (Host Only). Use empty string to remove password.

Room Actions

Actions.submitAction
public static ActionSubmitResponse submitAction(
    Client client,
    String playerToken,
    SubmitAction<?> request
) throws IOException

Submits a game action to specific targets (host, all, others, or specific players) with typed request data.

Actions.pollActions
public static ActionPollResponse pollActions(
    Client client,
    String playerToken
) throws IOException

Polls for completed actions from other players with typed response data.

Actions.getPendingActions
public static ActionPendingResponse<?> getPendingActions(
    Client client,
    String playerToken
) throws IOException

Retrieves a list of pending actions that need to be processed with typed request data.

Actions.completeAction
public static ActionCompleteResponse completeAction(
    Client client,
    String actionId,
    String playerToken,
    ActionComplete<?> request
) throws IOException

Marks an action as completed with response data using typed ActionComplete parameter.

Room Updates

Updates.updatePlayers
public static UpdatePlayersResponse updatePlayers(
    Client client,
    String playerToken,
    UpdatePlayers<?> request
) throws IOException

Sends updates to specific players or all players. Uses typed UpdatePlayers parameter.

Updates.pollUpdates
public static PollUpdatesResponse pollUpdates(
    Client client,
    String playerToken,
    PollUpdates request
) throws IOException

Polls for updates from other players. Returns list of update messages with typed data.

Realtime

Realtime.getToken
public static TokenResponse getToken(
    Client client,
    String playerToken
) throws IOException

Retrieves a realtime authentication token for WebSocket connections.

Realtime.connect
public boolean connect(
    String realtimeToken
)

Connects to the realtime WebSocket server using the provided token.

Realtime.send
public void send(
    ERoomTargetPlayer target,
    String command,
    Object data,
    int[] targetIds
)

Sends a message to the specified players via WebSocket.

Realtime.disconnect
public void disconnect()

Disconnects from the WebSocket server and cleans up resources.

Matchmaking

Matchmaking.getLobbies
public static MatchmakingListResponse getLobbies(
    Client client,
    String search,
    Integer limit
) throws IOException

Retrieves a list of all available matchmaking lobbies with typed rules support.

Requests.createMatchmakingLobby
public static MatchmakingCreateResponse createMatchmakingLobby(
    Client client,
    String playerToken,
    String matchmakingName,
    int maxPlayers,
    boolean strictFull,
    boolean joinByRequests,
    boolean hostSwitch,
    boolean canLeaveRoom,
    boolean realtimeRoom,
    String password,
    Object playerData,
    Object rules
) throws IOException

Creates a matchmaking lobby with typed player data and rules support. Supports approval-based or direct join modes.

Matchmaking.joinDirectly
public static MatchmakingDirectJoinResponse joinDirectly(
    Client client,
    String playerToken,
    String matchmakingId
) throws IOException

Joins a matchmaking lobby directly (requires lobby to be in direct join mode).

Requests.requestToJoinMatchmaking
public static MatchmakingJoinRequestResponse requestToJoinMatchmaking(
    Client client,
    String playerToken,
    String matchmakingId,
    Object playerData
) throws IOException

Requests to join a matchmaking lobby (requires lobby to be in approval mode).

Requests.respondToJoinRequest
public static MatchmakingPermissionResponse respondToJoinRequest(
    Client client,
    String playerToken,
    String requestId,
    EMatchmakingRequestAction action
) throws IOException

Responds to a join request (APPROVE or REJECT). Host only.

Matchmaking.getCurrent
public static MatchmakingCurrentResponse getCurrent(
    Client client,
    String playerToken
) throws IOException

Gets current matchmaking lobby status with typed rules support.

Matchmaking.getPlayers
public static MatchmakingPlayersResponse getPlayers(
    Client client,
    String playerToken
) throws IOException

Gets list of players in the matchmaking lobby with typed player data.

Matchmaking.startGame
public static MatchmakingStartResponse startGame(
    Client client,
    String playerToken
) throws IOException

Starts the game from matchmaking lobby and creates a room. Host only.

Matchmaking.leave
public static MatchmakingLeaveResponse leave(
    Client client,
    String playerToken
) throws IOException

Leaves the current matchmaking lobby.

Matchmaking.sendHeartbeat
public static MatchmakingHeartbeatResponse sendHeartbeat(
    Client client,
    String playerToken
) throws IOException

Sends heartbeat to maintain connection in matchmaking lobby.

Matchmaking.removeLobby
public static MatchmakingRemoveResponse removeLobby(
    Client client,
    String playerToken
) throws IOException

Removes the matchmaking lobby (Host Only).

Matchmaking.kickPlayer
public static MatchmakingKickResponse kickPlayer(
    Client client,
    String playerToken,
    int playerId
) throws IOException

Kicks a player from the matchmaking lobby (Host Only).

Matchmaking.updatePassword
public static SuccessResponse updatePassword(
    Client client,
    String playerToken,
    String password
) throws IOException

Updates the matchmaking lobby password (Host Only).

Requests.checkJoinRequestStatus
public static MatchmakingRequestStatusResponse checkJoinRequestStatus(
    Client client,
    String playerToken,
    String requestId
) throws IOException

Checks the status of a specific join request.

Leaderboard

Leaderboard.getLeaderboard
public static LeaderboardResponse<?> getLeaderboard(
    Client client,
    String[] sortBy,
    int limit
) throws IOException

Retrieves leaderboard sorted by specified fields with typed player data support.