Package me.manossef.semihardcore
Class LifeChanges
java.lang.Object
me.manossef.semihardcore.LifeChanges
This is the class responsible for every change of any player's life count or death status, as well as for sending
messages not specific to the plugin's commands.
Every action related to players gaining or losing lives is done by this class. A lot of other utility methods meant to be used by add-ons are also contained in this class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLife
(org.bukkit.entity.Player player) Sets the specified player's life count to their current life count plus one life.void
addLifeUpToLimit
(org.bukkit.entity.Player player) Deprecated.void
addSacrificedPlayer
(UUID uuid) Adds a player's UUID to the set of UUIDs of players currently being sacrificed.Set<org.bukkit.entity.Player>
Returns a set of all players that currently have zero lives.int
getLives
(org.bukkit.entity.Player player) Returns the number of lives the specified player currently has.int
Returns a new random number of lives between the plugin's minimum starting lives (inclusive) and the maximum starting lives (inclusive).int
Returns the maximum number of lives a player can have at any time.Returns a map of all online players to their life counts.Returns a set containing the UUIDs of all players currently marked as being sacrificed.boolean
hasLives
(org.bukkit.entity.Player player) Returns whether the specified player has a life count.boolean
isDead
(org.bukkit.entity.Player player) Returns whether the specified player has zero lives.void
livesMessage
(org.bukkit.entity.Player player) Sends the message shown by the/lives
command to the specified player.void
livesMessageAfterBeingGenerous
(org.bukkit.entity.Player player, org.bukkit.entity.Player receiver) Sends the message shown to the donor of the/givelife
command to the specified player.void
livesMessageAfterDeath
(org.bukkit.entity.Player player) Sends the message shown to a player when they die to the specified player.void
livesMessageAfterGenerosity
(org.bukkit.entity.Player player, org.bukkit.entity.Player donor) Sends the message shown to the receiver of the/givelife
command to the specified player.void
livesMessageAfterLifesteal
(org.bukkit.entity.Player player, org.bukkit.entity.Player victim) Sends the message shown to a player when they steal a life to the specified player.void
removeSacrificedPlayer
(UUID uuid) Removes a player's UUID from the set of UUIDs of players currently being sacrificed, if it's currently contained in the set.boolean
respectLivesLimit
(org.bukkit.entity.Player player) Deprecated.It is no longer possible for a player to ever have a life count above the limit, therefore this method has no use.void
revivePlayer
(org.bukkit.entity.Player player) Revives the specified player, if they are dead.void
setDead
(org.bukkit.entity.Player player, boolean dead) Deprecated.The dead players list has been removed, therefore there wouldn't be a point in using this method anymore.void
setLives
(org.bukkit.entity.Player player, int lives) Sets the specified player's life count to the specified number.void
setLivesUpToLimit
(org.bukkit.entity.Player player, int lives) Deprecated.It is no longer possible to breach the life limit usingsetLives(Player, int)
, therefore this method has no use.void
setLivesZeroAndKill
(org.bukkit.entity.Player player) Sets the specified player's life count to zero and kills them.void
welcomeMessage
(org.bukkit.entity.Player player) Sends the welcome message to the specified player.
-
Constructor Details
-
LifeChanges
-
-
Method Details
-
getSacrificedPlayers
Returns a set containing the UUIDs of all players currently marked as being sacrificed. Note that this almost always returns an empty set, since the set is only used to temporarily store a player being sacrificed so the plugin can show them the correct message.- Returns:
- The set of players being sacrificed.
-
addSacrificedPlayer
Adds a player's UUID to the set of UUIDs of players currently being sacrificed.- Parameters:
uuid
- The player's UUID.
-
removeSacrificedPlayer
Removes a player's UUID from the set of UUIDs of players currently being sacrificed, if it's currently contained in the set.- Parameters:
uuid
- The player's UUID.
-
getLives
public int getLives(org.bukkit.entity.Player player) Returns the number of lives the specified player currently has.- Parameters:
player
- The player in question.- Returns:
- The player's life count.
-
hasLives
public boolean hasLives(org.bukkit.entity.Player player) Returns whether the specified player has a life count. Note that this will almost always return true, since a player only lacks a life count when they join the server for the first time, when the plugin's listeners immediately give a new life count to the player.- Parameters:
player
- The player in question.- Returns:
true
if the player has a life count,false
otherwise.
-
getOnlinePlayerLifeMap
Returns a map of all online players to their life counts. This can be used to save all players' life counts at a certain point in time. The map will not contain any player for whomhasLives(Player)
returns false.- Returns:
- A map of all players to their life counts.
-
isDead
public boolean isDead(org.bukkit.entity.Player player) Returns whether the specified player has zero lives.- Parameters:
player
- The player in question.- Returns:
true
if the player is dead,false
otherwise.
-
getDeadOnlinePlayers
Returns a set of all players that currently have zero lives.- Returns:
- A set of all dead players.
-
setLives
public void setLives(org.bukkit.entity.Player player, int lives) Sets the specified player's life count to the specified number. Note that this will obey the plugin's life limit, so it is not possible to set a player's life count to a number above the limit. If the life count after this method is run is different, aPlayerLifeChangeEvent
is called.- Parameters:
player
- The player in question.lives
- The new life count.- Throws:
IllegalArgumentException
- Iflives
is negative.
-
setLivesUpToLimit
@Deprecated(since="2.7.0") public void setLivesUpToLimit(org.bukkit.entity.Player player, int lives) Deprecated.It is no longer possible to breach the life limit usingsetLives(Player, int)
, therefore this method has no use.Sets the specified player's life count to the specified number, obeying the plugin's life limit. This is a convenience method that runssetLives(Player, int)
and thenrespectLivesLimit(Player)
.- Parameters:
player
- The player in question.lives
- The new life count.- Throws:
IllegalArgumentException
- Iflives
is negative.
-
setLivesZeroAndKill
public void setLivesZeroAndKill(org.bukkit.entity.Player player) Sets the specified player's life count to zero and kills them.- Parameters:
player
- The player in question.
-
setDead
Deprecated.The dead players list has been removed, therefore there wouldn't be a point in using this method anymore. UsingsetLives(org.bukkit.entity.Player, int)
with a life count of 0 is enough.Adds or removes the specified player from the dead players list, based on the value of thedead
argument.- Parameters:
player
- The player in question.dead
- Whether the player will be set to dead or alive.
-
addLife
public void addLife(org.bukkit.entity.Player player) Sets the specified player's life count to their current life count plus one life. Note that this will obey the plugin's life limit, so it is not possible to set a player's life count to a number above the limit. If the life count after this method is run is different, aPlayerLifeChangeEvent
is called.- Parameters:
player
- The player in question.
-
addLifeUpToLimit
Deprecated.It is no longer possible to breach the life limit usingaddLife(Player)
, therefore this method has no use.Sets the specified player's life count to their current life count plus one life, obeying the plugin's life limit. This is a convenience method that runsaddLife(Player)
and thenrespectLivesLimit(Player)
.- Parameters:
player
- The player in question.
-
getLivesForNewPlayer
public int getLivesForNewPlayer()Returns a new random number of lives between the plugin's minimum starting lives (inclusive) and the maximum starting lives (inclusive).- Returns:
- A new random life count.
-
revivePlayer
public void revivePlayer(org.bukkit.entity.Player player) Revives the specified player, if they are dead. Reviving includes the following steps:- The player's life count is set to 1.
- The player is teleported to their last spawn point, or the world spawn point if there was none.
- The player's health is set to their maximum health.
- The player's hunger and saturation values are set to 20.
- The player's game mode is set to survival.
- Parameters:
player
- The player in question.
-
getLivesLimit
public int getLivesLimit()Returns the maximum number of lives a player can have at any time.- Returns:
- The plugin's upper limit of lives.
-
respectLivesLimit
Deprecated.It is no longer possible for a player to ever have a life count above the limit, therefore this method has no use.Checks if the specified player's life count is above the life limit, and reduces it down to the life limit if it is.- Parameters:
player
- The player in question.- Returns:
true
if the player's life count was changed,false
otherwise.
-
livesMessage
public void livesMessage(org.bukkit.entity.Player player) Sends the message shown by the/lives
command to the specified player.- Parameters:
player
- The player in question.
-
livesMessageAfterGenerosity
public void livesMessageAfterGenerosity(org.bukkit.entity.Player player, org.bukkit.entity.Player donor) Sends the message shown to the receiver of the/givelife
command to the specified player.- Parameters:
player
- The player to be sent the message.donor
- The player to be shown as the donor.
-
livesMessageAfterBeingGenerous
public void livesMessageAfterBeingGenerous(org.bukkit.entity.Player player, org.bukkit.entity.Player receiver) Sends the message shown to the donor of the/givelife
command to the specified player.- Parameters:
player
- The player to be sent the message.receiver
- The player to be shown as the receiver.
-
livesMessageAfterDeath
public void livesMessageAfterDeath(org.bukkit.entity.Player player) Sends the message shown to a player when they die to the specified player.- Parameters:
player
- The player in question.
-
livesMessageAfterLifesteal
public void livesMessageAfterLifesteal(org.bukkit.entity.Player player, org.bukkit.entity.Player victim) Sends the message shown to a player when they steal a life to the specified player.- Parameters:
player
- The player to be sent the message.victim
- The player to be shown as the victim.
-
welcomeMessage
public void welcomeMessage(org.bukkit.entity.Player player) Sends the welcome message to the specified player.- Parameters:
player
- The player in question.
-
addLife(Player)
, therefore this method has no use.