Class PlayerDatabase


  • public class PlayerDatabase
    extends java.lang.Object
    Manages all Player database operations.
    • Constructor Detail

      • PlayerDatabase

        protected PlayerDatabase()
    • Method Detail

      • add

        public void add​(Player player,
                        DatabaseConsumer<Player> callback)
        Adds a player that does not currently exist in the database to the database.
        Parameters:
        player - player to add without a database reference id
        callback - callback to call once the operation has finished
        Throws:
        java.lang.IllegalArgumentException - if the player has a document id
      • update

        public void update​(Player player,
                           DatabaseConsumer<java.lang.Void> callback)
        Update a player that already exists in the database.
        Parameters:
        player - player to add with a database reference id
        callback - callback to call once the operation has finished
        Throws:
        java.lang.IllegalArgumentException - if the player does not have a document id
      • delete

        public void delete​(Player player,
                           DatabaseConsumer<java.lang.Void> callback)
        Delete a player from the database
        Parameters:
        player - player with a database reference id to delete
        callback - callback to call once the operation has finished
        Throws:
        java.lang.IllegalArgumentException - if the player does not have a document id
      • getPlayerByDeviceId

        public void getPlayerByDeviceId​(java.util.UUID deviceUUID,
                                        DatabaseConsumer<Player> callback)
        Retrieve a player by their device UUID from the database
        Parameters:
        deviceUUID - device UUID to lookup
        callback - callback to call once the operation has finished
      • getPlayerByDocumentId

        public void getPlayerByDocumentId​(java.lang.String documentId,
                                          DatabaseConsumer<Player> callback)
        Retrieve players by their document id
        Parameters:
        documentId - document id of the player
        callback - callback to call with the player
      • getPlayerByUsername

        public void getPlayerByUsername​(java.lang.String username,
                                        DatabaseConsumer<Player> callback)
        Retrieve a player by their username from the database
        Parameters:
        username - username to lookup
        callback - callback to call once the operation has finished
      • getAllPlayers

        public void getAllPlayers​(DatabaseConsumer<java.util.Set<Player>> callback)
        Retrieve all players from the database
        Parameters:
        callback - callback to call once the operation has finished
      • unfollow

        public void unfollow​(Player player,
                             Player playerToUnfollow,
                             DatabaseConsumer<java.lang.Void> callback)
        Unfollow the playerToUnfollow as the player
        Parameters:
        player - the player issuing the unfollow
        playerToUnfollow - the player losing a follower
        callback - callback
      • follow

        public void follow​(Player player,
                           Player playerToFollow,
                           DatabaseConsumer<java.lang.Void> callback)
        Follow the playerToFollow as the player
        Parameters:
        player - player issuing the follow request
        playerToFollow - player to follow
        callback - callback
      • getInstance

        public static PlayerDatabase getInstance()
        Retrieves the PlayerDatabase
        Returns:
        PlayerDatabase
      • mockInstance

        public static void mockInstance​(PlayerDatabase mockPlayerDB)
        Sets instance to a mocked PlayerDatabase for testing purposes.
        Parameters:
        mockPlayerDB - The mocked PlayerDatabase to use.