Doubling an arrow

Discussion in 'Plugin Development' started by Reflxction, Jul 13, 2018.

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

    Reflxction

    Hello. I'm currently making an abilities plugin and I have across making a double arrow ability, pretty much self explanatory that when you shoot an arrow it gets doubled. Now, I'm just confused on how would I go with that. I thought of something like spawning a new arrow with the same velocity but I didn't know how would I copy the exact arrow (direction, shooter, etc.) Any ideas? (no, not asking for spoonfeeding, just steps/suggestions on how would I get a clone)
     
  2. Offline

    jersogamer

    Maybe this part of my code could help you.
    Code:
    @EventHandler
       public void fireball(PlayerInteractEvent event) {
         Player player = event.getPlayer();
         Action eventAction = event.getAction();
        if (eventAction == Action.RIGHT_CLICK_AIR || eventAction == Action.RIGHT_CLICK_BLOCK ){
        if (player.getItemInHand().getType().equals(Material.BOW) && player.getItemInHand() != null){
          event.getPlayer().launchProjectile(Fireball.class).setVelocity(player.getLocation().getDirection().multiply(2));
    }
    }
    }
    
    I guess you can change the Fireball.class and write Arrow.class all the other part from "Setvelocity" is used to take the direction of the player and the part "multiply(2)" is the velocity of the arrow, I don't know how to set the same velocity than the first arrow.

    Pd. Sorry if my english is bad.
     
  3. Offline

    timtower Ninja on the waves Moderator

    @jersogamer Your code order is wrong, check for null, then for the type.
     
  4. Offline

    Edmond

    the method GetIteminhand() is deprecated . sorry, it doesn't work. there must be another way to do it.
     
  5. Offline

    sebcio98

    What about ProjectileLaunchEvent? Sounds useful.
    Also, https://jd.bukkit.org/org/bukkit/Wo...cation, org.bukkit.util.Vector, float, float)


    I'd recommend spawning the second arrow with a delay of 1 tick for a better visual effect. Easiest solution for that would be
    Code:
    Bukkit.getScheduler().runTaskLater(yourPlugin, new Runnable() {
      public void run() {
        //spawn arrow. (make sure you have the location saved in a final variable - one that won't change on its own)
      }}, 1L);
     
Thread Status:
Not open for further replies.

Share This Page