onProjectileHit Get Display Name

Discussion in 'Plugin Development' started by McStormify, Apr 4, 2013.

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

    McStormify

    I'm creating an exploding grenades plugin, but came across a problem.

    When the egg hits, I want to check if it's display name equals "grenade". How would I do this?

    This is my code.

    Code:java
    1.  
    2. public void onProjectileHit(ProjectileHitEvent event) {
    3. Entity entity = event.getEntity();
    4.  
    5. if (entity instanceof Egg) {
    6. Egg egg = (Egg) entity;
    7. Entity shooter = egg.getShooter();
    8.  
    9. if (shooter instanceof Player == false) {
    10. return;
    11. }
    12.  
    13. Player player = (Player) shooter;
    14. }
    15. }
    16.  


    Hugs to anyone who can solve my problem!
     
  2. Offline

    ZeusAllMighty11

    I don't think you can restore it back to an ItemStack, so when it's 'projected', it loses it's meta
     
  3. Offline

    McStormify

    Oh, darn. Then how would I go about doing this?
     
  4. Offline

    ZeusAllMighty11

    What are you trying to do? I did something similar by using projectileshootevent, projectilehitevent, etc.
     
  5. Offline

    McStormify

    I have a crafting recipe which creates an egg with the display name "Grenade". I want to check if the display name is "Grenade" in onProjectileHit and if it is, I want to create an explosion. :D
     
  6. Offline

    ZeusAllMighty11

  7. Offline

    McStormify

    I already tried that after reading another support thread here. It works perfectly if the user has more than one egg left, but if he has only one remaining, it doesn't work. :(
     
  8. Offline

    1SmallVille1

    McStormify
    What you could do is store the UUID of the item that they threw, then on the projectilehitevent check to see if the entity UUID is equal to that of the one they had in their hand
     
  9. Offline

    McStormify

    Good news! I solved this by storing metadata in onProjectileLaunch. :)

    EDIT:
    Didn't see your reply, but thanks anyway 1SmallVille1!
     
  10. Offline

    1SmallVille1

    McStormify
    Glad you figured it out! It's always a good feeling to get a plugin working :D
     
    McStormify likes this.
Thread Status:
Not open for further replies.

Share This Page