Package me.manossef.semihardcore
Class LifeChanges
java.lang.Object
me.manossef.semihardcore.LifeChanges
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.
-
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
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
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) Checks if the specified player's life count is above the life limit, and reduces it down to the life limit if it is.void
revivePlayer
(org.bukkit.entity.Player player) Revives the specified player, if they are dead.void
setDead
(org.bukkit.entity.Player player, boolean dead) Adds or removes the specified player from the dead players list, based on the value of thedead
argument.void
setLives
(org.bukkit.entity.Player player, int lives) Sets the specified player's life count to the specified number.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.
-
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 not obey the plugin's life limit, and thus add-ons should always run therespectLivesLimit(Player)
method right after this one for the same player.- Parameters:
player
- the player in questionlives
- the new life count
-
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
public void setDead(org.bukkit.entity.Player player, boolean dead) Adds or removes the specified player from the dead players list, based on the value of thedead
argument.- Parameters:
player
- the player in questiondead
- 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 not obey the plugin's life limit, and thus add-ons should always run therespectLivesLimit(Player)
method right after this one for the same 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 removed from the dead players list.
- 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
public boolean respectLivesLimit(org.bukkit.entity.Player player) 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 messagedonor
- 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 messagereceiver
- 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.
-
welcomeMessage
public void welcomeMessage(org.bukkit.entity.Player player) Sends the welcome message to the specified player.- Parameters:
player
- the player in question.
-