Repairing items issue

Discussion in 'Plugin Development' started by SirQuantum, Sep 3, 2017.

Thread Status:
Not open for further replies.
  1. So I'm working on a little project where items will be repaired, so I've decided to use the following method which I know works, or worked atleast.

    Code:
    if(args[0].equalsIgnoreCase("hand")) {
                               
                                if(player.hasPermission("fix.hand")) {
                                   
                                    if(player.getItemInHand() instanceof Repairable) {
                                       
                                        player.getItemInHand().setDurability((short)0);
                                        player.sendMessage(Lang.getMessage("fix-hand-repaired"));
                                       
                                    }else {
                                        player.sendMessage(Lang.getMessage("fix-hand-unrepairable"));
                                    }
                                   
                                }else {
                                   
                                    player.sendMessage(Lang.getMessage("command-no-permission"));
                                   
                                }
                               
                            }else if(args[0].equalsIgnoreCase("all")) {
                               
                                if(player.hasPermission("fix.fixall")) {
                                   
                                    for(ItemStack item : player.getInventory().getContents()) {
                                        if(item instanceof Repairable) {
                                            item.setDurability((short)0);
                                        }
                                    }
                                   
                                    for(ItemStack armour : player.getInventory().getArmorContents()) {
                                        if(armour instanceof Repairable) {
                                            armour.setDurability((short)0);
                                        }
                                    }
                                   
                                    player.sendMessage(Lang.getMessage("fix-fixall-repaired"));
                                   
                                }else {
                                    player.sendMessage(Lang.getMessage("command-no-permission"));
                                }
    But when I try running it; the hand repair always shows that the item is unrepairable. Whilst when using the fix all it sends the message saying all items have been repaired but doesn't actually change the durability of any of the items
     
  2. Offline

    LRK

    I fixed the problem through check instead of instanceof if the maxdura is 0.
    I know thats not very good but it's a solution....

    Like this:
    Code:
    if (args[0].equalsIgnoreCase("hand")) {
    short maxDura = p.getItemInHand().getType().getMaxDurability();
    if (maxDura != 0) {
    p.getItemInHand().setDurability((short)0);
    p.sendMessage(Lang.getMessage("fix-hand-repaired"));
    } else {
    p.sendMessage(Lang.getMessage("fix-hand-unrepairable"));
    }
    }
    
    If this answer was your solution please mark the thread as Solved
     
  3. Forgot to mention, when I was testing this I decided to use a wooden shovel that was roughly 50% on it's remaining uses.
     
Thread Status:
Not open for further replies.

Share This Page