Adhil Tn

Make me a /repair all plugin to repair all tools and armour in inventory

Kodari AI
KodariTue at 4:48 pm 1
RepairAll
RepairAll is a Minecraft plugin that adds a /repair all command, allowing players to instantly repair all tools and armor in their inventory. The plugin scans the player's inventory, identifies all repairable items (tools, weapons, and armor), and repairs them to full durability. It supports both the main inventory and armor slots, with configurable permission nodes and optional cost settings. The command provides clear feedback messages confirming successful repairs and handles edge cases like unrepairable items gracefully. The plugin is lightweight, efficient, and designed for easy integration into any server.

Added /repair all to repair damaged items throughout your inventory, including equipped armor and your offhand.

Permission: repairall.use (operators by default).

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 75
src/main/java/com/kodari/repairall/RepairAllPlugin.java
package com.kodari.repairall;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

public final class RepairAllPlugin extends JavaPlugin {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "Only players can use this command.");
            return true;
        }
        if (args.length != 1 || !args[0].equalsIgnoreCase("all")) {
            sender.sendMessage(ChatColor.RED + "Usage: /repair all");
            return true;
        }

        Player player = (Player) sender;
        int repaired = 0;
        ItemStack[] contents = player.getInventory().getContents();
        for (int slot = 0; slot < contents.length; slot++) {
            ItemStack item = contents[slot];
            if (item == null || item.getType().getMaxDurability() <= 0) {
                continue;
            }
            ItemMeta meta = item.getItemMeta();
            if (meta instanceof Damageable && ((Damageable) meta).hasDamage()) {
                ((Damageable) meta).setDamage(0);
                item.setItemMeta(meta);
                player.getInventory().setItem(slot, item);
                repaired++;
            }
        }
        player.sendMessage(ChatColor.GREEN + "Repaired " + repaired + " item(s).");
        return true;
    }
}