Class SQLite
java.lang.Object
com.fren_gor.ultimateAdvancementAPI.database.impl.SQLite
- All Implemented Interfaces:
IDatabase
- Direct Known Subclasses:
InMemory
Class used to establish a connection to a SQLite database.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the unused team ids in the database.void
close()
Closes the connection to the database.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.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.movePlayerInNewTeam
(@NotNull UUID uuid) 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.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.fren_gor.ultimateAdvancementAPI.database.IDatabase
getPlayerByName, getTeamId, movePlayer, movePlayerInNewTeam, unregisterPlayer
-
Constructor Details
-
SQLite
Creates the SQLite connection. -
SQLite
Creates a SQLite in memory database connection.
-
-
Method Details
-
setUp
Sets up the database, like creating the tables.- Specified by:
setUp
in interfaceIDatabase
- Throws:
SQLException
- If an SQL exception occurs.
-
openConnection
Opens or gets a connection to the database.- Specified by:
openConnection
in interfaceIDatabase
- Returns:
- The opened connection.
- Throws:
SQLException
- If an SQL exception occurs.
-
close
Closes the connection to the database.- Specified by:
close
in interfaceIDatabase
- Throws:
SQLException
- If an SQL exception occurs.
-
getTeamId
Gets the team id of the provided player.- Specified by:
getTeamId
in interfaceIDatabase
- 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.- Specified by:
getTeamMembers
in interfaceIDatabase
- 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.
- Specified by:
getTeamAdvancements
in interfaceIDatabase
- Parameters:
teamId
- The team id.- Returns:
- The team advancements mapped with their respective progressions.
- Throws:
SQLException
- If an SQL exception occurs.
-
loadOrRegisterPlayer
public 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.- Specified by:
loadOrRegisterPlayer
in interfaceIDatabase
- 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
public 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.- Specified by:
loadUUID
in interfaceIDatabase
- 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
public 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.- Specified by:
updateAdvancement
in interfaceIDatabase
- 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.- Specified by:
getUnredeemed
in interfaceIDatabase
- 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
IDatabase.setUnredeemed(AdvancementKey, boolean, int)
). - Throws:
SQLException
- If an SQL exception occurs.
-
setUnredeemed
public void setUnredeemed(@NotNull @NotNull AdvancementKey key, boolean giveRewards, int teamId) throws SQLException Sets the provided advancement unredeemed for the specified team.- Specified by:
setUnredeemed
in interfaceIDatabase
- 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.- Specified by:
isUnredeemed
in interfaceIDatabase
- 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.- Specified by:
unsetUnredeemed
in interfaceIDatabase
- Parameters:
key
- The advancement key.teamId
- The team id.- Throws:
SQLException
- If an SQL exception occurs.
-
unsetUnredeemed
public void unsetUnredeemed(@NotNull @NotNull List<Map.Entry<AdvancementKey, Boolean>> keyList, int teamId) throws SQLExceptionSets the provided advancements redeemed for the specified team.- Specified by:
unsetUnredeemed
in interfaceIDatabase
- 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.- Specified by:
unregisterPlayer
in interfaceIDatabase
- 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.- Specified by:
movePlayer
in interfaceIDatabase
- 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.- Specified by:
movePlayerInNewTeam
in interfaceIDatabase
- 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.
-
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
.- Specified by:
getPlayersByName
in interfaceIDatabase
- 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
public String getPlayerName(@NotNull @NotNull UUID uuid) throws SQLException, UserNotRegisteredException Gets the stored name for the specified player.- Specified by:
getPlayerName
in interfaceIDatabase
- 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
public void updatePlayerName(@NotNull @NotNull UUID uuid, @NotNull @NotNull String name) throws SQLException Updates the player name in the database.- Specified by:
updatePlayerName
in interfaceIDatabase
- 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.- Specified by:
clearUpTeams
in interfaceIDatabase
- Throws:
SQLException
- If an SQL exception occurs.
-