Solved Repair code wont work

Discussion in 'Spigot Plugin Development' started by mshari, Jun 1, 2017.

  1. Hello, so i have this code to repair my inventory + armors but it didn't work.
    Code:
    Code (Text):

        public void repairAll(Player p) {
            ItemStack[] items = p.getInventory().getContents();
            ItemStack[] armor = p.getInventory().getArmorContents();
           
            for(ItemStack item : items){
                if(!(item == null)){
                    item.setDurability((short) 0);
                }
            }
            for(ItemStack item : armor){
                if(!(item == null)){
                    item.setDurability((short) 0);
                }
            }
        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
          if (cmd.getName().equalsIgnoreCase("fixall")){
            Player p = (Player)sender;
                repairAll(p);
                p.sendMessage(ChatColor.GREEN + "Items Repaired!");

          }
          return false;
        }
     
    how do i fix it?
     
  2. What was the issue?
     
  3. i just changed the armor itemstack thing
    fixed code:
    Code (Text):

    for(ItemStack arm : armor)
     
    that works for some reason
     
  4. Hmm. May just be an issue since you used that in the other for loop.