Class LifestealerUserController
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
The settings for the ban feature.static final record
A result of a change for hearts of a player. -
Constructor Summary
ConstructorsConstructorDescriptionLifestealerUserController
(LifestealerUserManager userManager, LifestealerUserRulesController userRulesController, @NotNull LifestealerUserController.BanSettings banSettings) -
Method Summary
Modifier and TypeMethodDescriptionaddHearts
(@NotNull LifestealerUser user, @NotNull LifestealerUserRules rules, int hearts) Adds hearts to the player health bar and saves the new amount in the database asynchronously.computeUserRules
(org.bukkit.entity.Player player, LifestealerUser user) Computes theLifestealerUserRules
of a player based on their permissions and the user's rules modifier.void
executeBanCommands
(@NotNull org.bukkit.entity.Player player, Duration banDuration) Executes the ban commands.getBan
(@NotNull LifestealerUser user) Gets the ban information of a user.getBanIfNotExternalSettingEnabled
(@NotNull LifestealerUser user) Gets the ban information of a user if the external flag is disabled.Gets the current ban settings.int
getOverflowAmount
(@NotNull LifestealerUser user, @NotNull LifestealerUserRules rules, int additionalHearts) Gets the amount of hearts that will overflow if the additional hearts are added to the user based on theirLifestealerUserRules
.boolean
isBanned
(@NotNull LifestealerUser user) Checks if a user is banned.boolean
isOverflowing
(@NotNull LifestealerUser user, @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 theirLifestealerUserRules
.void
postBanOperations
(@NotNull org.bukkit.entity.Player player, @NotNull LifestealerUser user, LifestealerUser.Ban ban) Executes the ban commands and kicks the player.removeHearts
(@NotNull LifestealerUser user, LifestealerUserRules rules, int hearts) Removes hearts from the player health bar and saves the new amount in the database asynchronously.void
setBanSettings
(@NotNull LifestealerUserController.BanSettings banSettings) Sets new ban settings.setHearts
(@NotNull LifestealerUser user, @NotNull LifestealerUserRules rules, int hearts) Sets the amount of hearts a player health has.void
setRulesModifier
(LifestealerUser user, LifestealerUserRules modifierRules) Sets the rules modifier of a user.setUserBanned
(@NotNull LifestealerUser user, @NotNull Duration banDuration) Bans a user for a specific duration.setUserBanned
(@NotNull org.bukkit.entity.Player player, @NotNull LifestealerUser user) Bans a user for the default ban time depending on itsLifestealerUserRules
.void
unbanUser
(@NotNull LifestealerUser user) Unbans a user.void
updatePlayerHearts
(@NotNull org.bukkit.entity.Player player, @NotNull LifestealerUser user) Updates the player health bar to match the amount of hearts the user has.
-
Constructor Details
-
LifestealerUserController
public LifestealerUserController(LifestealerUserManager userManager, LifestealerUserRulesController userRulesController, @NotNull @NotNull LifestealerUserController.BanSettings banSettings)
-
-
Method Details
-
setBanSettings
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
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 theirLifestealerUserRules
.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 playerrules
- the precomputed rules of the userhearts
- the amount hearts to set- Returns:
- a
LifestealerUserController.ChangeHeartsResult
with the previous and new amount of hearts
-
isOverflowing
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 theirLifestealerUserRules
.Thread-safety: Requires a read lock on the user.
- Parameters:
user
- the user to checkrules
- the rules of the useradditionalHearts
- the amount of hearts to add- Returns:
- if the user is overflowing with the additional hearts
-
getOverflowAmount
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 theirLifestealerUserRules
. 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 checkrules
- the rules of the useradditionalHearts
- the amount of hearts to add- Returns:
- the amount of hearts that will overflow if the additional hearts are added
-
updatePlayerHearts
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 heartsuser
- the user related to the player
-
addHearts
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 playerrules
- the precomputed rules of the userhearts
- the amount of hearts to add- Returns:
- a
LifestealerUserController.ChangeHeartsResult
with the previous and new amount of hearts
-
removeHearts
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 playerhearts
- the amount of hearts to remove- Returns:
- a
LifestealerUserController.ChangeHeartsResult
with the previous and new amount of hearts
-
getBanSettings
Gets the current ban settings.Thread-safety: This method is not thread-safe.
- Returns:
- the current ban settings
-
setUserBanned
@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 itsLifestealerUserRules
.You need to call
postBanOperations(Player, LifestealerUser, LifestealerUser.Ban)
to kick the player andexecuteBanCommands(Player, Duration)
to execute the ban commands.Thread-safety: Requires a write lock on the user.
- Parameters:
player
- the player to banuser
- the user related to the player- Returns:
- the created ban information
-
setUserBanned
@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 andexecuteBanCommands(Player, Duration)
to execute the ban commands.Thread-safety: Requires a write lock on the user.
-
postBanOperations
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 callingsetUserBanned(Player, LifestealerUser)
.Thread-safety: Thread-safe but requires to run on the player's region thread.
- Parameters:
player
- the player to banuser
- the user related to the playerban
- the ban information of the user
-
executeBanCommands
public void executeBanCommands(@NotNull @NotNull org.bukkit.entity.Player player, Duration banDuration) Executes the ban commands. You should call this method after callingsetUserBanned(Player, LifestealerUser)
.Thread-safety: Thread-safe but requires to run on the global thread.
- Parameters:
player
- the player to banbanDuration
- the duration of the ban
-
getBan
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
@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
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
Unbans a user.Thread-safety: Requires a write lock on the user.
- Parameters:
user
- the user to unban
-
computeUserRules
Computes theLifestealerUserRules
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 rulesuser
- the user related to the player- Returns:
- the computed
LifestealerUserRules
of the player
-
setRulesModifier
Sets the rules modifier of a user.Thread-safety: Requires a write lock on the user.
- Parameters:
user
- the user to set the rules modifiermodifierRules
- the rules modifier to set
-