Take 3 items from player inventory

Discussion in 'Plugin Help/Development/Requests' started by davidp027, Nov 25, 2014.

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

    davidp027

    I need to take 3 items out of the player inventory but my code dosen't take it if the player has more than 3 in a stack in his inv(player has a stack of 15 items, it will say he dosen't have enough but if he has a stack of 3 items it'll work)
    Here's my code:
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. Player p = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_BLOCK){
    5. if (e.getClickedBlock().getState() instanceof Sign) {
    6. Sign s = (Sign) e.getClickedBlock().getState();
    7. if(s.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[Aura Node]")){
    8. int itemTrade = 30186;
    9. int reward = 2416;
    10. ItemStack is = new ItemStack(itemTrade, 3, (short)0);
    11. ItemStack rw = new ItemStack(reward, 1, (short) 0);
    12. if(p.getInventory().contains(is, 1)){
    13. p.getInventory().removeItem(is);
    14. p.getInventory().addItem(rw);
    15. p.updateInventory();
    16. p.sendMessage(ChatColor.GREEN + "You bought an Aura Node !");
    17. } else {
    18. p.sendMessage(ChatColor.RED + "You do not have enough tokens.");
    19. }
    20. }
    21. }
    22. }else{
    23. return;
    24. }
    25. }
     
  2. Offline

    Skionz

    davidp027 You shouldn't compare ItemStacks. If you compare ItemStacks both of them have to be exactly the same, same durability, amount, and material. I suggest comparing an ItemStack's type to a Material.
     
  3. Offline

    davidp027

    It's for some modded items so I can't use Material.something
     
  4. Offline

    eyamaz

    moved to Alternatives as this looks like a Cauldron project
     
Thread Status:
Not open for further replies.

Share This Page