Interface IDatabase
The database stores the following information:
- The players name and
UUID
; - The team ids;
- The current progression of every advancement for every team;
- The unredeemed advancements.
The connection to the database should be opened in the constructor of the implementing class.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the unused team ids in the database.void
close()
Closes the connection to the database.default UUID
getPlayerByName
(@NotNull String name) Gets theUUID
of the player with the specified name.getPlayerName
(@NotNull UUID uuid) Gets the stored name for the specified player.getPlayersByName
(@NotNull String name) Gets a list of the players with the specified name (in the database).getTeamAdvancements
(int teamId) Gets the team advancements mapped with their respective progressions.int
Gets the team id of the provided player.default int
Gets the team id of the provided player.getTeamMembers
(int teamId) Gets the team members.getUnredeemed
(int teamId) Get the list of the unredeemed advancements of the provided team.boolean
isUnredeemed
(@NotNull AdvancementKey key, int teamId) Returns whether the provided advancement is unredeemed for the specified team.loadOrRegisterPlayer
(@NotNull UUID uuid, @NotNull String name) Loads the provided player or registers they if they are new.Loads the provided player from the database.void
movePlayer
(@NotNull UUID uuid, int newTeamId) Moves the provided player to the specified team.default void
movePlayer
(@NotNull Player player, int newTeamId) Moves the provided player to the specified team.movePlayerInNewTeam
(@NotNull UUID uuid) Moves a player in a new team and returns theTeamProgression
of the new team.default TeamProgression
movePlayerInNewTeam
(@NotNull Player player) Moves a player in a new team and returns theTeamProgression
of the new team.Opens or gets a connection to the database.void
setUnredeemed
(@NotNull AdvancementKey key, boolean giveRewards, int teamId) Sets the provided advancement unredeemed for the specified team.void
setUp()
Sets up the database, like creating the tables.void
unregisterPlayer
(@NotNull UUID uuid) Deletes the provided player from the database.default void
unregisterPlayer
(@NotNull Player player) Deletes the provided player from the database.void
unsetUnredeemed
(@NotNull AdvancementKey key, int teamId) Sets the provided advancement redeemed for the specified team if it is unredeemed.void
unsetUnredeemed
(@NotNull List<Map.Entry<AdvancementKey, Boolean>> keyList, int teamId) Sets the provided advancements redeemed for the specified team.void
updateAdvancement
(@NotNull AdvancementKey key, int teamId, @Range(from=0, to=Integer.MAX_VALUE) int progression) Updates the progression for the provided advancement and the specified team.void
updatePlayerName
(@NotNull UUID uuid, @NotNull String name) Updates the player name in the database.
-
Method Details
-
setUp
Sets up the database, like creating the tables.- Throws:
SQLException
- If an SQL exception occurs.
-
openConnection
Opens or gets a connection to the database.- Returns:
- The opened connection.
- Throws:
SQLException
- If an SQL exception occurs.
-
close
Closes the connection to the database.- Throws:
SQLException
- If an SQL exception occurs.
-
getTeamId
default int getTeamId(@NotNull @NotNull Player player) throws SQLException, UserNotRegisteredException Gets the team id of the provided player.- Parameters:
player
- The player.- Returns:
- The team id.
- Throws:
SQLException
- If an SQL exception occurs.UserNotRegisteredException
- If the provided player could not be found in the database.
-
getTeamId
Gets the team id of the provided player.- Parameters:
uuid
- The playerUUID
.- Returns:
- The team id.
- Throws:
SQLException
- If an SQL exception occurs.UserNotRegisteredException
- If the provided player could not be found in the database.
-
getTeamMembers
Gets the team members.- Parameters:
teamId
- The team id.- Returns:
- The team members.
- Throws:
SQLException
- If an SQL exception occurs.
-
getTeamAdvancements
Gets the team advancements mapped with their respective progressions.The resulting map can contain keys of not-existent advancements that might exist in the database.
- Parameters:
teamId
- The team id.- Returns:
- The team advancements mapped with their respective progressions.
- Throws:
SQLException
- If an SQL exception occurs.
-
loadOrRegisterPlayer
Map.Entry<TeamProgression,Boolean> loadOrRegisterPlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String name) throws SQLException Loads the provided player or registers they if they are new.- Parameters:
uuid
- The playerUUID
.name
- The player name.- Returns:
- A pair containing a (always new)
TeamProgression
with the player team information and whether the player has been registered (so it was not found in the database). - Throws:
SQLException
- If an SQL exception occurs.
-
loadUUID
TeamProgression loadUUID(@NotNull @NotNull UUID uuid) throws SQLException, UserNotRegisteredException Loads the provided player from the database. If the player is not registered anUserNotRegisteredException
is thrown.- Parameters:
uuid
- The playerUUID
.- Returns:
- The player team's
TeamProgression
. - Throws:
SQLException
- If an SQL exception occurs.UserNotRegisteredException
- If the provided player could not be found in the database.- See Also:
-
updateAdvancement
void updateAdvancement(@NotNull @NotNull AdvancementKey key, int teamId, @Range(from=0, to=Integer.MAX_VALUE) int progression) throws SQLException Updates the progression for the provided advancement and the specified team.- Parameters:
key
- The advancement key.teamId
- The team id.progression
- The new progression.- Throws:
SQLException
- If an SQL exception occurs.
-
getUnredeemed
Get the list of the unredeemed advancements of the provided team.- Parameters:
teamId
- The team id.- Returns:
- A list of pairs containing the key of the unredeemed advancement and whether to give rewards for it
(see
setUnredeemed(AdvancementKey, boolean, int)
). - Throws:
SQLException
- If an SQL exception occurs.
-
setUnredeemed
void setUnredeemed(@NotNull @NotNull AdvancementKey key, boolean giveRewards, int teamId) throws SQLException Sets the provided advancement unredeemed for the specified team.- Parameters:
key
- The advancement key.giveRewards
- Whether to give rewards on redeem.teamId
- The team id.- Throws:
SQLException
- If an SQL exception occurs.
-
isUnredeemed
Returns whether the provided advancement is unredeemed for the specified team.- Parameters:
key
- The advancement key.teamId
- The team id.- Returns:
- Whether the provided advancement is unredeemed for the specified team.
- Throws:
SQLException
- If an SQL exception occurs.
-
unsetUnredeemed
Sets the provided advancement redeemed for the specified team if it is unredeemed.- Parameters:
key
- The advancement key.teamId
- The team id.- Throws:
SQLException
- If an SQL exception occurs.
-
unsetUnredeemed
void unsetUnredeemed(@NotNull @NotNull List<Map.Entry<AdvancementKey, Boolean>> keyList, int teamId) throws SQLExceptionSets the provided advancements redeemed for the specified team.- Implementation Requirements:
- The default implementation ignores the boolean value in each pair of the list.
- Parameters:
keyList
- The list of advancements to set redeemed.teamId
- The team id.- Throws:
SQLException
- If an SQL exception occurs.
-
unregisterPlayer
Deletes the provided player from the database.- Parameters:
player
- The player to be unregistered.- Throws:
SQLException
- If an SQL exception occurs.
-
unregisterPlayer
Deletes the provided player from the database.- Parameters:
uuid
- TheUUID
of the player to be unregistered.- Throws:
SQLException
- If an SQL exception occurs.
-
movePlayer
Moves the provided player to the specified team.- Parameters:
player
- The player to be moved.newTeamId
- The team id.- Throws:
SQLException
- If an SQL exception occurs.
-
movePlayer
Moves the provided player to the specified team.- Parameters:
uuid
- TheUUID
of the player to be moved.newTeamId
- The team id.- Throws:
SQLException
- If an SQL exception occurs.
-
movePlayerInNewTeam
Moves a player in a new team and returns theTeamProgression
of the new team.- Parameters:
player
- The player to be moved apart from their team.- Returns:
- The
TeamProgression
of the new team. - Throws:
SQLException
- If an SQL exception occurs.
-
movePlayerInNewTeam
Moves a player in a new team and returns theTeamProgression
of the new team.- Parameters:
uuid
- TheUUID
of the player to be moved apart from their team.- Returns:
- The
TeamProgression
of the new team. - Throws:
SQLException
- If an SQL exception occurs.
-
getPlayerByName
default UUID getPlayerByName(@NotNull @NotNull String name) throws SQLException, UserNotRegisteredException Gets theUUID
of the player with the specified name.Since more than one player could have the same name in the database (for example, if the old owner changes name without updating it in the database and another player with that name joins the server), this method returns the
UUID
of the first player found with the specified name.- Parameters:
name
- The player name.- Returns:
- The
UUID
of the first player found with the provided name. - Throws:
SQLException
- If an SQL exception occurs.UserNotRegisteredException
- If the provided player name could not be found in the database.
-
getPlayersByName
Gets a list of the players with the specified name (in the database).Since more than one player could have the same name in the database (for example, if the old owner changes name without updating it in the database and another player with that name joins the server), this method could return a list with more than one
UUID
.- Parameters:
name
- The player name.- Returns:
- A list of the
UUID
s of the players with the specified name. - Throws:
SQLException
- If an SQL exception occurs.
-
getPlayerName
Gets the stored name for the specified player.- Parameters:
uuid
- The playerUUID
.- Returns:
- The stored name.
- Throws:
SQLException
- If an SQL exception occurs.UserNotRegisteredException
- If the provided player could not be found in the database.
-
updatePlayerName
void updatePlayerName(@NotNull @NotNull UUID uuid, @NotNull @NotNull String name) throws SQLException Updates the player name in the database.- Parameters:
uuid
- TheUUID
of the player to be updated.name
- The new player name.- Throws:
SQLException
- If an SQL exception occurs.
-
clearUpTeams
Clears the unused team ids in the database.- Throws:
SQLException
- If an SQL exception occurs.
-