Class LifestealerUserController

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

public class LifestealerUserController extends Object
Handling of the logic of the Lifestealer plugin.
  • Constructor Details Link icon

  • Method Details Link icon

    • setBanSettings Link icon

      public void setBanSettings(@NotNull @NotNull LifestealerUserController.BanSettings banSettings)
      Sets new ban settings. Used when the configuration is reloaded.

      Thread-safety: This method is not thread-safe.

      Parameters:
      banSettings - the new ban settings
    • setHearts Link icon

      public LifestealerUserController.ChangeHeartsResult setHearts(@NotNull @NotNull LifestealerUser user, @NotNull @NotNull LifestealerUserRules rules, int hearts)
      Sets the amount of hearts a player health has. This also saves the new amount in the database asynchronously. The amount of hearts is clamped between the minimum and maximum amount of hearts the player can have, based on their LifestealerUserRules.

      You need to call updatePlayerHearts(Player, LifestealerUser) to update the player health bar.

      Thread-safety: Requires a write lock on the user.

      Parameters:
      user - the user related to the player
      rules - the precomputed rules of the user
      hearts - the amount hearts to set
      Returns:
      a LifestealerUserController.ChangeHeartsResult with the previous and new amount of hearts
    • isOverflowing Link icon

      public boolean isOverflowing(@NotNull @NotNull LifestealerUser user, @NotNull @NotNull LifestealerUserRules rules, int additionalHearts)
      Checks if adding the additional hearts to the user will make them overflow over the maximum amount of hearts they can have in their LifestealerUserRules.

      Thread-safety: Requires a read lock on the user.

      Parameters:
      user - the user to check
      rules - the rules of the user
      additionalHearts - the amount of hearts to add
      Returns:
      if the user is overflowing with the additional hearts
    • getOverflowAmount Link icon

      public int getOverflowAmount(@NotNull @NotNull LifestealerUser user, @NotNull @NotNull LifestealerUserRules rules, int additionalHearts)
      Gets the amount of hearts that will overflow if the additional hearts are added to the user based on their LifestealerUserRules. If the additional hearts won't overflow, it will return 0.

      Thread-safety: Requires a read lock on the user.

      Parameters:
      user - the user to check
      rules - the rules of the user
      additionalHearts - the amount of hearts to add
      Returns:
      the amount of hearts that will overflow if the additional hearts are added
    • updatePlayerHearts Link icon

      public void updatePlayerHearts(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull LifestealerUser user)
      Updates the player health bar to match the amount of hearts the user has.

      Thread-safety: Requires a read lock on the user and should be called on the player's region thread.

      Parameters:
      player - the player to update the hearts
      user - the user related to the player
    • addHearts Link icon

      public LifestealerUserController.ChangeHeartsResult addHearts(@NotNull @NotNull LifestealerUser user, @NotNull @NotNull LifestealerUserRules rules, int hearts)
      Adds hearts to the player health bar and saves the new amount in the database asynchronously. If the new amount exceeds the maximum amount of hearts the player can have, it will be clamped to the maximum value.

      You need to call updatePlayerHearts(Player, LifestealerUser) to update the player health bar.

      Thread-safety: Requires a write lock on the user.

      Parameters:
      user - the user related to the player
      rules - the precomputed rules of the user
      hearts - the amount of hearts to add
      Returns:
      a LifestealerUserController.ChangeHeartsResult with the previous and new amount of hearts
    • removeHearts Link icon

      public LifestealerUserController.ChangeHeartsResult removeHearts(@NotNull @NotNull LifestealerUser user, LifestealerUserRules rules, int hearts)
      Removes hearts from the player health bar and saves the new amount in the database asynchronously. If the new amount is less than the minimum amount of hearts the player can have, it will be clamped the minimum value.

      You need to call updatePlayerHearts(Player, LifestealerUser) to update the player health bar.

      Thread-safety: Requires a write lock on the user.

      Parameters:
      user - the user related to the player
      hearts - the amount of hearts to remove
      Returns:
      a LifestealerUserController.ChangeHeartsResult with the previous and new amount of hearts
    • getBanSettings Link icon

      @NotNull public @NotNull LifestealerUserController.BanSettings getBanSettings()
      Gets the current ban settings.

      Thread-safety: This method is not thread-safe.

      Returns:
      the current ban settings
    • setUserBanned Link icon

      @NotNull public LifestealerUser.Ban setUserBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull LifestealerUser user)
      Bans a user for the default ban time depending on its LifestealerUserRules.

      You need to call postBanOperations(Player, LifestealerUser, LifestealerUser.Ban) to kick the player and executeBanCommands(Player, Duration) to execute the ban commands.

      Thread-safety: Requires a write lock on the user.

      Parameters:
      player - the player to ban
      user - the user related to the player
      Returns:
      the created ban information
    • setUserBanned Link icon

      @NotNull public LifestealerUser.Ban setUserBanned(@NotNull @NotNull LifestealerUser user, @NotNull @NotNull Duration banDuration)
      Bans a user for a specific duration.

      You need to call postBanOperations(Player, LifestealerUser, LifestealerUser.Ban) to kick the player and executeBanCommands(Player, Duration) to execute the ban commands.

      Thread-safety: Requires a write lock on the user.

    • postBanOperations Link icon

      public void postBanOperations(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull LifestealerUser user, @NotNull LifestealerUser.Ban ban)
      Executes the ban commands and kicks the player. You should call this method after calling setUserBanned(Player, LifestealerUser).

      Thread-safety: Thread-safe but requires to run on the player's region thread.

      Parameters:
      player - the player to ban
      user - the user related to the player
      ban - the ban information of the user
    • executeBanCommands Link icon

      public void executeBanCommands(@NotNull @NotNull org.bukkit.entity.Player player, Duration banDuration)
      Executes the ban commands. You should call this method after calling setUserBanned(Player, LifestealerUser).

      Thread-safety: Thread-safe but requires to run on the global thread.

      Parameters:
      player - the player to ban
      banDuration - the duration of the ban
    • getBan Link icon

      @Nullable public LifestealerUser.Ban getBan(@NotNull @NotNull LifestealerUser user)
      Gets the ban information of a user. If the user is not banned, it will return null.

      Thread-safety: Requires a write lock on the user (if the ban is expired, it will be removed from the user).

      Parameters:
      user - the user to get the ban information
      Returns:
      the ban information of the user, or null if the user is not banned
    • getBanIfNotExternalSettingEnabled Link icon

      @Nullable public LifestealerUser.Ban getBanIfNotExternalSettingEnabled(@NotNull @NotNull LifestealerUser user)
      Gets the ban information of a user if the external flag is disabled. If the user is not banned or the external flag is enabled, it will return null.

      Use this to test if the player is being kicked by the plugin.

      Thread-safety: Requires a write lock on the user (if the ban is expired, it will be removed from the user).

      Parameters:
      user - the user to check if they are banned
      Returns:
      the ban information of the user, or null if the user is not banned or the external flag is enabled
    • isBanned Link icon

      public boolean isBanned(@NotNull @NotNull LifestealerUser user)
      Checks if a user is banned.

      Thread-safety: Requires a write lock on the user (if the ban is expired, it will be removed from the user).

      Parameters:
      user - the user to check if they are banned
      Returns:
      true if the user is banned
    • unbanUser Link icon

      public void unbanUser(@NotNull @NotNull LifestealerUser user)
      Unbans a user.

      Thread-safety: Requires a write lock on the user.

      Parameters:
      user - the user to unban
    • computeUserRules Link icon

      public LifestealerUserRules computeUserRules(org.bukkit.entity.Player player, LifestealerUser user)
      Computes the LifestealerUserRules of a player based on their permissions and the user's rules modifier.

      Thread-safety: Requires a read lock on the user.

      Parameters:
      player - the player to compute the rules
      user - the user related to the player
      Returns:
      the computed LifestealerUserRules of the player
    • setRulesModifier Link icon

      public void setRulesModifier(LifestealerUser user, LifestealerUserRules modifierRules)
      Sets the rules modifier of a user.

      Thread-safety: Requires a write lock on the user.

      Parameters:
      user - the user to set the rules modifier
      modifierRules - the rules modifier to set