Skip to main content

Java SDK Getting Started Guide

Last updated on

Overview

You can use AccelByte Cloud's Java SDK to implement our backend services within your game. The SDK acts as a bridge between your game and our services. Follow the tutorials below to learn how to set up our Cloud Java SDK.

Prerequisites

Getting Started

Installation

Add the required configuration in gradle.build. Replace {VERSION} with the specific release version tag from releases without the leading v character.

repositories {
mavenCentral()
maven {
url 'https://nexus.accelbyte.net/repository/maven-releases/'
}
}

dependencies {
implementation 'net.accelbyte.sdk:sdk:{VERSION}'
}
tip

Use the latest Java version that matches the Justice backend version.

Log in as a Client using the SDK

Follow the steps below to log in as the client you have just created:

  1. Create an http client instance called OkhttpClient.

  2. Create a token repository instance called DefaultConfigRepository.

  3. Create a config repository instance called DefaultTokenRepository.

  4. Create a Server SDK instance called AccelByteSDK using the http client, token repository, and config repository instances you have just created.

  5. Call the loginClient method of the AccelByteSDK Server SDK instance.

    import net.accelbyte.sdk.core.AccelByteSDK;
    import net.accelbyte.sdk.core.client.OkhttpClient;
    import net.accelbyte.sdk.core.logging.OkhttpLogger;
    import net.accelbyte.sdk.core.repository.DefaultConfigRepository;
    import net.accelbyte.sdk.core.repository.DefaultTokenRepository;

    ...

    OkhttpClient httpClient = new OkhttpClient();
    DefaultTokenRepository tokenRepository = DefaultTokenRepository.getInstance();
    DefaultConfigRepository configRepository = new DefaultConfigRepository();

    AccelByteSDK sdk = new AccelByteSDK(
    httpClient,
    tokenRepository,
    configRepository
    );

    boolean login = sdk.loginClient();

    if (!login) {
    // Login failed
    }
    tip

    DefaultTokenRepository provides the necessary values for AccelByteSDK from environment variables such as AB_BASE_URL, AB_CLIENT_ID, and AB_CLIENT_SECRET.

Available AccelByte Services

You can now start using any of the following AccelByte Cloud services in your app.

SDK Examples

See our Java SDK example repo for a selection of test cases you can use to customize your game.

IAM

API Docs
SDK reference

import net.accelbyte.sdk.api.iam.models.*;
import net.accelbyte.sdk.api.iam.operations.*;
import net.accelbyte.sdk.api.iam.wrappers.*;
Basic

API Docs
SDK reference

import net.accelbyte.sdk.api.basic.operations.*;
import net.accelbyte.sdk.api.basic.wrappers.*;
Social

API Docs
SDK reference

import net.accelbyte.sdk.api.social.models.*;
import net.accelbyte.sdk.api.social.operations.*;
import net.accelbyte.sdk.api.social.wrappers.*;
Platform

API Docs
SDK reference

import net.accelbyte.sdk.api.platform.models.*;
import net.accelbyte.sdk.api.platform.operations.*;
import net.accelbyte.sdk.api.platform.wrappers.*;
Group

API Docs
SDK reference

import net.accelbyte.sdk.api.group.models.*;
import net.accelbyte.sdk.api.group.operations.*;
import net.accelbyte.sdk.api.group.wrappers.*;
Cloudsave

API Docs
SDK reference

import net.accelbyte.sdk.api.cloudsave.models.*;
import net.accelbyte.sdk.api.cloudsave.operations.*;
import net.accelbyte.sdk.api.cloudsave.wrappers.*;
DSM Controller

API Docs
SDK reference

import net.accelbyte.sdk.api.dsmc.models.*;
import net.accelbyte.sdk.api.dsmc.operations.*;
import net.accelbyte.sdk.api.dsmc.wrappers.*;
Session Browser

API Docs
SDK reference

net.accelbyte.sdk.api.sessionbrowser.models.*;
import net.accelbyte.sdk.api.sessionbrowser.operations.*;
import net.accelbyte.sdk.api.sessionbrowser.wrappers.*;
Lobby

API Docs
SDK reference

import net.accelbyte.sdk.api.lobby.models.*;
import net.accelbyte.sdk.api.lobby.operations.*;
import net.accelbyte.sdk.api.lobby.wrappers.*;
Achievement

API Docs
SDK reference

import net.accelbyte.sdk.api.achievement.models.*;
import net.accelbyte.sdk.api.achievement.operations.*;
import net.accelbyte.sdk.api.achievement.wrappers.*;
DS Log Manager

