DatabaseManager.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.gmail.nossr50.database;
  2. import com.gmail.nossr50.api.exceptions.InvalidSkillException;
  3. import com.gmail.nossr50.config.Config;
  4. import com.gmail.nossr50.datatypes.database.DatabaseType;
  5. import com.gmail.nossr50.datatypes.database.PlayerStat;
  6. import com.gmail.nossr50.datatypes.player.PlayerData;
  7. import com.gmail.nossr50.datatypes.player.PlayerProfile;
  8. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  9. import com.neetgames.mcmmo.player.MMOPlayer;
  10. import org.bukkit.entity.Player;
  11. import org.jetbrains.annotations.NotNull;
  12. import org.jetbrains.annotations.Nullable;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.UUID;
  16. public interface DatabaseManager {
  17. // One month in milliseconds
  18. long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
  19. // During convertUsers, how often to output a status
  20. int progressInterval = 200;
  21. /**
  22. * Purge users with 0 power level from the database.
  23. */
  24. void purgePowerlessUsers();
  25. /**
  26. * Purge users who haven't logged on in over a certain time frame from the database.
  27. */
  28. void purgeOldUsers();
  29. /**
  30. * Remove a user from the database.
  31. *
  32. * @param playerName The name of the user to remove
  33. * @param uuid player UUID, can be null
  34. * @return true if the user was successfully removed, false otherwise
  35. */
  36. boolean removeUser(String playerName, UUID uuid);
  37. /**
  38. * Removes any cache used for faster lookups
  39. * Currently only used for SQL
  40. * @param uuid target UUID to cleanup
  41. */
  42. void cleanupUser(UUID uuid);
  43. /**
  44. * Save a user to the database.
  45. *
  46. * @param playerData target player data
  47. * @return true if successful, false on failure
  48. */
  49. boolean saveUser(@NotNull PlayerData playerData);
  50. /**
  51. * Retrieve leaderboard info.
  52. * Will never be null but it may be empty
  53. *
  54. * @param skill The skill to retrieve info on
  55. * @param pageNumber Which page in the leaderboards to retrieve
  56. * @param statsPerPage The number of stats per page
  57. * @return the requested leaderboard information
  58. */
  59. @NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException;
  60. /**
  61. * Retrieve rank info into a HashMap from PrimarySkillType to the rank.
  62. * <p>
  63. * The special value <code>null</code> is used to represent the Power
  64. * Level rank (the combination of all skill levels).
  65. *
  66. * @param playerName The name of the user to retrieve the rankings for
  67. * @return the requested rank information
  68. */
  69. Map<PrimarySkillType, Integer> readRank(String playerName);
  70. /**
  71. * Add a new user to the database.
  72. *
  73. * @param playerName The name of the player to be added to the database
  74. * @param uuid The uuid of the player to be added to the database
  75. */
  76. void newUser(String playerName, UUID uuid);
  77. @NotNull PlayerProfile newUser(@NotNull Player player);
  78. /**
  79. * Load a player from the database.
  80. *
  81. * @param playerName The name of the player to load from the database
  82. * @return The player's data, or an unloaded PlayerProfile if not found
  83. * and createNew is false
  84. */
  85. @NotNull PlayerProfile loadPlayerProfile(@NotNull String playerName);
  86. /**
  87. * Load a player from the database.
  88. *
  89. * @param uuid The uuid of the player to load from the database
  90. * @return The player's data, or an unloaded PlayerProfile if not found
  91. */
  92. @NotNull PlayerProfile loadPlayerProfile(@NotNull UUID uuid, @Nullable String playerName);
  93. /**
  94. * Get all users currently stored in the database.
  95. *
  96. * @return list of playernames
  97. */
  98. List<String> getStoredUsers();
  99. /**
  100. * Convert all users from this database to the provided database using
  101. * {@link #saveUser(PlayerProfile)}.
  102. *
  103. * @param destination The DatabaseManager to save to
  104. */
  105. void convertUsers(DatabaseManager destination);
  106. boolean saveUserUUID(String userName, UUID uuid);
  107. boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
  108. /**
  109. * Retrieve the type of database in use. Custom databases should return CUSTOM.
  110. *
  111. * @return The type of database
  112. */
  113. DatabaseType getDatabaseType();
  114. /**
  115. * Called when the plugin disables
  116. */
  117. void onDisable();
  118. }