Weird really weird

Discussion in 'Plugin Development' started by XgXXSnipz, Jun 24, 2014.

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


    Ok so Im making a plugin so that when a player drops an arrow it cancels it out and launches the arrow and then removes one, ok but it removes the arrows just fine until the last one, then it stops but theres another problem it doesnt even make sense to me, first here is the code
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void dropEvent(PlayerDropItemEvent event){
    4. Player p = event.getPlayer();
    7. if(event.getItemDrop().getItemStack().getType() == Material.ARROW) {
    8. event.setCancelled(true);
    9. p.launchProjectile(Arrow.class);
    10. event.getPlayer().getInventory().removeItem(new ItemStack(Material.ARROW, 1));
    11. p.updateInventory();
    12. }
    13. }
    14. }

    Anyways ok so I but the arrow in my inventory slot 1 and I click Q and it launches the arrow and removes one, but when I take all the arrows completely out of my inventory when I select slot 1 and I click Q even without the arrow in my inventory it launches an arrow, how is even possible
  2. Offline


    Why do you have a suppress warning?

    Also, for when checking if they have an arrow in their hand, try "event.getItemDrop().equals(Material.ARROW);"

    Also, don't update their inventory. You don't need it for this situation.

    Also, you made a Player variable and you don't even use it.

    Player p;
  3. You need to add in a statement that will check if the player actually has an arrow in the selected slot. Currently the script doesn't know weather there is or not.
  4. Offline


    XgXXSnipz at the time that the event is fired, the ItemStack is not in their inventory. Thus they won't have any arrows when they drop it, it won't be removed, and after the event the ItemStack will be added back due to the cancellation of the event.
Thread Status:
Not open for further replies.

Share This Page