jssyro.

make a plugin that lets u do /randomdurability on a player and it gives all their items at random durability on 3 modes, low which is rando mbteween 10-45 medium 50-60 and high is 60-100 and each item is random and /durability amount 26.1.1 paper java 25

Kodari AI
KodariWed at 8:57 pm 2
RandomDurability
A Minecraft Paper plugin that randomly sets durability on all items in a player's inventory. The /randomdurability command applies to a target player with three modes: low (10-45%), medium (50-60%), and high (60-100%), with each item receiving an independent random value within the selected range. The /durability command sets a specific durability percentage (1-100) on all items of a target player. Built for Paper 1.26.1.1, Java 25, using the Paper API. Commands support console and in-game execution with proper permission checks and player validation.
  • /randomdurability <player> <low|medium|high> will assign each damageable item a random remaining-durability percentage.

  • /durability <amount> will set the held item’s remaining durability to a percentage from 0 to 100.

Created the plugin with:

  • /randomdurability <player> <low|medium|high> — randomizes each damageable inventory item independently.

  • /durability <0–100> — sets the held item’s remaining durability percentage.

Both commands default to operator-only access.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 156
src/main/java/com/kodari/randomdurability/RandomDurabilityPlugin.java
package com.kodari.randomdurability;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
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.PlayerInventory;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

public final class RandomDurabilityPlugin extends JavaPlugin {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("randomdurability")) {
            if (args.length != 2) {
                return false;
            }
            Player target = Bukkit.getPlayerExact(args[0]);
            if (target == null) {
                sender.sendMessage(ChatColor.RED + "That player is not online.");
                return true;
            }
            int min;
            int max;
            switch (args[1].toLowerCase(Locale.ROOT)) {
                case "low": min = 10; max = 45; break;
                case "medium": min = 50; max = 60; break;
                case "high": min = 60; max = 100; break;
                default:
                    sender.sendMessage(ChatColor.RED + "Mode must be low, medium, or high.");
                    return true;
            }
            PlayerInventory inventory = target.getInventory();
            int changed = 0;
            for (int slot = 0; slot < inventory.getSize(); slot++) {
                ItemStack item = inventory.getItem(slot);
                if (setDurability(item, ThreadLocalRandom.current().nextInt(min, max + 1))) {
                    inventory.setItem(slot, item);
                    changed++;
                }
            }
            sender.sendMessage(ChatColor.GREEN + "Randomized durability for " + changed + " item(s) belonging to " + target.getName() + ".");
            return true;
        }
        if (command.getName().equalsIgnoreCase("durability")) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Only players can use this command.");
                return true;
            }
            if (args.length != 1) {
                return false;
            }
            int percent;
            try {
                percent = Integer.parseInt(args[0]);
            } catch (NumberFormatException ex) {
                sender.sendMessage(ChatColor.RED + "Enter a whole number from 0 to 100.");
                return true;
            }
            if (percent < 0 || percent > 100) {
                sender.sendMessage(ChatColor.RED + "Enter a whole number from 0 to 100.");
                return true;
            }
            Player player = (Player) sender;
            ItemStack item = player.getInventory().getItemInMainHand();
            if (!setDurability(item, percent)) {
                player.sendMessage(ChatColor.RED + "Hold an item that has durability.");
                return true;
            }
            player.getInventory().setItemInMainHand(item);
            player.sendMessage(ChatColor.GREEN + "Set remaining durability to " + percent + "%. ");
            return true;
        }
        return false;
    }

    private boolean setDurability(ItemStack item, int remainingPercent) {
        if (item == null || item.getType().getMaxDurability() <= 0) {
            return false;
        }
        ItemMeta meta = item.getItemMeta();
        if (!(meta instanceof Damageable)) {
            return false;
        }
        int max = item.getType().getMaxDurability();
        ((Damageable) meta).setDamage((int) Math.round(max * (100 - remainingPercent) / 100.0));
        item.setItemMeta(meta);
        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        if (!command.getName().equalsIgnoreCase("randomdurability")) {
            return new ArrayList<>();
        }
        List<String> options;
        if (args.length == 1) {
            options = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
        } else if (args.length == 2) {
            options = Arrays.asList("low", "medium", "high");
        } else {
            return new ArrayList<>();
        }
        String prefix = args[args.length - 1].toLowerCase(Locale.ROOT);
        return options.stream().filter(option -> option.toLowerCase(Locale.ROOT).startsWith(prefix)).collect(Collectors.toList());
    }
}