Package wtf.choco.dragoneggdrop.dragon
Class DamageHistory
java.lang.Object
wtf.choco.dragoneggdrop.dragon.DamageHistory
public class DamageHistory extends Object
Represents a recordable history of damage for an entity.
- Author:
- Parker Hawke - Choco
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
DamageHistory.DamageEntry
Represents a mapping of an entity's UUID to an amount of damage. -
Method Summary
Modifier and Type Method Description void
clear()
Clear all total damage and damage history from this history.void
clearDamageHistory()
Clear all damage history from this history.static void
clearGlobalDamageHistory()
Clear all damage history from all entities.void
clearTotalDamage()
Reset all total damage from all entities in this history to zero.static DamageHistory
forEntity(UUID uuid)
Get theDamageHistory
associated with the given entity UUID.static DamageHistory
forEntity(org.bukkit.entity.Entity entity)
Get theDamageHistory
associated with the given entity.org.bukkit.entity.Entity
getEntity()
Get the Entity instance to which this damage history belongs.UUID
getEntityUUID()
Get the UUID of the entity to which this damage history belongs.DamageHistory.DamageEntry
getMostRecentDamage()
Get the most recent damage entry to this history.DamageHistory.DamageEntry
getMostRecentDamage(int offset)
Get the damage entry at the given offset (from most recent + offset).DamageHistory.DamageEntry
getTopDamager()
Get the entity that caused the most amount of damage to this entity.DamageHistory.DamageEntry
getTopDamager(int offset)
Get the top damager at the given offset (from most amount of damage + offset).DamageHistory.DamageEntry[]
getTopDamagers(int amount)
Get an array of entities that caused the most amount of damage to this entity in order of most amount of damage (first index) to least amount of damage (last index).double
getTotalDamageFrom(UUID uuid)
Get the total amount of damage caused by the specified entity's UUID.double
getTotalDamageFrom(org.bukkit.entity.Entity entity)
Get the total amount of damage caused by the specified entity.void
recordDamage(org.bukkit.entity.Entity source, double damage)
Record damage to this history.int
size()
Get the amount of history recorded by this record.int
uniqueDamagers()
Get the amount of unique damagers recorded by this history.
-
Method Details
-
getEntityUUID
Get the UUID of the entity to which this damage history belongs.- Returns:
- the belonging entity's UUID
- See Also:
getEntity()
-
getEntity
public org.bukkit.entity.Entity getEntity()Get the Entity instance to which this damage history belongs. Note that internally this makes a call toBukkit.getEntity(UUID)
ongetEntityUUID()
. Therefore this may return null! One should take caution in using the result of this method without first checking for nullability.- Returns:
- the belonging entity
- See Also:
getEntityUUID()
-
getTotalDamageFrom
public double getTotalDamageFrom(org.bukkit.entity.Entity entity)Get the total amount of damage caused by the specified entity.- Parameters:
entity
- the entity whose damage to retrieve- Returns:
- the amount of damage caused by the entity
-
getTotalDamageFrom
Get the total amount of damage caused by the specified entity's UUID.- Parameters:
uuid
- the UUID of the entity whose damage to retrieve- Returns:
- the amount of damage caused by the entity
-
getTopDamager
Get the entity that caused the most amount of damage to this entity. This comes paired with the amount of total damage done.- Returns:
- the top damager
-
getTopDamager
Get the top damager at the given offset (from most amount of damage + offset). For example, if fetching at the offset of 1, the second top damager will be retrieved. If offset of 2, third most. So on and so forth. Offset 0 would be equivalent togetTopDamager()
.- Parameters:
offset
- the damage entry offset. Must be <uniqueDamagers()
- Returns:
- the top damager at the given offset
-
getTopDamagers
Get an array of entities that caused the most amount of damage to this entity in order of most amount of damage (first index) to least amount of damage (last index). This comes paired with the amount of total damage done by each entity.If more damagers are queried than is available, the resulting array will fill as much as it can after which point null will be used to represent unrecorded or unavailable data.
- Parameters:
amount
- the amount of damagers to retrieve. Must be greater than 0- Returns:
- the top x damagers
-
recordDamage
public void recordDamage(org.bukkit.entity.Entity source, double damage)Record damage to this history.- Parameters:
source
- the damage's source entitydamage
- the damage to record
-
getMostRecentDamage
Get the most recent damage entry to this history.- Returns:
- the most recent damage. null if no damage has been recorded
-
getMostRecentDamage
Get the damage entry at the given offset (from most recent + offset). For example, if fetching at the offset of 1, the second most recent damage will be retrieved. If offset of 2, third most. So on and so forth. Offset 0 would be equivalent togetMostRecentDamage()
.- Parameters:
offset
- the damage entry offset. Must be <size()
- Returns:
- the damage entry at the given offset
-
size
public int size()Get the amount of history recorded by this record.- Returns:
- the history size
-
uniqueDamagers
public int uniqueDamagers()Get the amount of unique damagers recorded by this history.- Returns:
- the amount of unique damagers
-
clearTotalDamage
public void clearTotalDamage()Reset all total damage from all entities in this history to zero. -
clearDamageHistory
public void clearDamageHistory()Clear all damage history from this history. -
clear
public void clear()Clear all total damage and damage history from this history. This is equivalent to calling bothclearTotalDamage()
andclearDamageHistory()
. -
forEntity
Get theDamageHistory
associated with the given entity UUID. This method will never return null.- Parameters:
uuid
- the entity whose history to get- Returns:
- the entity's damage history
-
forEntity
Get theDamageHistory
associated with the given entity. This method will never return null.- Parameters:
entity
- the entity whose history to get- Returns:
- the entity's damage history
-
clearGlobalDamageHistory
public static void clearGlobalDamageHistory()Clear all damage history from all entities.
-