2013-01-25 04:53:02 +01:00
|
|
|
package com.gmail.nossr50.database;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-06-04 18:14:43 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2014-08-01 20:17:15 +02:00
|
|
|
import java.util.UUID;
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-08-22 15:11:33 +02:00
|
|
|
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
2013-06-04 18:14:43 +02:00
|
|
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
2013-09-12 04:42:27 +02:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
public interface DatabaseManager {
|
2014-08-07 19:54:28 +02:00
|
|
|
// One month in seconds
|
|
|
|
public final long PURGE_TIME = 2630000L * Config.getInstance().getOldUsersCutoff();
|
2013-10-16 03:32:54 +02:00
|
|
|
// During convertUsers, how often to output a status
|
|
|
|
public final int progressInterval = 200;
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge users with 0 power level from the database.
|
|
|
|
*/
|
|
|
|
public void purgePowerlessUsers();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge users who haven't logged on in over a certain time frame from the database.
|
|
|
|
*/
|
|
|
|
public void purgeOldUsers();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a user from the database.
|
|
|
|
*
|
|
|
|
* @param playerName The name of the user to remove
|
|
|
|
* @return true if the user was successfully removed, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean removeUser(String playerName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a user to the database.
|
|
|
|
*
|
|
|
|
* @param profile The profile of the player to save
|
2013-10-06 00:18:10 +02:00
|
|
|
* @return true if successful, false on failure
|
2013-06-04 18:14:43 +02:00
|
|
|
*/
|
2013-10-06 00:18:10 +02:00
|
|
|
public boolean saveUser(PlayerProfile profile);
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve leaderboard info.
|
|
|
|
*
|
2014-02-27 16:56:21 +01:00
|
|
|
* @param skill The skill to retrieve info on
|
2013-06-04 18:14:43 +02:00
|
|
|
* @param pageNumber Which page in the leaderboards to retrieve
|
|
|
|
* @param statsPerPage The number of stats per page
|
|
|
|
* @return the requested leaderboard information
|
|
|
|
*/
|
2013-09-12 04:42:27 +02:00
|
|
|
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage);
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-12 04:42:27 +02:00
|
|
|
* Retrieve rank info into a HashMap from SkillType to the rank.
|
|
|
|
* <p>
|
|
|
|
* The special value <code>null</code> is used to represent the Power
|
|
|
|
* Level rank (the combination of all skill levels).
|
2013-06-04 18:14:43 +02:00
|
|
|
*
|
|
|
|
* @param playerName The name of the user to retrieve the rankings for
|
|
|
|
* @return the requested rank information
|
|
|
|
*/
|
2013-09-12 04:42:27 +02:00
|
|
|
public Map<SkillType, Integer> readRank(String playerName);
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new user to the database.
|
|
|
|
*
|
|
|
|
* @param playerName The name of the player to be added to the database
|
2014-08-07 19:54:28 +02:00
|
|
|
* @param uuid The uuid of the player to be added to the database
|
2013-06-04 18:14:43 +02:00
|
|
|
*/
|
2014-08-07 19:54:28 +02:00
|
|
|
public void newUser(String playerName, UUID uuid);
|
2013-06-04 18:14:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a player from the database.
|
|
|
|
*
|
2014-08-01 19:35:36 +02:00
|
|
|
* @deprecated replaced by {@link #loadPlayerProfile(String playerName, UUID uuid, boolean createNew)}
|
2014-08-01 20:17:15 +02:00
|
|
|
*
|
2013-06-04 18:14:43 +02:00
|
|
|
* @param playerName The name of the player to load from the database
|
2013-06-29 00:02:58 +02:00
|
|
|
* @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
|
2013-06-04 18:14:43 +02:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-06-29 00:02:58 +02:00
|
|
|
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
|
2013-06-04 18:14:43 +02:00
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-08-01 19:35:36 +02:00
|
|
|
public PlayerProfile loadPlayerProfile(UUID uuid);
|
2014-08-01 20:17:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean createNew);
|
|
|
|
|
2013-06-04 18:14:43 +02:00
|
|
|
/**
|
2013-06-29 00:02:58 +02:00
|
|
|
* Get all users currently stored in the database.
|
2013-06-04 18:14:43 +02:00
|
|
|
*
|
2013-06-29 00:02:58 +02:00
|
|
|
* @return list of playernames
|
2013-06-04 18:14:43 +02:00
|
|
|
*/
|
2013-06-29 00:02:58 +02:00
|
|
|
public 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
|
2013-06-29 00:02:58 +02:00
|
|
|
*/
|
|
|
|
public void convertUsers(DatabaseManager destination);
|
2013-08-22 15:11:33 +02:00
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
public boolean saveUserUUID(String userName, UUID uuid);
|
|
|
|
|
|
|
|
public boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
|
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the type of database in use. Custom databases should return CUSTOM.
|
|
|
|
*
|
|
|
|
* @return The type of database
|
|
|
|
*/
|
|
|
|
public DatabaseType getDatabaseType();
|
2014-08-01 19:35:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the plugin disables
|
|
|
|
*/
|
|
|
|
public void onDisable();
|
2013-01-16 01:03:13 +01:00
|
|
|
}
|