Removing Item's From Player's Inventory Not Working

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

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

    FuZioN720

    Hello, I am trying to make it so when a player buy a sword it remove money, and money is Nether Stars with a DisplayName, but when i buy the item it doesn't remove the Items/money from my inventory but i have a debug message and the debugmessage works please help.

    Buying The Item Code:
    Code:java
    1.  
    2. if (slot == 0){
    3. if (money(player) >= 25){
    4. rmoney(player, 25);
    5. player.closeInventory();
    6. ItemStack is = new ItemStack(Material.DIAMOND_SWORD, 1);
    7. is.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    8. player.getInventory().addItem(is);
    9. player.sendMessage("You Bought A Diamond Sword With Your Vote Coins");
    10. } else {
    11. player.sendMessage("You don't have enough to buy this item.");
    12. }
    13. }
    14.  


    remove money method:
    Code:java
    1.  
    2. public void rmoney(Player player, int xam) {
    3. int rem = 0;
    4. for (ItemStack i : player.getInventory().getContents())
    5. if ((i != null) &&
    6. (i.getType() == Material.NETHER_STAR) &&
    7. (rem < xam))
    8. if (i.getAmount() >= xam) {
    9. player.sendMessage("Works!");
    10. rem = xam;
    11. i.setAmount(i.getAmount() - xam);
    12. } else {
    13. rem = i.getAmount();
    14. i.setType(Material.AIR);
    15. }
    16. }
    17.  


    Bump

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

    FuZioN720

  3. Offline

    creepers84

    Remove one from the players inventory each time and then update the inventory using: player.updateInventory();
     
    tommycake50 likes this.
  4. Offline

    tommycake50

    No, but player.updateInventory(); is absolutely necessary and its stupidly deprecated but to avoid inventory glitches use it because bukkit has many inventory bugs that updateInventory fixes.
     
Thread Status:
Not open for further replies.

Share This Page