DatabaseAPI.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.gmail.nossr50.api;
  2. import com.gmail.nossr50.datatypes.player.PlayerProfile;
  3. import com.gmail.nossr50.mcMMO;
  4. import java.util.UUID;
  5. import org.bukkit.OfflinePlayer;
  6. import org.jetbrains.annotations.NotNull;
  7. public class DatabaseAPI {
  8. private DatabaseAPI() {
  9. }
  10. /**
  11. * Checks if a player exists in the mcMMO Database
  12. *
  13. * @param offlinePlayer target player
  14. * @return true if the player exists in the DB, false if they do not
  15. */
  16. public boolean doesPlayerExistInDB(@NotNull OfflinePlayer offlinePlayer) {
  17. PlayerProfile playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(offlinePlayer);
  18. return playerProfile.isLoaded();
  19. }
  20. /**
  21. * Checks if a player exists in the mcMMO Database
  22. *
  23. * @param uuid target player
  24. * @return true if the player exists in the DB, false if they do not
  25. */
  26. public boolean doesPlayerExistInDB(@NotNull UUID uuid) {
  27. PlayerProfile playerProfile = null;
  28. try {
  29. playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
  30. } catch (Exception e) {
  31. return false;
  32. }
  33. return playerProfile.isLoaded();
  34. }
  35. /**
  36. * Checks if a player exists in the mcMMO Database
  37. *
  38. * @param playerName target player
  39. * @return true if the player exists in the DB, false if they do not
  40. */
  41. public boolean doesPlayerExistInDB(@NotNull String playerName) {
  42. PlayerProfile playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
  43. return playerProfile.isLoaded();
  44. }
  45. }