Custom damage event

Discussion in 'Plugin Development' started by HamOmlet, Jul 25, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    I currently have an explosion created at certain location, but I'd like to check if a player is killed by the explosion. I noticed a 'CUSTOM' enum for the damage event and was wondering if this would allow me to check if the player was killed by the generated explosion.
  2. Offline


    The reason something dies by an explosion should be DamageCause.BLOCK_EXPLOSION. You can get the DamageCause by getting the entity that the EntityDeathEvent is referring to, the entity's last damage event, and finally the cause of that damage:
    @EventHandler(priority = EventPriority.MONITOR)
    public void onEntityDeath(final EntityDeathEvent e) {
        Entity ent = e.getEntity();
        EntityDamageEvent ede = ent.getLastDamageCause();
        DamageCause dc = ede.getCause();
        if (ent instanceof Player && dc == DamageCause.BLOCK_EXPLOSION) {
            Player p = (Player)ent;
            p.sendMessage("You exploded.");
Thread Status:
Not open for further replies.

Share This Page