package net.wayward_realms.waywardprofessions;

import net.wayward_realms.waywardlib.character.CharacterPlugin;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class BlockBreakListener implements Listener {

    private final WaywardProfessions plugin;

    public BlockBreakListener(WaywardProfessions plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        RegisteredServiceProvider<CharacterPlugin> characterPluginProvider = Bukkit.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
        if (characterPluginProvider != null) {
            CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
            net.wayward_realms.waywardlib.character.Character character = characterPlugin.getActiveCharacter(event.getPlayer());
            Material material = event.getBlock().getType();
            List<ItemStack> drops = new ArrayList<>();
            Random random = new Random();
            for (ItemStack drop : event.getBlock().getDrops()) {
                int miningEfficiency = plugin.getMiningEfficiency(character, event.getBlock().getType());
                int amount = (int) ((double) (random.nextInt(100) <= 30 ? (miningEfficiency > 10 ? random.nextInt(miningEfficiency) : random.nextInt(10)) : 25) * (4D / 100D) * (double) drop.getAmount());
                drops.add(new ItemStack(drop.getType(), amount));
            }
            event.setCancelled(true);
            event.getBlock().setType(Material.AIR);
            for (ItemStack drop : drops) {
                event.getBlock().getWorld().dropItem(event.getBlock().getLocation().add(0.5D, 0.5D, 0.5D), drop);
            }
            plugin.setMiningEfficiency(character, material, plugin.getMiningEfficiency(character, material) + (random.nextInt(100) <= 30 ? random.nextInt(3) : 0));
        }
    }
}

package net.wayward_realms.waywardprofessions;

import net.wayward_realms.waywardlib.character.CharacterPlugin;
import net.wayward_realms.waywardlib.professions.ToolType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class BlockBreakListener implements Listener {

    private final WaywardProfessions plugin;

    public BlockBreakListener(WaywardProfessions plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        RegisteredServiceProvider<CharacterPlugin> characterPluginProvider = Bukkit.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
        if (characterPluginProvider != null) {
            CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
            net.wayward_realms.waywardlib.character.Character character = characterPlugin.getActiveCharacter(event.getPlayer());
            Material material = event.getBlock().getType();
            List<ItemStack> drops = new ArrayList<>();
            Random random = new Random();
            for (ItemStack drop : event.getBlock().getDrops()) {
                int miningEfficiency = plugin.getMiningEfficiency(character, event.getBlock().getType());
                int amount = (int) ((double) (random.nextInt(100) <= 30 ? (miningEfficiency > 10 ? random.nextInt(miningEfficiency) : random.nextInt(10)) : 25) * (4D / 100D) * (double) drop.getAmount());
                drops.add(new ItemStack(drop.getType(), amount));
            }
            event.setCancelled(true);
            if (event.getPlayer().getItemInHand() != null) {
                if (ToolType.getToolType(event.getPlayer().getItemInHand().getType()) != null) {
                    ToolType toolType = ToolType.getToolType(event.getPlayer().getItemInHand().getType());
                    switch (toolType) {
                        case SWORD: event.getPlayer().getItemInHand().setDurability((short) (event.getPlayer().getItemInHand().getDurability() + 2)); break;
                        case PICKAXE:case AXE:case SPADE: event.getPlayer().getItemInHand().setDurability((short) (event.getPlayer().getItemInHand().getDurability() + 1)); break;
                    }
                }
            }
            event.getBlock().setType(Material.AIR);
            for (ItemStack drop : drops) {
                event.getBlock().getWorld().dropItem(event.getBlock().getLocation().add(0.5D, 0.5D, 0.5D), drop);
            }
            plugin.setMiningEfficiency(character, material, plugin.getMiningEfficiency(character, material) + (random.nextInt(100) <= 30 ? random.nextInt(3) : 0));
        }
    }
}

Decrease durability when breaking blocks