Check if arrow from itemstack is shot?

Discussion in 'Spigot Plugin Development' started by TheBlackFish, Jul 1, 2015.

  1. Herrorroo!!!
    So I am making a plugin that includes explosive arrows, how can I make only the arrows from my itemstack explode? I think it would have to do with the getCustomName() method?
    Code (Text):
    @EventHandler
            public void arrowEvent(ProjectileHitEvent event) {
                if(event.getEntity() instanceof Arrow) {
                    Arrow arrow = (Arrow)event.getEntity();
                    Entity shooter = (Entity) arrow.getShooter();
               
                    if(shooter instanceof Player && arrow.hasMetadata("arrowmeta")) {
                        ParticleEffect.SMOKE_LARGE.display(0, 2, 0, 100, 1000, arrow.getLocation(), 60);      
                        arrow.getLocation().getWorld().createExplosion(arrow.getLocation(), (float) 4.0);
                    }else
                        return;
                }
    Code (Text):
        ItemStack bowarrow = new ItemStack(Material.ARROW, 3);
            ItemMeta arrowmeta = bowarrow.getItemMeta();
            ArrayList<String> arrow = new ArrayList<String>();
            arrowmeta.setDisplayName(ChatColor.BOLD.toString() + ChatColor.RED + "TNT arrows");
            arrow.add(ChatColor.RED +  "Do some damage");
            arrowmeta.setLore(hub);
            bowarrow.setItemMeta(arrowmeta);
    Thanks!
     
  2. Still can't figure it out :(
     
  3. Right here you are checking if it has the string "arrowmeta" rather than the object, arrowmeta.
     
  4. Use the ProjectileLaunchEvent and make sure that the shooter has that item, then add the entity to an ArrayList. Use the ProjectileHitEvent and check if the entity is the one that you stored in the ArrayList.
     
  5. If a player shoots an arrow, check if they have used your fancy arrow and apply a metadata to the launched arrow. In the ProjectileHitEvent check whether the arrow has this metadata.
     
  6. How do you do the metadata, I'm not sure I'm doing this correctly.
     
  7. I don't think adding the entity to a array list is a good idea. Hash sets are way easier, and cause a lot less stress. Also yes, you are checking for a string arrowmeta not a object.
     
  8. I know about the string problem, I dont know how to check for an object
     
  9. Thanks! I'll look into that