how to launch an arrow?

Discussion in 'Plugin Development' started by vhbob, May 14, 2015.

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

    vhbob

    i have this code but whenever the arrow launches it only goes one way... please help
    Code:
    @EventHandler
        public void onUse(PlayerInteractEvent e) {
            ItemStack used = e.getItem();
            Player p = e.getPlayer();
            ItemMeta usedm = used.getItemMeta();
            String name = usedm.getDisplayName();
            if (name.equalsIgnoreCase(ChatColor.MAGIC + ":::" + ChatColor.RESET
                    + "" + ChatColor.GRAY + "Grappling hook" + ChatColor.RESET + ""
                    + ChatColor.MAGIC + ":::")) {
                if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    Arrow a = p.getWorld().spawn(
                            e.getPlayer().getLocation()
                                    .add(new Vector(0.0D, 1.0D, 0.0D)),
                                    Arrow.class);
                    a.setVelocity(a.getLocation().getDirection());
                }
            }
        }
     
  2. try p.launchProjectile(Arrow.class)
    And your code will throw many errors, because:
    • Not all items have ItemMeta
    • Not all ItemMetas have displaynames
     
  3. Offline

    vhbob

    @FisheyLP how would i get where the arrow landed
     
  4. ProjectileHitEvent

    But you need to add the arrows UUID or something to a List to see if it is really this arrow you want
     
Thread Status:
Not open for further replies.

Share This Page