目录

PlayersClient

Interface Info

public interface PlayersClient

Provides APIs for obtaining player information.

Public Method Summary

Qualifier and Type

Method Name and Description

Task<Player>

getCurrentPlayer()

Obtains the Player object of the current player.

Task<Player>

getGamePlayer()

Obtains the Player object of the current player. In the returned Player object, only getDisplayName, getOpenId, and getUnionId have return values. For other methods, a null value is returned.

Task<Player>

getGamePlayer(boolean isRequirePlayerId)

Obtains the Player object of the current player, in which both playerId and openId are returned.

Task<String>

getCachePlayerId()

Obtains the locally cached player ID of the current player.

Task<Void>

savePlayerInfo(AppPlayerInfo appPlayerInfo)

Saves a player's role information in the current game.

CAUTION:

This API will be deprecated. To save a player's role information, use the savePlayerRole method.

Task<Void>

savePlayerRole(PlayerRoleInfo playerRoleInfo)

Saves a player's role information in the current game.

Public Methods

[h2]getCurrentPlayer

Method

public Task<Player> getCurrentPlayer()

Obtains the Player object of the current player.

Returns

Type

Description

Task<Player>

Player object.

You need to set two callback listeners in Task returned by the API. In Task, you can obtain success data from OnSuccessListener, and request failure data from OnFailureListener. In OnFailureListener, you need to check whether the exception object is an ApiException instance. If so, use its getStatusCode() method to obtain the result code and then process the exception accordingly.

[h2]getGamePlayer

Method

public Task<Player> getGamePlayer()

Obtains the Player object of the current player.

Returns

Type

Description

Task<Player>

Player object. In the returned Player object, only getDisplayName, getOpenId, and getUnionId have return values. For other methods, a null value is returned.

You need to set two callback listeners in Task returned by the API. In Task, you can obtain success data from OnSuccessListener, and request failure data from OnFailureListener. In OnFailureListener, you need to check whether the exception object is an ApiException instance. If so, use its getStatusCode() method to obtain the result code and then process the exception accordingly.

[h2]getGamePlayer

Method

public Task<Player> getGamePlayer(boolean isRequirePlayerId)

Obtains the Player object of the current player.

Parameters

Name

Description

isRequirePlayerId

Indicates whether to return playerId.

  • true: The returned Player object contains playerId.
  • false: The returned Player object does not contain playerId, and the method functions the same as getGamePlayer().
NOTE:

This parameter needs to be set only when playerId is replaced with openId.

Returns

Type

Description

Task<Player>

Player object.

  • If isRequirePlayerId is set to true, all parameters of the Player object have values.
  • If isRequirePlayerId is set to false, only getDisplayName, getOpenId, and getUnionId have return values. For other methods, a null value is returned.

You need to set two callback listeners in Task returned by the API. In Task, you can obtain success data from OnSuccessListener, and request failure data from OnFailureListener. In OnFailureListener, you need to check whether the exception object is an ApiException instance. If so, use its getStatusCode() method to obtain the result code and then process the exception accordingly.

[h2]getCachePlayerId

Method

public Task<String> getCachePlayerId()

Obtains the locally cached player ID of the current player.

Returns

Type

Description

Task<String>

Player ID.

[h2]savePlayerInfo

Method

public Task<Void> savePlayerInfo(AppPlayerInfo appPlayerInfo)

Stores the information about a player in a game, such as the level and region.

Parameters

Name

Description

AppPlayerInfo

Details about a player in a game.

Returns

Type

Description

Task<Void>

Save result.

You need to set two callback listeners in Task returned by the API. In Task, you can obtain success data from OnSuccessListener, and request failure data from OnFailureListener. In OnFailureListener, you need to check whether the exception object is an ApiException instance. If so, use its getStatusCode() method to obtain the result code and then process the exception accordingly.

[h2]savePlayerRole

Method

public Task<Void> savePlayerRole(PlayerRoleInfo playerRoleInfo)

Stores the role information of a player in a game, such as the game server and role name.

Parameters

Name

Description

playerRoleInfo

Role information of a player in a game. For details, please refer to PlayerRoleInfo.

Returns

Type

Description

Task<Void>

Save result.

You need to set two callback listeners in Task returned by the API. In Task, you can obtain success data from OnSuccessListener, and request failure data from OnFailureListener. In OnFailureListener, you need to check whether the exception object is an ApiException instance. If so, use its getStatusCode() method to obtain the result code and then process the exception accordingly.