Item's not removing from player's inventory

Discussion in 'Plugin Development' started by FuZioN720, Aug 4, 2013.

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

    FuZioN720

    Hello, I'm trying to get it so when a player click on a sword in a custom inventory nether stars in the regular inventory gets remove but it doesn't work.

    Code:java
    1.  
    2. [B]@SuppressWarnings("deprecation")[/B]
    3. @EventHandler
    4. public void inventoryclick(InventoryClickEvent e) {
    5. if (e.getInventory().getName().equalsIgnoreCase(ChatColor.YELLOW + "" + ChatColor.BOLD +"Vote Rewards")){
    6. int slot = e.getSlot();
    7. HumanEntity player = e.getWhoClicked();
    8. e.setCancelled(true);
    9. if (slot == 0){
    10. if (money(player) >= 25){
    11. player.closeInventory();
    12. ItemStack is = new ItemStack(Material.DIAMOND_SWORD, 1);
    13. is.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    14. player.getInventory().addItem(is);
    15. ((CommandSender) player).sendMessage("You Bought A Diamond Sword With Your Vote Coins");
    16. ((Player) player).getInventory().removeItem(new ItemStack (Material.NETHER_STAR, 25));
    17. ((Player) player).updateInventory();
    18. } else {
    19. ((CommandSender) player).sendMessage("You don't have enough to buy this item.");
    20. }
    21. }
    22. }
    23.  
     
  2. Offline

    Compressions

    FuZioN720 You are removing an ItemStack that you just created. Try looping through the incentory's contents and setting the type of nether star to air.
     
  3. Offline

    FuZioN720

  4. Offline

    Compressions

    FuZioN720
    Code:
    for(ItemStack is : player.getinventory().getContents()) {
    if(is.getType.equals(Material.NETHER_STAR)) {
          is.setType(Material.AIR);
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page