Class PlayerDatabase
- java.lang.Object
-
- com.cmput301w23t09.qrhunter.player.PlayerDatabase
-
public class PlayerDatabase extends java.lang.ObjectManages all Player database operations.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPlayerDatabase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Player player, DatabaseConsumer<Player> callback)Adds a player that does not currently exist in the database to the database.voiddelete(Player player, DatabaseConsumer<java.lang.Void> callback)Delete a player from the databasevoidfollow(Player player, Player playerToFollow, DatabaseConsumer<java.lang.Void> callback)Follow the playerToFollow as the playervoidgetAllPlayers(DatabaseConsumer<java.util.Set<Player>> callback)Retrieve all players from the databasestatic PlayerDatabasegetInstance()Retrieves the PlayerDatabasevoidgetPlayerByDeviceId(java.util.UUID deviceUUID, DatabaseConsumer<Player> callback)Retrieve a player by their device UUID from the databasevoidgetPlayerByDocumentId(java.lang.String documentId, DatabaseConsumer<Player> callback)Retrieve players by their document idvoidgetPlayerByUsername(java.lang.String username, DatabaseConsumer<Player> callback)Retrieve a player by their username from the databasestatic voidmockInstance(PlayerDatabase mockPlayerDB)Sets instance to a mocked PlayerDatabase for testing purposes.voidunfollow(Player player, Player playerToUnfollow, DatabaseConsumer<java.lang.Void> callback)Unfollow the playerToUnfollow as the playervoidupdate(Player player, DatabaseConsumer<java.lang.Void> callback)Update a player that already exists in the database.
-
-
-
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 idcallback- 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 idcallback- 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 deletecallback- 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 lookupcallback- 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 playercallback- 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 lookupcallback- 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 unfollowplayerToUnfollow- the player losing a followercallback- 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 requestplayerToFollow- player to followcallback- 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.
-
-