DatabaseManager.java 4.0 KB

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