DatabaseManager.java 4.1 KB

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