Help with death messages

Discussion in 'Spigot Plugin Development' started by RiotShielder, May 26, 2015.

  1. RiotShielder


    Hey all!

    I'm working on changing the death messages for players, but I'm running into a few problems, hoping that someone can help me out.


    Here's what I'm currently stuck on
    1. When a player dies to a mob (ENTITY_ATTACK), the death message doesn't change.
      • I think this is due to me setting the killer variable to the type Player, however if I use the type Entity, I can't get use getItemInHand if the killer is a player.
    2. How can I tell if the killer entity is a spider jockey, wither skeleton, etc?
    3. With ENTITY_EXPLOSION, how do I check if a creeper is the damager?

    I appreciate any help! Also I apologize for all the questions, I've been searching around for a good while and can't find any answers.
  2. Watch your line 57, killer has to be a player. In PlayerDeathEvent, the getKiller() function will only work while a player killed him.

    If a player dies to a mob, cast PlayerDeathEvent to EntityDamageByEntityEvent, and use event.getDamager() to get the actual killer entity.

    Ps: If killer entity is an arrow, you know what to do.
  3. RiotShielder doing Java, am I dreaming?
    • Like Like x 2
    • Funny Funny x 1
  4. To check if the entity is a SpiderJockey:

    Code (Text):
    public boolean isSpiderJockey(Entity e){
            if(e instanceof Skeleton){
                if(e.getVehicle()!=null&&e.getVehicle() instanceof Spider)return true;
            if(e instanceof Spider){
                if(e.getPassenger()!=null&&e.getPassenger() instanceof Skeleton)return true;
            return false;
    • Like Like x 1
  5. RiotShielder


    I honestly have no idea what I'm doing right now.

    Current source:

    From what I understand, getKiller() won't return anything unless the player was killed by a player, so what do I use instead? I really don't have much experience with Java so I do apologize.
  6. @RiotShielder try getLastDamageCause(). It returns a EntityDamageEvent, which you can cast to EntityDamageByEntityEvent - if it is one, obviously - and get the damager from there.
  7. RiotShielder


    How would I cast it to that? And after casting it, how would I see what entity killed the player?
  8. Check if event.getKiller() != null (meaning killer is player)
  9. cast it with : 'instanceof EntityDamageByEntityEvent'.
  10. get the damager from the EntityDamageByEntityEvent. That should be the killer.
  11. Something like this?

    Code (Text):
        public void onPlayerDeath(PlayerDeathEvent event) {
            Player p = event.getEntity();
            if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
                EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) event

                if ((nEvent.getDamager() instanceof WhateverMob)) {
                    // Do something if the player was killed by WhateverMob that isn't a player
                if (((event.getEntity().getKiller() instanceof Player))
                        && (event.getEntity().getKiller() != null))
                    // Do something if the player was killed by another player
    • Like Like x 1
  12. You can always set the event message to null or a blank string, then broadcast a message.
  13. RiotShielder


    Thanks! This makes a lot more sense now.

    Here's my current code:
    #13 RiotShielder, May 29, 2015
    Last edited: May 29, 2015