damage cause on health and player kill event
This commit is contained in:
parent
9bedf456db
commit
f387c63183
4 changed files with 53 additions and 14 deletions
|
@ -10,8 +10,10 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.item.Item;
|
||||
import me.unurled.sacredrealms.sr.events.player.PlayerKillEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
@ -31,22 +33,15 @@ public class SRPlayer {
|
|||
private double health = 100;
|
||||
@Expose private HashMap<Attribute, Double> attributes = new HashMap<>();
|
||||
private HashMap<Attribute, HashMap<ItemStack, Double>> itemAttributes = new HashMap<>();
|
||||
@Expose private List<PotionEffect> potionEffects;
|
||||
@Expose private Inventory inventory;
|
||||
@Expose private List<PotionEffect> potionEffects = new ArrayList<>();
|
||||
@Expose private Inventory inventory = null;
|
||||
|
||||
public SRPlayer(@NotNull UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
this.inventory = (player != null) ? player.getInventory() : null;
|
||||
this.itemAttributes = new HashMap<>();
|
||||
this.potionEffects = new ArrayList<>();
|
||||
}
|
||||
|
||||
public SRPlayer(@NotNull Player player) {
|
||||
this.uuid = player.getUniqueId();
|
||||
this.inventory = player.getInventory();
|
||||
this.itemAttributes = new HashMap<>();
|
||||
this.potionEffects = (List<PotionEffect>) player.getActivePotionEffects();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -236,7 +231,13 @@ public class SRPlayer {
|
|||
return health;
|
||||
}
|
||||
|
||||
public void setHealth(double health) {
|
||||
public void setHealth(double health, DamageCause cause) {
|
||||
if (health < 0) {
|
||||
health = 0;
|
||||
// kill player
|
||||
PlayerKillEvent event = new PlayerKillEvent(this, cause);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue