2013-01-24 22:53:02 -05:00
|
|
|
package com.gmail.nossr50.database;
|
2012-04-27 02:47:11 -07:00
|
|
|
|
2013-08-22 09:11:33 -04:00
|
|
|
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
2013-06-04 12:14:43 -04:00
|
|
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
2019-01-12 23:54:53 -08:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
2019-03-13 13:09:27 -07:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-06-04 12:14:43 -04:00
|
|
|
|
2019-01-14 22:11:58 -08:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2013-06-04 12:14:43 -04:00
|
|
|
public interface DatabaseManager {
|
2015-06-11 18:10:53 -04:00
|
|
|
// One month in milliseconds
|
2019-03-13 13:09:27 -07:00
|
|
|
public final long PURGE_TIME = 2630000000L * mcMMO.getDatabaseCleaningSettings().getOldUserCutoffMonths();
|
2013-10-15 18:32:54 -07:00
|
|
|
// During convertUsers, how often to output a status
|
|
|
|
public final int progressInterval = 200;
|
2013-06-04 12:14:43 -04: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-05 15:18:10 -07:00
|
|
|
* @return true if successful, false on failure
|
2013-06-04 12:14:43 -04:00
|
|
|
*/
|
2013-10-05 15:18:10 -07:00
|
|
|
public boolean saveUser(PlayerProfile profile);
|
2013-06-04 12:14:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve leaderboard info.
|
|
|
|
*
|
2014-02-27 10:56:21 -05:00
|
|
|
* @param skill The skill to retrieve info on
|
2013-06-04 12:14:43 -04:00
|
|
|
* @param pageNumber Which page in the leaderboards to retrieve
|
|
|
|
* @param statsPerPage The number of stats per page
|
|
|
|
* @return the requested leaderboard information
|
|
|
|
*/
|
2019-01-12 23:54:53 -08:00
|
|
|
public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage);
|
2013-06-04 12:14:43 -04:00
|
|
|
|
|
|
|
/**
|
2019-01-12 23:54:53 -08:00
|
|
|
* Retrieve rank info into a HashMap from PrimarySkillType to the rank.
|
2013-09-11 19:42:27 -07:00
|
|
|
* <p>
|
|
|
|
* The special value <code>null</code> is used to represent the Power
|
|
|
|
* Level rank (the combination of all skill levels).
|
2013-06-04 12:14:43 -04:00
|
|
|
*
|
|
|
|
* @param playerName The name of the user to retrieve the rankings for
|
|
|
|
* @return the requested rank information
|
|
|
|
*/
|
2019-01-12 23:54:53 -08:00
|
|
|
public Map<PrimarySkillType, Integer> readRank(String playerName);
|
2013-06-04 12:14:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new user to the database.
|
|
|
|
*
|
|
|
|
* @param playerName The name of the player to be added to the database
|
2014-08-07 13:54:28 -04:00
|
|
|
* @param uuid The uuid of the player to be added to the database
|
2013-06-04 12:14:43 -04:00
|
|
|
*/
|
2014-08-07 13:54:28 -04:00
|
|
|
public void newUser(String playerName, UUID uuid);
|
2013-06-04 12:14:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a player from the database.
|
|
|
|
*
|
2014-08-01 13:35:36 -04:00
|
|
|
* @deprecated replaced by {@link #loadPlayerProfile(String playerName, UUID uuid, boolean createNew)}
|
2014-08-01 20:17:15 +02:00
|
|
|
*
|
2013-06-04 12:14:43 -04:00
|
|
|
* @param playerName The name of the player to load from the database
|
2013-06-28 15:02:58 -07: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 12:14:43 -04:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-06-28 15:02:58 -07:00
|
|
|
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
|
2013-06-04 12:14:43 -04: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 13:35:36 -04: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 12:14:43 -04:00
|
|
|
/**
|
2013-06-28 15:02:58 -07:00
|
|
|
* Get all users currently stored in the database.
|
2013-06-04 12:14:43 -04:00
|
|
|
*
|
2013-06-28 15:02:58 -07:00
|
|
|
* @return list of playernames
|
2013-06-04 12:14:43 -04:00
|
|
|
*/
|
2013-06-28 15:02:58 -07: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-28 15:02:58 -07:00
|
|
|
*/
|
|
|
|
public void convertUsers(DatabaseManager destination);
|
2013-08-22 09:11:33 -04: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 09:11:33 -04:00
|
|
|
/**
|
|
|
|
* Retrieve the type of database in use. Custom databases should return CUSTOM.
|
|
|
|
*
|
|
|
|
* @return The type of database
|
|
|
|
*/
|
|
|
|
public DatabaseType getDatabaseType();
|
2014-08-01 13:35:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the plugin disables
|
|
|
|
*/
|
|
|
|
public void onDisable();
|
2013-01-15 19:03:13 -05:00
|
|
|
}
|