Solved Detect when player kills chickenjockey

Discussion in 'Plugin Development' started by i3ick, Sep 9, 2015.

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

    i3ick

    Hey I need to see when a chickenjockey was killed.

    For distinguishing between a witherskeleton and a skeleton i use this method

    Code:
    case SKELETON:
                    int skeletonType = ((CraftSkeleton) e.getEntity()).getHandle().getSkeletonType();
                    if(skeletonType == 0){
                        // Skeleton
                        pInfo.addPoints(award.getSkeleton());
                    }
                    else{
                        // Wither
                        pInfo.addPoints(award.getWitherskeleton());
                    }
                    playAwardSound(p);
                    break;

    However there is no .getZombieType();

    Do I need to do case CHICKEN and then get the rider?


    Thanks, i3ick
     
  2. Offline

    oceantheskatr

    I think you can check .getPassenger() of the chicken, which will return null or the zombie or something like that. Maybe give that a shot? I don't have eclipse on my laptop to check.
     
  3. Offline

    i3ick

    I've just tried this.
    Code:
    Entity someEntity = ((CraftChicken) e.getEntity()).getPassenger();
                    if( someEntity instanceof Zombie){
                        p.sendMessage("bububu");
                    }
    But when I wanted to test it I realized you can't actually damage the chicken while it's being ridden, only the zombie. So I would somehow need to detect if the zombie is the raider
     
  4. @i3ick
    Why are you making casts to craftbukkit classes? It's highly inefficient due to breaking on each update. Skeleton has a getSkeletonType() which returns an enum, and the cast to CraftChicken is even worse because Entity even has the getPassenger() method. Also, I don't know where you got that you can't damage the chicken while it's being ridden, it should be possible at any time.
     
  5. Offline

    i3ick

    @megamichiel Oh yeah, you're right about the casting. Fixed

    I did some further testing
    You are also right about being able to kill the chicken, but because of the zombies' hitbox it's incredibly unlikely that the player will kill the chicken before the zombie. Also killing one does't kill both.
     
  6. @i3ick
    You can check if a chicken is killed, but you can also check if the zombie is killed, and from then you can use Entity#getVehicle() and check if it's a chicken, and using Entity#remove() you can remove an entity.
     
  7. Offline

    i3ick

    @megamichiel Awesome! Exactly what I was looking for!

    Thanks mate :)
     
Thread Status:
Not open for further replies.

Share This Page