API Docs
SDK reference

import net.accelbyte.sdk.api.dslogmanager.models.*;
import net.accelbyte.sdk.api.dslogmanager.operations.*;
import net.accelbyte.sdk.api.dslogmanager.wrappers.*;
UGC

API Docs
SDK reference

import net.accelbyte.sdk.api.ugc.models.*;
import net.accelbyte.sdk.api.ugc.operations.*;
import net.accelbyte.sdk.api.ugc.wrappers.*;
Leaderboard

API Docs
SDK reference

import net.accelbyte.sdk.api.leaderboard.models.*;
import net.accelbyte.sdk.api.leaderboard.operations.*;
import net.accelbyte.sdk.api.leaderboard.wrappers.*;
GDPR

API Docs
SDK reference

import net.accelbyte.sdk.api.gdpr.models.*;
import net.accelbyte.sdk.api.gdpr.operations.*;
import net.accelbyte.sdk.api.gdpr.wrappers.*;
Legal

API Docs
SDK reference

import net.accelbyte.sdk.api.legal.models.*;
import net.accelbyte.sdk.api.legal.operations.*;
import net.accelbyte.sdk.api.legal.wrappers.*;
Matchmaking

API Docs
SDK reference

import net.accelbyte.sdk.api.matchmaking.models.*;
import net.accelbyte.sdk.api.matchmaking.operations.*;
import net.accelbyte.sdk.api.matchmaking.wrappers.*;

Achievement Service

Before using the Achievement service, you will need to set some permissions. Initialize the Achievements wrapper from Achievement service using the following code:

Achievements wAchievements = new Achievements(sdk);

Once completed, you can use the SDK to create, read, update, or delete achievements.

Creating an achievement

POST /achievement/v1/admin/namespaces/{namespace}/achievements

ModelsAchievementRequest newAchievement = ModelsAchievementRequest.builder()
.achievementCode(achievementCode)
.defaultLanguage("en")
.name(Collections.singletonMap("en", achievementName))
.description(Collections.singletonMap("en", achievementDesc))
.goalValue(1000f)
.statCode(achievementCode)
.hidden(true)
.incremental(false)
.lockedIcons(Arrays.asList(new ModelsIcon[] { ModelsIcon.builder()
.slug("shield-locked")
.url("https://cdn.demo.accelbyte.io/files/accelbyte/achievements/50000f325ef841a6972a005779e20991.png")
.build() }))
.unlockedIcons(Arrays.asList(new ModelsIcon[] { ModelsIcon.builder()
.slug("shield-unlocked")
.url("https://cdn.demo.accelbyte.io/files/accelbyte/achievements/fe89fd07102f4057be202fbd3fdd9a21.png")
.build() }))
.tags(Arrays.asList(new String[] { "sdk", "test", "java" }))
.build();

ModelsAchievementResponse cResp = wAchievements.adminCreateNewAchievement(
AdminCreateNewAchievement.builder()
.namespace(namespace)
.body(newAchievement)
.build());

Deleting an achievement

DELETE /achievement/v1/admin/namespaces/{namespace}/achievements/{achievementCode}

wAchievements.adminDeleteAchievement(AdminDeleteAchievement.builder()
.namespace(namespace)
.achievementCode(achievementCode)
.build());

Retrieving all achievements

GET /achievement/v1/admin/namespaces/{namespace}/achievements

ModelsPaginatedAchievementResponse gaResp = wAchievements
.adminListAchievements(AdminListAchievements.builder()
.namespace(namespace)
.limit(100)
.offset(0)
.build());

Updating an achievement

PUT /achievement/v1/admin/namespaces/{namespace}/achievements/{achievementCode}

ModelsAchievementUpdateRequest updateAchievement = ModelsAchievementUpdateRequest.builder()
.goalValue(2000f)
.build();

ModelsAchievementResponse uResp = wAchievements.adminUpdateAchievement(
AdminUpdateAchievement.builder()
.namespace(namespace)
.achievementCode(achievementCode)
.body(updateAchievement)
.build());

Retrieve an Achievement by its code

GET /achievement/v1/admin/namespaces/{namespace}/achievements/{achievementCode}

ModelsAchievementResponse rResp = wAchievements.adminGetAchievement(AdminGetAchievement.builder()
.namespace(namespace)
.achievementCode(achievementCode)
.build());
Assertions.assertNotNull(rResp);
Assertions.assertEquals(rResp.getGoalValue(), 2000f);
Assertions.assertEquals(rResp.getName().get("en"), achievementName);

Basic Service

