[SOLVED] Player.updateInventory() - Need help with tool damage

Discussion in 'Plugin Development' started by ACTruncale, Apr 3, 2011.

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

    ACTruncale

    I am trying to figure out how to make a mod that repairs tools randomly after breaking a block. I've got the damage of the tool to change, but the icon on the bottom tool bar is still showing damage as if the damage was taken. Now if you right click with tool in hand it will refresh the damage bar.

    Does anyone have any idea how to get this to work?

    I've tried to make a new ItemStack and using the setItem method. Also tried setItemInHand

    here is a piece of code:
    Code:
    public void onBlockBreak(BlockBreakEvent event) {
    
            Player player = event.getPlayer();
    
            Random rnd = new Random();
            int die = rnd.nextInt(99) + 1;
    
            for (Entry<String, ToolSet> entry : plugin.ToolList.entrySet()) {
                if (player.getItemInHand().getTypeId() == entry.getValue().ID) {
                    if ((entry.getValue().MOD + die) >= 100){
                        short damage = (short) (player.getItemInHand().getDurability() - 1);
                        PlayerInventory inv = player.getInventory();
                        
                        int slot =inv.getHeldItemSlot();
                        ItemStack temp = inv.getItem(slot);
                        temp.setDurability(damage);
                    }
                }
            }
    
        }
    Ok I found the method player.updateInventory();

    But it says it is depreciated. Is there another way to do it now?

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

    Drakia

    That's the only method, it's been deprecated since it was added because it's not an optimal solution.
     
  3. Offline

    Acrobot

    @ACTruncale
    AFAIK there is no other way to do it, it is depreciated because Bukkit developers don't want you to rely on this.

    EDIT: Ninja'd
     
Thread Status:
Not open for further replies.

Share This Page