Class LifestealerUserManager

java.lang.Object
dev.chicoferreira.lifestealer.user.LifestealerUserManager

public class LifestealerUserManager extends Object
Manages the LifestealerUser instances and persistence of them.
  • Constructor Details

  • Method Details

    • loadUser

      @Nullable public @Nullable LifestealerUser loadUser(UUID uuid) throws Exception
      Loads a user from the database. This does not cache the user in memory. Thread-safety: Can be run asynchronously.
      Parameters:
      uuid - the uuid of the user to load
      Returns:
      the loaded user or null if the user is not saved in the database
      Throws:
      Exception - if an error occurs while loading the user
    • getOrLoadUser

      @NotNull public @NotNull LifestealerUser getOrLoadUser(UUID uuid) throws Exception
      Gets or loads a user from the database synchronously. If the user is not already loaded, it will be loaded from the database and cached in memory. If the user is not saved in the database, a new user will be created and cached in memory.

      Thread-safety: This method is thread-safe and you can call it from any thread.

      Parameters:
      uuid - the uuid of the user to get or load
      Returns:
      the user if it's already loaded, otherwise loads it from the database and puts it in memory
      Throws:
      Exception - if an error occurs while loading the user
    • getOnlineUser

      @NotNull public @NotNull LifestealerUser getOnlineUser(org.bukkit.entity.Player player)
      Gets the LifestealerUser of a player that is online. This method is guaranteed to return a user if the player is online because of LifestealerUserListener.onPreLogin(AsyncPlayerPreLoginEvent).
      Parameters:
      player - the player to get the user from
      Returns:
      the user of the player
    • getOnlineUser

      @Nullable public @Nullable LifestealerUser getOnlineUser(UUID uuid)
      Gets the LifestealerUser of a player that is online. This method is guaranteed to return a user if that UUID is from a player is that online because of LifestealerUserListener.onPreLogin(AsyncPlayerPreLoginEvent). This method is annotated with Nullable because the UUID might not be from a player that is online.
      Parameters:
      uuid - the uuid of the user to get
      Returns:
      the user of the player
    • isDefaultUser

      public boolean isDefaultUser(LifestealerUser user)
      Checks if a user hasn't changed from the default values.
      Parameters:
      user - the user to check
      Returns:
      true if the user is the default user, false otherwise
    • saveUserAsync

      public CompletableFuture<Void> saveUserAsync(LifestealerUser user)
      Saves a user to the database asynchronously. This method is thread-safe and can be called from any thread.
      Parameters:
      user - the user to save
      Returns:
      a CompletableFuture that will be completed when the user is saved
    • saveUserSync

      public void saveUserSync(LifestealerUser user) throws Exception
      Saves a user to the database synchronously. This method is thread-safe and can be called from any thread, but it will block the current thread.
      Parameters:
      user - the user to save
      Throws:
      Exception - if an error occurs while saving the user
    • getStartingHearts

      public int getStartingHearts()
      Gets the starting amount of hearts for new users.
      Returns:
      the starting amount of hearts for new users
    • setStartingHearts

      public void setStartingHearts(int startingHearts)
      Sets the starting amount of hearts for new users. Used when reloading the configuration.
      Parameters:
      startingHearts - the starting amount of hearts for new users