Before using the Basic service, you will need to set some permissions. Initialize the UserProfile wrapper from the Basic service using the following code:

UserProfile wProfile = new UserProfile(sdk);

Once completed, you can use the SDK to create, read, update, or delete player profiles.

Creating a profile

POST /v1/public/namespaces/{namespace}/users/me/profiles

UserProfilePrivateCreate createProfile = UserProfilePrivateCreate.builder()
.firstName(profileFirstName)
.lastName(profileLastName)
.dateOfBirth(profileDateOfBirth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
.language(profileLanguage)
.build();

UserProfilePrivateInfo cInfo = wProfile.createMyProfile(CreateMyProfile.builder()
.namespace(namespace)
.body(createProfile)
.build());

Deleting a profile

DELETE /v1/admin/namespaces/{namespace}/users/{userId}/profiles

UserProfilePrivateInfo delResp = wProfile.deleteUserProfile(DeleteUserProfile.builder()
.namespace(namespace)
.userId(userId)
.build());

Retrieving a profile

GET /v1/public/namespaces/{namespace}/users/{userId}/profiles

UserProfileInfo userProfile = wProfile.publicGetUserProfileInfo(PublicGetUserProfileInfo.builder()
.namespace(namespace)
.userId(userId)
.build());

Updating a profile

PUT /v1/public/namespaces/{namespace}/users/{userId}/profiles

UserProfileUpdate upd = UserProfileUpdate.builder()
.timeZone(profileTimeZone)
.build();

wProfile.updateUserProfile( PublicUpdateUserProfile.builder()
.namespace(namespace)
.userId(userId)
.body(upd)
.build());

Cloudsave Service

Before using the Cloudsave service, you will need to set some permissions. Initialize the PublicGameRecord wrapper from the Cloudsave service using the following code:

PublicGameRecord wPublicGameRecord = new PublicGameRecord(sdk);

Once completed, you can use the SDK to create, read, update, or delete cloudsaves.

Creating a game record

POST /cloudsave/v1/namespaces/{namespace}/records/{key}

TestModelsGameRecordRequest gameRecord = TestModelsGameRecordRequest.builder()
.Foo(gameRecordFoo)
.FooBar(gameRecordFooBar)
.FooValue(gameRecordFooValue)
.build();

wPublicGameRecord.postGameRecordHandlerV1(PostGameRecordHandlerV1.builder()
.namespace(namespace)
.key(gameRecordKey)
.body(gameRecord)
.build());

Deleting a game record

DELETE /cloudsave/v1/namespaces/{namespace}/records/{key}

wPublicGameRecord.deleteGameRecordHandlerV1(DeleteGameRecordHandlerV1.builder()
.namespace(namespace)
.key(gameRecordKey)
.build());

Retrieving a game record

GET /cloudsave/v1/namespaces/{namespace}/records/{key}

ModelsGameRecordResponse gRecord = wPublicGameRecord.getGameRecordHandlerV1(GetGameRecordHandlerV1.builder()
.namespace(namespace)
.key(gameRecordKey)
.build());

Updating a game record

PUT /cloudsave/v1/namespaces/{namespace}/records/{key}

TestModelsGameRecordRequest updateRecord = TestModelsGameRecordRequest.builder()
.Foo(gameRecordFoo)
.FooBar(gameRecordFooBar + "update")
.FooValue(gameRecordFooValue)
.build();

wPublicGameRecord.putGameRecordHandlerV1(PutGameRecordHandlerV1.builder()
.namespace(namespace)
.key(gameRecordKey)
.body(updateRecord)
.build());

DS Log Manager Service

Before using the DS Log Manager service, you will need to set some permissions. Initialize the TerminatedServers wrapper from the DS Log Manager service using the following code:

TerminatedServers wTerminatedServers = new TerminatedServers(sdk);

Once completed, you can use the SDK to create, read, update, or delete logs.

Retrieving all terminated servers

GET /dslogmanager/namespaces/{namespace}/servers/search

ModelsListTerminatedServersResponse tsResp = wTerminatedServers
.listTerminatedServers(ListTerminatedServers.builder()
.namespace(namespace)
.limit(10)
.build());

DSMC Service

Before using the DSMC service, you will need to set some permissions. Initialize the Session wrapper from the DSMC service using the following code:

net.accelbyte.sdk.api.dsmc.wrappers.Session wSession = new net.accelbyte.sdk.api.dsmc.wrappers.Session(sdk);

Once completed, you can use the SDK to create, read, update, or delete DSMCs.

Creating a session

POST /dsmcontroller/namespaces/{namespace}/sessions

net.accelbyte.sdk.api.dsmc.models.ModelsSessionResponse csResp = wSession
.createSession(net.accelbyte.sdk.api.dsmc.operations.session.CreateSession.builder()
.namespace(target_namespace)
.body(sessionRequest)
.build());

Claiming a Dedicated Server

POST dsmcontroller/namespaces/{namespace}/sessions/claim

ModelsClaimSessionRequest claimServer = ModelsClaimSessionRequest.builder()
.sessionId(session_id)
.build();

wSession.claimServer(ClaimServer.builder()
.namespace(target_namespace)
.body(claimServer)
.build());

Retrieving a session

GET /dsmcontroller/namespaces/{namespace}/sessions/{sessionID}

net.accelbyte.sdk.api.dsmc.models.ModelsSessionResponse csResp = wSession
.createSession(net.accelbyte.sdk.api.dsmc.operations.session.CreateSession.builder()
.namespace(target_namespace)
.body(sessionRequest)
.build());

Event Log Service

Before using the Event Log service, you will need to set some permissions. Initialize the EventV2 wrapper from the Event Log service using the following code:

EventV2 wEvent = new EventV2(sdk);

Once completed, you can use the SDK to create, read, update, or delete event logs.

Retrieving a set of events

POST /event/v2/admin/namespaces/{namespace}/query

ModelsGenericQueryPayload eQueryPayload = ModelsGenericQueryPayload.builder()
.clientId(_sdk.getSdkConfiguration().getConfigRepository().getClientId())
.build();

ModelsEventResponseV2 eResp = wEvent.queryEventStreamHandler(QueryEventStreamHandler.builder()
.namespace(namespace)
.offset(0)
.pageSize(10)
.body(eQueryPayload)
.build());

Retrieving a player's events

Get /event/v2/admin/namespaces/{namespace}/users/{userId}/event

ModelsEventResponseV2 eResp = wEvent.getEventSpecificUserV2Handler(GetEventSpecificUserV2Handler.builder()
.namespace(namespace)
.userId(userId)
.offset(0)
.pageSize(10)
.build());

GDPR Service

Before using the GDPR service, you will need to set some permissions. Initialize the DataRetrieval wrapper from the GDPR service using the following code:

DataRetrieval wGdprRetrieval = new DataRetrieval(sdk);

Once completed, you can use the SDK to create, read, update, or delete GDPRs.

Creating admin email configuration

POST /gdpr/admin/namespaces/{namespace}/emails/configurations

wGdprRetrieval.saveAdminEmailConfiguration(SaveAdminEmailConfiguration.builder()
.namespace(namespace)
.body(Arrays.asList(new String[] { emailToTest }))
.build());

Deleting admin email configuration

DELETE /gdpr/admin/namespaces/{namespace}/emails/configurations

wGdprRetrieval.deleteAdminEmailConfiguration(DeleteAdminEmailConfiguration.builder()
.namespace(namespace)
.emails(Arrays.asList(new String[] { anotherEmailToTest }))
.build());

Retrieving an admin email addresses configuration

GET /gdpr/admin/namespaces/{namespace}/emails/configurations

List<String> emails = wGdprRetrieval.getAdminEmailConfiguration(
GetAdminEmailConfiguration.builder()
.namespace(namespace)

### Updating an admin email configuration

PUT /gdpr/admin/namespaces/{namespace}/emails/configurations

```java
wGdprRetrieval.updateAdminEmailConfiguration(UpdateAdminEmailConfiguration.builder()
.namespace(namespace)
.body(Arrays.asList(new String[] { anotherEmailToTest }))
.build());

Group Service

Before using the Group service, you will need to set some permissions. Initialize the Group wrapper from the Group service using the following code:

Group wGroup = new Group(sdk);

Once completed, you can use the SDK to create, read, update, or delete groups.

Creating a group

POST /group/v1/public/namespaces/{namespace}/groups

ModelsPublicCreateNewGroupRequestV1 createGroup = ModelsPublicCreateNewGroupRequestV1.builder()
.groupName(groupName)
.groupType(groupType)
.groupDescription(groupDescription)
.groupMaxMember(100)
.groupRegion(groupRegion)
.configurationCode(configurationCode)
.build();

ModelsGroupResponseV1 cGroup = wGroup.createNewGroupPublicV1(CreateNewGroupPublicV1.builder()
.namespace(namespace)
.body(createGroup)
.build());

Deleting a group

DELETE /group/v1/public/namespaces/{namespace}/groups/{groupId}

wGroup.deleteGroupPublicV1(DeleteGroupPublicV1.builder()
.namespace(namespace)
.groupId(groupId)
.build());

Retrieving a single group

GET /group/v1/public/namespaces/{namespace}/groups/{groupId}

ModelsGroupResponseV1 gGroup = wGroup.getSingleGroupPublicV1(GetSingleGroupPublicV1.builder()
.namespace(namespace)
.groupId(group_id)
.build());

Updating a group

PATCH /group/v1/public/namespaces/{namespace}/groups/{groupId}

ModelsUpdateGroupRequestV1 updateGroup = ModelsUpdateGroupRequestV1.builder()
.groupDescription(groupDescriptionUpdated)
.build();

ModelsGroupResponseV1 uGroup = wGroup.updateSingleGroupV1(UpdateSingleGroupV1.builder()
.namespace(namespace)
.groupId(group_id)
.body(updateGroup)
.build());

IAM Service

Before using the IAM service, you will need to set some permissions. Initialize the UsersV4 wrapper from the IAM service using the following code:

UsersV4 wIamUserV4 = new UsersV4(sdk);

Once completed, you can use the SDK to create, read, update, or delete players.

Creating a player

POST /iam/namespaces/{namespace}/users

AccountCreateUserRequestV4 newUser = AccountCreateUserRequestV4.builder()
.authType("EMAILPASSWD")
.emailAddress(userEmail)
.password(userPassword)
.displayName(userDisplayName)
.username(userName)
.country("ID")
.dateOfBirth(userDateOfBirth)
.build();

AccountCreateUserResponseV4 cuResp = wIamUserV4.publicCreateUserV4(
PublicCreateUserV4.builder()
.namespace(namespace)
.body(newUser)
.build());

Deleting a player

DELETE /iam/namespaces/{namespace}/users/{userId}

wIamUser.deleteUser(DeleteUser.builder()
.namespace(namespace)
.userId(user_id)
.build());

Retrieving a player by ID

GET /iam/namespaces/{namespace}/users/{userId}

ModelUserResponse gUser = wIamUser.getUserByUserID(
GetUserByUserID.builder()
.namespace(namespace)
.userId(user_id)
.build());

Updating a player

PUT /iam/namespaces/{namespace}/users/{userId}

ModelUserUpdateRequest updateUser = ModelUserUpdateRequest.builder()
.dateOfBirth(userDateOfBirthUpdated)
.build();

Leaderboard Service

Before using the Leaderboard service, you will need to set some permissions. Initialize the LeaderboardConfiguration wrapper from the Leaderboard service using the following code:

LeaderboardConfiguration wLeaderboard = new LeaderboardConfiguration(sdk);

Once completed, you can use the SDK to create, read, update, or delete leaderboards.

Creating a leaderboard

POST /leaderboard/v1/admin/namespaces/{namespace}/leaderboards

ModelsLeaderboardConfigReq newLeaderboard = ModelsLeaderboardConfigReq.builder()
.leaderboardCode(leaderboardCode)
.name(leaderboardName)
.statCode("1")
.seasonPeriod(36)
.descending(false)
.startTime(startTime)
.daily(ModelsDailyConfig.builder().resetTime("00:00:00").build())
.weekly(ModelsWeeklyConfig.builder().resetDay(0).resetTime("00:00:00").build())
.monthly(ModelsMonthlyConfig.builder().resetDate(1).resetTime("00:00:00").build())
.build();

ModelsLeaderboardConfigReq cLeaderboard = wLeaderboard
.createLeaderboardConfigurationAdminV1(CreateLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.body(newLeaderboard)
.build());

Deleting a leaderboard

DELETE /leaderboard/v1/admin/namespaces/{namespace}/leaderboards/{leaderboardCode}

wLeaderboard.deleteLeaderboardConfigurationAdminV1(DeleteLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.leaderboardCode(leaderboardCode)
.build());

Retrieving a leaderboard

GET /leaderboard/v1/admin/namespaces/{namespace}/leaderboards/{leaderboardCode}

ModelsGetLeaderboardConfigResp gLeaderboard = wLeaderboard
.getLeaderboardConfigurationAdminV1(GetLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.leaderboardCode(leaderboardCode)
.build());

Updating a leaderboard

PUT /leaderboard/v1/admin/namespaces/{namespace}/leaderboards/{leaderboardCode}

ModelsUpdateLeaderboardConfigReq updateLeaderboard = ModelsUpdateLeaderboardConfigReq.builder()
.name(leaderboardName)
.statCode("1")
.startTime(startTime)
.seasonPeriod(40)
.build();

ModelsGetLeaderboardConfigResp uLeaderboard = wLeaderboard
.updateLeaderboardConfigurationAdminV1(UpdateLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.leaderboardCode(leaderboardCode)
.body(updateLeaderboard)
.build());

Before using the Legal service, you will need to set some permissions. Initialize the Agreement wrapper from the Legal service using the following code:

Agreement wLegalAgreement = new Agreement(sdk);

Once completed, you can use the SDK to create, read, update, or delete agreements.

Bulk accept policy versions

POST /public/agreements/policies

List<AcceptAgreementRequest> request = Arrays.asList(AcceptAgreementRequest.builder()
.localizedPolicyVersionId(localizedPolicyVersionId)
.policyVersionId(policyVersionId)
.policyId(policyId)
.isAccepted(true)
.build());

wLegalAgreement.bulkAcceptVersionedPolicy(BulkAcceptVersionedPolicy.builder()
.body(request)
.build());

Retrieving agreements

GET /public/agreements/policies

List<RetrieveAcceptedAgreementResponse> aggrs = wLegalAgreement
.retrieveAgreementsPublic(RetrieveAgreementsPublic.builder().build());

Updating marketing preferences

PATCH /public/agreements/localized-policy-versions/preferences

List<AcceptAgreementRequest> agreementRequests = Arrays.asList(new AcceptAgreementRequest[] {
AcceptAgreementRequest.builder()
.localizedPolicyVersionId(localizedPolicyVersionId)
.policyVersionId(policyVersionId)
.policyId(policyId)
.isAccepted(true)
.build()
});

wLegalAgreement.changePreferenceConsent(
ChangePreferenceConsent.builder()
.body(agreementRequests)
.build());

Lobby Service

Before using the Lobby service, you will need to set some permissions. Initialize the Notification wrapper from the Lobby service using the following code:

Notification wLobbyNotification = new Notification(_sdk);

Once completed, you can use the SDK to create, read, update, or delete notifications or friends, or send and receive WebSocket formatted messages from your app.

Sending a free form notification to a player

POST /notification/namespaces/{namespace}/freeform

ModelFreeFormNotificationRequest notifBody = ModelFreeFormNotificationRequest.builder()
.topic(topic)
.message(message)
.build();

wLobbyNotification.freeFormNotification(FreeFormNotification.builder()
.namespace(namespace)
.body(notifBody)
.build());

Receiving and parsing WebSocket messages

final String request_id = GenerateRandomId(64);
final CountDownLatch response = new CountDownLatch(1);
final Map<String,String> parsedResponseWSM = new HashMap<>();

WebSocketListener listener = new WebSocketListener() {
@Override
public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
if (response.getCount() > 0) {
parsedResponseWSM .putAll(net.accelbyte.sdk.core.util.Helper.parseWSM(text));
response.countDown();
}
}
};

OkhttpWebSocketClient ws = OkhttpWebSocketClient.create(
new DefaultConfigRepository(),
DefaultTokenRepository.getInstance(),
listener);

String requestMessage = PartyCreateRequest.builder()
.id(requestId)
.build()
.toWSM();

ws.sendMessage(requestMessage);

response.await(10, TimeUnit.SECONDS);

Sending a request for offline notifications using WebSocket

type: offlineNotificationRequest
id: <websocket-message-id>

final String request_id = GenerateRandomId(64);
final CountDownLatch response = new CountDownLatch(1);
final StringBuilder responseMessage = new StringBuilder();

WebSocketListener listener = new WebSocketListener() {
@Override
public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
if (response.getCount() > 0) {
responseMessage.append(text);
response.countDown();
}
}
};

OkhttpWebSocketClient ws = OkhttpWebSocketClient.create(
new DefaultConfigRepository(),
DefaultTokenRepository.getInstance(),
listener);

String requestMessage = OfflineNotificationRequest.builder()
.id(requestId)
.build()
.toWSM();

ws.sendMessage(requestMessage);

response.await(10, TimeUnit.SECONDS);

Sending a request to join a party using WebSocket

type: partyJoinRequest
id: <websocket-message-id>
invitationToken: <invitation-token>
partyId: <party-id>

final String request_id = GenerateRandomId(64);
final CountDownLatch response = new CountDownLatch(1);
final StringBuilder responseMessage = new StringBuilder();

WebSocketListener listener = new WebSocketListener() {
@Override
public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
if (response.getCount() > 0) {
responseMessage.append(text);
response.countDown();
}
}
};

OkhttpWebSocketClient ws = OkhttpWebSocketClient.create(
new DefaultConfigRepository(),
DefaultTokenRepository.getInstance(),
listener);

String requestMessage = PartyCreateRequest.builder()
.id(requestId)
.build()
.toWSM();

ws.sendMessage(requestMessage);

response.await(10, TimeUnit.SECONDS);

Matchmaking Service

Before using the Matchmaking service, you will need to set some permissions. Initialize the Matchmaking wrapper from the Matchmaking service using the following code:

Matchmaking wMatchmaking = new Matchmaking(sdk);

Once completed, you can use the SDK to create, read, update, or delete matchmaking.

Adding a player into a session in a channel

POST /matchmaking/v1/admin/namespaces/{namespace}/channels/{channelName}/sessions/{matchID}

ModelsMatchAddUserIntoSessionRequest body = ModelsMatchAddUserIntoSessionRequest.builder()
.userId("")
.partyId("")
.build();

wMatchmaking.addUserIntoSessionInChannel(AddUserIntoSessionInChannel.builder()
.namespace(namespace)
.channelName(channelName)
.matchID("")
.body(body)
.build());

Deleting a player from a session in a channel

DELETE /matchmaking/v1/admin/namespaces/{namespace}/channels/{channelName}/sessions/{matchID}/users/{userID}

wMatchmaking.deleteUserFromSessionInChannel(DeleteUserFromSessionInChannel.builder()
.namespace(namespace)
.channelName(channelName)
.matchID(matchId)
.userID(userId)
.build());

Retrieving a channel

GET /matchmaking/v1/admin/namespaces/{namespace}/channels/{channelName}

ModelsChannelV1 gResp = wMatchmaking.getSingleMatchmakingChannel(GetSingleMatchmakingChannel.builder()
.namespace(namespace)
.channelName(channelName)
.build());

Updating a channel

PATCH /matchmaking/v1/admin/namespaces/{namespace}/channels/{channelName}

ModelsUpdateChannelRequest body = ModelsUpdateChannelRequest.builder()
.description(description)
.build();

wMatchmaking.updateMatchmakingChannel(UpdateMatchmakingChannel.builder()
.namespace(namespace)
.channelName(channelName)
.body(body)
.build());

Platform Service

Before using the Platform service, you will need to set some permissions. Initialize the Store wrapper from the Platform service using the following code:

Store wStore = new Store(sdk);

Once completed, you can use the SDK to create, read, update, or delete stores.

Creating a store

POST /admin/namespaces/{namespace}/stores

StoreCreate createStore = StoreCreate.builder()
.title(storeTitle)
.description(storeDescription)
.defaultLanguage("en")
.defaultRegion("US")
.supportedLanguages(Arrays.asList(new String[] { "en", "id" }))
.supportedRegions(Arrays.asList(new String[] { "US", "ID" }))
.build();

StoreInfo cStore = wStore.createStore(CreateStore.builder()
.namespace(namespace)
.body(createStore)
.build());

Deleting a store

DELETE /admin/namespaces/{namespace}/stores/{storeId}

StoreInfo dStore = wStore.deleteStore(DeleteStore.builder()
.namespace(namespace)
.storeId(store_id)
.build());

Retrieving a store

GET /admin/namespaces/{namespace}/stores/{storeId}

StoreInfo gStore = wStore.getStore(GetStore.builder()
.namespace(namespace)
.storeId(store_id)
.build());

Updating a store

PUT /admin/namespaces/{namespace}/stores/{storeId}

StoreUpdate updateStore = StoreUpdate.builder()
.description(storeDescriptionUpdated)
.build();

StoreInfo cStoreUpdate = wStore.updateStore(UpdateStore.builder()
.namespace(namespace)
.storeId(storeId)
.body(updateStore)
.build());

Session Browser Service

Before using the Session Browser service, you will need to set some permissions. Initialize the Session wrapper from the Session Browser service using the following code:

Session wSBSession = new Session(sdk);

Once completed, you can use the SDK to create, read, update, or delete sessions.

Creating a session

POST /sessionbrowser/namespaces/{namespace}/gamesession

ModelsCreateSessionRequest createSession = ModelsCreateSessionRequest.builder()
.namespace(namespace)
.sessionType("p2p")
.gameVersion("0.3.0")
.username(usernameToTest)
.gameSessionSetting(ModelsGameSessionSetting.builder()
.mode("deathmatch")
.allowJoinInProgress(true)
.mapName("Java SDK Integration Test")
.maxPlayer(100)
.build())
.build();

ModelsSessionResponse cResp = wSBSession.createSession(
CreateSession.builder()
.namespace(namespace)
.body(createSession)
.build());

Deleting a session

DELETE /sessionbrowser/namespaces/{namespace}/gamesession/{sessionID}

ModelsSessionResponse dResp = wSBSession.deleteSession(
DeleteSession.builder()
.namespace(namespace)
.sessionID(session_id)
.build());

Retrieving a session

GET /sessionbrowser/namespaces/{namespace}/gamesession/{sessionID}

ModelsSessionResponse gResp = wSBSession.getSession(
GetSession.builder()
.namespace(namespace)
.sessionID(session_id)
.build());

Updating a session

PUT /sessionbrowser/namespaces/{namespace}/gamesession/{sessionID}

ModelsUpdateSessionRequest updateSession = ModelsUpdateSessionRequest.builder()
.gameMaxPlayer(150)
.build();

ModelsSessionResponse uResp = wSBSession.updateSession(
UpdateSession.builder()
.namespace(namespace)
.sessionID(sessionId)
.body(updateSession)
.build());

Social Service

Before using the Social service, you will need to set some permissions. Initialize the StatConfiguration wrapper from the Social service using the following code:

StatConfiguration wStatConfig = new StatConfiguration(sdk);

Once completed, you can use the SDK to create, read, update, or delete a player's** **statistics from your game client.

Creating a statistic

POST /social/v1/admin/namespaces/{namespace}/stats

StatCreate createStat = StatCreate.builder()
.name(name)
.description(description)
.statCode(statCode)
.setBy(setBy)
.minimum(minimum)
.maximum(maximum)
.defaultValue(default)
.incrementOnly(incrementOnly)
.setAsGlobal(setAsGlobal)
.tags(tags)
.build();

Deleting a statistic

DELETE /social/v1/admin/namespaces/{namespace}/stats/{statCode}

wStatConfig.deleteStat(DeleteStat.builder()
.namespace(namespace)
.statCode(stat_code)
.build());

Retrieving a statistic by stat code

GET /social/v1/admin/namespaces/{namespace}/stats/{statCode}

StatInfo gStat = wStatConfig.getStat(GetStat.builder()
.namespace(namespace)
.statCode(statCode)
.build());

Retrieving all statistics

GET /social/v1/admin/namespaces/{namespace}/stats

StatInfo gStat = wStatConfig.getStat(GetStat.builder()
.namespace(namespace)
.build());

Querying statistics by a keyword

GET /social/v1/admin/namespaces/{namespace}/stats/search

QueryStats queryStats = QueryStats.builder()
.namespace(namespace)
.keyword(keyword)
.build();

StatPagingSlicedResult result = wStatConfig.queryStats(queryStats);

Updating a statistic

PATCH /social/v1/admin/namespaces/{namespace}/stats/{statCode}

StatUpdate updateStat = StatUpdate.builder()
.description("Updated description.")
.build();

StatInfo uStat = wStatConfig.updateStat(
UpdateStat.builder()
.namespace(namespace)
.statCode(stat_code)
.body(updateStat)
.build());

UGC Service

Before using the UGC service, you will need to set some permissions. Initialize the AdminTag wrapper from the UGC service using the following code:

AdminTag wAdminTag = new AdminTag(sdk);

Once completed, you can use the SDK to create, read, update, or delete tags.

Creating a tag

POST /ugc/v1/admin/namespaces/{namespace}/tags

ModelsCreateTagRequest createTag = ModelsCreateTagRequest.builder()
.tag(tag_name)
.build();

ModelsCreateTagResponse cTag = wAdminTag.adminCreateTag(
AdminCreateTag.builder()
.namespace(namespace)
.body(createTag)
.build());

Deleting a tag

DELETE /ugc/v1/admin/namespaces/{namespace}/tags/{tagId}

wAdminTag.adminDeleteTag(AdminDeleteTag.builder()
.namespace(namespace)
.tagId(tag_id)
.build());

Retrieving a tag

GET /ugc/v1/admin/namespaces/{namespace}/tags

ModelsPaginatedGetTagResponse gTag = wAdminTag.adminGetTag(
AdminGetTag.builder()
.namespace(namespace)
.offset(0)
.limit(10)
.build());

Updating a tag

PUT /ugc/v1/admin/namespaces/{namespace}/tags/{tagId}

ModelsCreateTagRequest updateTag = ModelsCreateTagRequest.builder()
.tag(tag)
.build();

ModelsCreateTagResponse uTag = wAdminTag.adminUpdateTag(
AdminUpdateTag.builder()
.namespace(namespace)
.tagId(tagId)
.body(updateTag)
.build());