mcMMO/src/main/java/com/gmail/nossr50/database/DatabaseManager.java

147 lines
4.6 KiB
Java
Raw Normal View History

2013-01-25 04:53:02 +01:00
package com.gmail.nossr50.database;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public interface DatabaseManager {
// One month in milliseconds
2020-07-13 20:39:03 +02:00
long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
// During convertUsers, how often to output a status
2020-07-13 20:39:03 +02:00
int progressInterval = 200;
/**
* Purge users with 0 power level from the database.
*/
2020-07-13 20:39:03 +02:00
void purgePowerlessUsers();
/**
* Purge users who haven't logged on in over a certain time frame from the database.
*/
2020-07-13 20:39:03 +02:00
void purgeOldUsers();
/**
* Remove a user from the database.
*
* @param playerName The name of the user to remove
* @param uuid player UUID, can be null
* @return true if the user was successfully removed, false otherwise
*/
2020-07-13 20:39:03 +02:00
boolean removeUser(String playerName, UUID uuid);
/**
* Removes any cache used for faster lookups
* Currently only used for SQL
* @param uuid target UUID to cleanup
*/
2020-07-13 20:39:03 +02:00
void cleanupUser(UUID uuid);
/**
* Save a user to the database.
*
* @param profile The profile of the player to save
* @return true if successful, false on failure
*/
2020-07-13 20:39:03 +02:00
boolean saveUser(PlayerProfile profile);
/**
* Retrieve leaderboard info.
*
2014-02-27 16:56:21 +01:00
* @param skill The skill to retrieve info on
* @param pageNumber Which page in the leaderboards to retrieve
* @param statsPerPage The number of stats per page
* @return the requested leaderboard information
*/
2020-07-13 20:39:03 +02:00
List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage);
/**
* Retrieve rank info into a HashMap from PrimarySkillType to the rank.
* <p>
* The special value <code>null</code> is used to represent the Power
* Level rank (the combination of all skill levels).
*
* @param playerName The name of the user to retrieve the rankings for
* @return the requested rank information
*/
2020-07-13 20:39:03 +02:00
Map<PrimarySkillType, Integer> readRank(String playerName);
/**
* Add a new user to the database.
*
* @param playerName The name of the player to be added to the database
* @param uuid The uuid of the player to be added to the database
*/
2020-07-13 20:39:03 +02:00
void newUser(String playerName, UUID uuid);
/**
* Load a player from the database.
*
* @deprecated replaced by {@link #loadPlayerProfile(String playerName, UUID uuid, boolean createNew)}
*
* @param playerName The name of the player to load from the database
* @param createNew Whether to create a new record if the player is not
* found
* @return The player's data, or an unloaded PlayerProfile if not found
* and createNew is false
*/
@Deprecated
2020-07-13 20:39:03 +02:00
PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
/**
* Load a player from the database.
*
* @param uuid The uuid of the player to load from the database
* @return The player's data, or an unloaded PlayerProfile if not found
*/
2020-07-13 20:39:03 +02:00
PlayerProfile loadPlayerProfile(UUID uuid);
/**
* Load a player from the database. Attempt to use uuid, fall back on playername
*
* @param playerName The name of the player to load from the database
* @param uuid The uuid of the player to load from the database
* @param createNew Whether to create a new record if the player is not
* found
* @return The player's data, or an unloaded PlayerProfile if not found
* and createNew is false
*/
2020-07-13 20:39:03 +02:00
PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean createNew);
/**
* Get all users currently stored in the database.
*
* @return list of playernames
*/
2020-07-13 20:39:03 +02:00
List<String> getStoredUsers();
/**
* Convert all users from this database to the provided database using
* {@link #saveUser(PlayerProfile)}.
*
2013-08-10 20:10:45 +02:00
* @param destination The DatabaseManager to save to
*/
2020-07-13 20:39:03 +02:00
void convertUsers(DatabaseManager destination);
2020-07-13 20:39:03 +02:00
boolean saveUserUUID(String userName, UUID uuid);
2020-07-13 20:39:03 +02:00
boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
/**
* Retrieve the type of database in use. Custom databases should return CUSTOM.
*
* @return The type of database
*/
2020-07-13 20:39:03 +02:00
DatabaseType getDatabaseType();
/**
* Called when the plugin disables
*/
2020-07-13 20:39:03 +02:00
void onDisable();
2013-01-16 01:03:13 +01:00
}