Firing arrows out of other items

Discussion in 'Plugin Development' started by 300cc2, Oct 14, 2012.

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

    300cc2

    Hello,

    I was working on my own kit pvp type plugin, I was working on my pro classes and I was going to add a archer pro class where instead of a bow a player could use item (idk what item, yet) and shoot arrows just like a bow. It seams pretty easy but for some reason I just can't figure it out.

    If someone could help me on this that would be great
     
  2. Offline

    Chrono7

    add a PlayerInteractEvent listener, and have it check if the player is holding a specific item. If so, use the code:

    Code:
    event.getPlayer().launchProjectile(Arrow.class);
    to have them fire the arrow. You could also add if statements to make sure they have an arrow before firing it, and remove the arrow after it is fired, etc.
     
  3. Offline

    300cc2

    Code:
            @EventHandler
                public void onPlayerInteract(PlayerInteractEvent event) {
                    Player player = event.getPlayer();
                      if ((player.hasPermission("pvpmc.class.archer+")));
                    int blockId = player.getItemInHand().getType().getId();
                    if(blockId == 259);
                    event.getPlayer().launchProjectile(Arrow.class);
    Something like that? Also, how would that "have the arrow before firing" work? Thanks.

    Uh, for some reason, when I right or left click using any block it shoots an arrow.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    Vandrake

    if(blockId == 259);
    this is your problem. You don't know how to make if statements
     
  5. Offline

    RainoBoy97

    if(event.getPlayer().getItemInHand().getType().equals(Material.FLINT_AND_STEEL)){

    Material.FLINT_AND_STEEL I dont have access to my workspace so the Material may be wrong! It should popup as a option i eclipse tho :p
     
  6. Offline

    bjsnow

    Heres What your Looking for :)
    Code:java
    1.  
    2. @EventHandler(priority=EventPriority.HIGH)
    3. public void onPlayerUse(PlayerInteractEvent event){
    4. Player p = event.getPlayer();
    5.  
    6. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    7. if(p.getItemInHand().getType() == Material.BLAZE_ROD){
    8. Arrow arrow = (Arrow) p.getWorld().spawn(event.getPlayer().getLocation().add(new Vector(0.0D, 1.0D, 0.0D)), Arrow.class);
    9. p.sendMessage(ChatColor.RED + "You Have Shot An Arrow Out Of a Blaze Rod Skillz? From Bj");
    10. }
    11. else if(p.getItemInHand().getType() == Material.BURNING_FURNACE){
    12. //Do whatever
    13. }
    14. }
    15. }
    16.  
    17. [/syntax=java]
    18. If Not Tell me :3(Might work xD Ill test soon)
    19. -Bj
     
  7. Offline

    300cc2

    It works somewhat, when I right click it fires an arrow but it just drops down right away and only goes in 1 direction.
     
  8. Offline

    Woobie

    I can give you the correct code once I get on my computer.
     
  9. Offline

    300cc2

    Thanks
     
Thread Status:
Not open for further replies.

Share This Page