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
|
@ -23,6 +23,7 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -206,7 +207,7 @@ public class CombatManager extends Manager {
|
|||
|
||||
SRPlayer player1 = pm.getPlayer(player.getUniqueId());
|
||||
if (player1 != null) {
|
||||
player1.setHealth(player.getHealth() - damage);
|
||||
player1.setHealth(player.getHealth() - damage, DamageCause.ENTITY_ATTACK);
|
||||
if (player1.getHealth() <= 0) {
|
||||
player.damage(player.getHealth());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package me.unurled.sacredrealms.sr.events.player;
|
||||
|
||||
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerKillEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final SRPlayer player;
|
||||
private final DamageCause cause;
|
||||
|
||||
public PlayerKillEvent(SRPlayer player, DamageCause cause) {
|
||||
super(false);
|
||||
this.player = player;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public SRPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public DamageCause getCause() {
|
||||
return cause;
|
||||
}
|
||||
}
|
|
@ -56,9 +56,9 @@ public class SRPlayerUtils {
|
|||
}
|
||||
|
||||
public static void updateActionBar(@NotNull Player p, @NotNull SRPlayer sr) {
|
||||
double maxHealth = sr.getAttribute(Attribute.HEALTH);
|
||||
double health = sr.getHealth();
|
||||
double mana = sr.getAttribute(Attribute.MANA);
|
||||
int maxHealth = (int) sr.getAttribute(Attribute.HEALTH);
|
||||
int health = (int) sr.getHealth();
|
||||
int mana = (int) sr.getAttribute(Attribute.MANA);
|
||||
|
||||
net.kyori.adventure.text.Component text =
|
||||
comp("<red>❤ " + health + "/" + maxHealth + " <blue>❈ " + mana);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue