Search in sources :

Example 1 with WarlordsDeathEvent

use of com.ebicep.warlords.events.WarlordsDeathEvent in project Warlords by ebicep.

the class WarlordsPlayer method die.

public void die(@Nullable WarlordsPlayer attacker) {
    dead = true;
    removeHorse();
    getLocation(this.deathLocation);
    showDeathAnimation();
    cooldownManager.clearCooldowns();
    if (attacker != null) {
        if (attacker != this) {
            hitBy.putAll(attacker.getHealedBy());
        }
        hitBy.remove(attacker);
    }
    this.addDeath();
    FlagHolder.dropFlagForPlayer(this);
    if (entity instanceof Player) {
        Player player = (Player) entity;
        player.setGameMode(GameMode.SPECTATOR);
        // removing yellow hearts
        ((EntityLiving) ((CraftPlayer) entity).getHandle()).setAbsorptionHearts(0);
        ItemStack item = ((CraftPlayer) entity).getInventory().getItem(0);
        // removing sg shiny weapon
        if (item != null) {
            item.removeEnchantment(Enchantment.OXYGEN);
        }
        // removing boner
        player.getInventory().remove(UndyingArmy.BONE);
    }
    Bukkit.getPluginManager().callEvent(new WarlordsDeathEvent(this, attacker));
    // giving out assists
    hitBy.forEach((assisted, value) -> {
        if (attacker == assisted || attacker == this) {
            assisted.sendMessage(ChatColor.GRAY + "You assisted in killing " + getColoredName());
        } else {
            if (attacker != null) {
                assisted.sendMessage(ChatColor.GRAY + "You assisted " + attacker.getColoredName() + ChatColor.GRAY + " in killing " + getColoredName());
            }
        }
        assisted.addAssist();
    });
    hitBy.clear();
    regenTimer = 0;
    heal();
}
Also used : WarlordsDeathEvent(com.ebicep.warlords.events.WarlordsDeathEvent) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)1 WarlordsDeathEvent (com.ebicep.warlords.events.WarlordsDeathEvent)1 EntityLiving (net.minecraft.server.v1_8_R3.EntityLiving)1 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1