Solved Remove Items from a Player's Inventory

Discussion in 'Plugin Development' started by kennylax12, Sep 13, 2012.

Thread Status:
Not open for further replies.
  1. I have been racking my brain at this for a while now and I just can't seem to think of a way to get this to work.

    Paste of the code: http://dev.bukkit.org/paste/6227/

    Code:
    setupEconomy();
    Material m = Material.matchMaterial(sign.getLine(1));
    Inventory inv = player.getInventory();
    String str = sign.getLine(2);
    int amount = Integer.parseInt(str.split(" ")[1]);
    //Check if player has a high enough balance
    if(economy.getBalance(player.getName()) < (plugin.getConfig().getDouble("vertexeco."+m.name()+".sell") * amount)){
    player.sendMessage(ChatColor.RED+"Error: You don't have enough money.");
    event.setCancelled(true);
    return;
    }
    ItemStack items = new ItemStack(m, amount);
    //inv.set ???
    economy.depositPlayer(event.getPlayer().getName(), plugin.getConfig().getDouble("vertexeco."+m.name()+".sell") * amount);
    player.sendMessage("You sold "+amount+" "+sign.getLine(1)+" for "+(plugin.getConfig().getDouble("vertexeco."+m.name()+".sell") * amount));
    Basically what I need to do is subtract the players current amount of the item minus the amount. Yes I know some of the code can be cleaned up and it is missing a few necessary checks, but still.

    If you guys need any more info about what I am trying to do then just ask and I will be happy to tell you!
     
  2. Code:
                    player.getInventory().removeItem(new ItemStack[] {
                            new ItemStack(Material.getMaterial(id), ammount) });
    
     
    angelofdev likes this.
  3. Many thanks. I solved the problem by using:
    Code:
    player.getInventory().removeItem(new ItemStack(Material.matchMaterial(sign.getLine(1)), amount));
    I am running into a new problem though. It removes the item from the players inventory, but the inventory does not update. As in you cannot see the decreasing blocks until the player clicks on the stack.
    Should I run this whole event in a thread to possibly solve this problem?
     
  4. Fixed. Using:
    Code:
    player.getInventory().updateInventory();
     
Thread Status:
Not open for further replies.

Share This Page