Class MojangAPI

java.lang.Object
de.saibotk.jmaw.MojangAPI

public class MojangAPI extends Object
This Mojang API wrapper class contains all functions to interact with the Mojang API and will return its answers as instances of their respective model classes found in de.saibotk.jmaw.
Since:
1.0
  • Constructor Details

    • MojangAPI

      public MojangAPI()
      Constructor of the MojangAPI class, that will initialize all internal objects used to make requests and deserialize them.
  • Method Details

    • getAPIStatus

      public Optional<APIStatus> getAPIStatus() throws ApiResponseException
      This will query the Mojang API for a response about the status of its services.
      Returns:
      an instance of APIStatus or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getUUIDInfo

      public Optional<UUIDInfo> getUUIDInfo(String username) throws ApiResponseException
      This will query the Mojang API for a response about the current UUID of a player by its username.
      Parameters:
      username - the players username.
      Returns:
      an instance of UUIDInfo or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getUUIDInfo

      public Optional<UUIDInfo> getUUIDInfo(String username, long timestamp) throws ApiResponseException
      This will query the Mojang API for a response about the current UUID of a player by its username at a given timestamp.
      Parameters:
      username - the players username.
      timestamp - the timestamp.
      Returns:
      an instance of UUIDInfo or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getUsernameHistory

      public Optional<List<UsernameItem>> getUsernameHistory(String uuid) throws ApiResponseException
      This will query the Mojang API for a response about the username history for a player by his uuid.
      Parameters:
      uuid - the unique user id of the player.
      Returns:
      a List instance or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getUUIDsForUsernames

      public List<UUIDInfo> getUUIDsForUsernames(List<String> usernames) throws ApiResponseException
      This will query the Mojang API for a response about the username history for a player by his uuid. The list might be empty or the item count may differ from the input count, since the API ignores wrong uuids.
      Parameters:
      usernames - list of usernames to query.
      Returns:
      a List instance or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getPlayerProfile

      public Optional<PlayerProfile> getPlayerProfile(String uuid) throws ApiResponseException
      This will query the Mojang API for a response about the informations (eg. skin etc) of a specific player by his uuid. This response will be unsigned.
      Parameters:
      uuid - the unique user id of the player.
      Returns:
      an instance of PlayerProfile or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getPlayerProfile

      public Optional<PlayerProfile> getPlayerProfile(String uuid, boolean signed) throws ApiResponseException
      This will query the Mojang API for a response about the informations (eg. skin etc) of a specific player by his uuid. This response will contain a signature by the server, if requested.
      Parameters:
      uuid - the unique user id of the player.
      signed - if the request should be signed by the server.
      Returns:
      an instance of PlayerProfile or null if the servers response is empty or an error occurred while connecting.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • changeSkin

      public void changeSkin(String uuid, String token, String url, SkinMetadata.SkinModel model) throws ApiResponseException
      This will query the Mojang API for a change of the players skin, by sending a url to the skin file.
      Parameters:
      uuid - the unique user id of the player.
      token - the api token.
      url - the link to the new skin.
      model - the model type of the new skin.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • uploadSkin

      public void uploadSkin(String uuid, String token, File skin, SkinMetadata.SkinModel model) throws ApiResponseException
      This will query the Mojang API for a change of the players skin, by sending the skin file.
      Parameters:
      uuid - the unique user id of the player.
      token - the api token.
      skin - the new skin file.
      model - the model type of the new skin.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • deleteSkin

      public void deleteSkin(String uuid, String token) throws ApiResponseException
      This will query the Mojang API to delete the players skin.
      Parameters:
      uuid - the unique user id of the player.
      token - the api token.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getBlockedServers

      public Optional<List<String>> getBlockedServers() throws ApiResponseException
      This will query the Mojang API for a list of blocked servers.
      Returns:
      List list with all blocked servers hashes.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0
    • getSaleStatistics

      This will query the Mojang API for informations about the sales for specific products.
      Parameters:
      keys - the metric keys to request the statistics for.
      Returns:
      SaleStatistics instance.
      Throws:
      ApiResponseException - This will occur when the API returns an error code and the user input might be incorrect or there is an internal server error.
      Since:
      1.0