Help please

Discussion in 'Spigot Plugin Development' started by Known, May 1, 2017.

  1. @EventHandler
    public void onEntityHitEvent(ProjectileHitEvent e) {
    Projectile p = e.getEntity();
    if(!(p instanceof Arrow)) return;
    Arrow a = (Arrow) p;
    a.getWorld().createExplosion(a.getLocation(), 1.0F);


    How would I get this so that the arrow only explodes when it has a certain item meta?
     
  2. maybe this?
    ItemMeta arrowMeta = a.getItemMeta();
     
  3. The game can't distinguish between an arrow who's item had custom meta, and just a regular arrow afaik. When it's shot, the item is consumed and an entity is spawned
     
  4. so is there no way around this, or maybe i could check if the bow has a certain item meta?
     
  5. Use the .getShooter() method for projectiles/arrows. This will return the entity/player that shot the arrow.
     
  6. BananaPuncher714

    Supporter

    The best way would be to shove it in an Array list when it's first fired.
     
  7. Not really after the player that shot the arrow, i was just looking for if theres a way to check the item meta of the arrow or the bow that shot it
     
    • Winner Winner x 1
  8. Not to sure, as i haven't tried that method yet
     
  9. Check if arrow has itemmeta, then create explosion ;)
     
  10. when shot, apply a fixed metadata value to it using Entity#setMetaData or whatever the method is called.
    when it lands, check for the metadata value. if it's null, return, else, explode.
     
  11. BananaPuncher714

    Supporter

    What you can do is to create a hashmap where you put the arrow in as a key and have and itemmeta or a list of strings as an object, and you can use that as an arrow identification system. When you fire the arrow, put it in, and when it lands, you can get the data feom the hashmap and compare it to see if it has the right meta or something.
     
  12. how would i get when it it is shot?
     
  13. There's an event for that. Something like ProjectileShootEvent or ProjectileLaunchEvent or something similar

    Sent from my Nexus 5 using Tapatalk
     
  14. Sorry i dont understand your problem
     
  15. Then don't post?
     
  16. How would I apply the metadata?