Can remove things but not arrows from player's inv,

Discussion in 'Plugin Development' started by mine-care, Jun 17, 2014.

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


    Hello, i found out a realy weird thing... im trying to make a custom bow and so i am canceling the shoot event and interact and i do my own code... at a point i check if player has arrows and if he does i remove one each time he shoots..
    For some realy weird reason arrows arent removed from his inventory!
    The code:
    1. if(p.getInventory().contains(Material.ARROW)){
    2. p.getInventory().removeItem(
    3. new ItemStack[] { new ItemStack(Material.ARROW,
    4. 1) });
    5. p.updateInventory();
    6. Arrow pr = p.launchProjectile(Arrow.class);
    7. pr.setVelocity(p.getEyeLocation().getDirection().multiply(4.0));
    8. e.setCancelled(true);
    9. }

    But i tryed with this code to remove snowballs and it worked perfecty... But not with arrows...
  2. Offline


    Try this
    1. if(p.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1)){
    2. p.getInventory().removeItem(new ItemStack(Material.ARROW, 1));
    3. p.updateInventory();
    4. Arrow pr = p.launchProjectile(Arrow.class);
    5. pr.setVelocity(p.getEyeLocation().getDirection().multiply(4.0));
    6. e.setCancelled(true);
    7. }
  3. Offline


    AoH_Ruthless likes this.
  4. Offline


    Protophite ye ik, its a older project im upgrading but bfor i wanted to check what works after so long... 1.5.2 was its last build, so i am redoing it :p im using code from the old plugin...

    MrSnare ok will do in a sec :) thanks.

    MrSnare just tested, it doesnt work... doesnt even pas the contains at least part, even though player has 8 stacks and yes the inv. is a updated... :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
  5. Offline


    Then your problem is not in this code. Post the whole class
  6. Offline


    MrSnare ok but the class depends on 23 other classes :/

    MrSnare Sooo.. i wraped it up a bit, and it is wordking but the remove arrow thing is still not removing arrows... :/
    1. @EventHandler
    2. public void inter(final PlayerInteractEvent e){
    3. final Player p = e.getPlayer();
    4. if(e.getItem() == null){
    5. return;
    6. }
    7. if(e.getItem().getType().equals(Material.BOW)){
    8. if(p.getItemInHand().getItemMeta().getDisplayName().equals("§rHeavy Bow")){
    9. if(e.getAction().equals(Action.RIGHT_CLICK_AIR)|| e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    10. if(p.getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1)){
    11. p.getInventory().removeItem(new ItemStack(Material.ARROW, 1));
    12. p.updateInventory();
    13. Arrow pr = p.launchProjectile(Arrow.class);
    14. pr.setVelocity(p.getEyeLocation().getDirection().multiply(4.0));
    15. e.setCancelled(true);
    16. }
    17. }
    18. }
    19. }else{
    20. return;
    21. }

    there ^

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page