1

Make me a folia supported plugin that allows me to adjust the chance to get an heavy core from an ominous vault in the config.yml. I can reload the plugin with /unstablemacechance reload. Must be optimized to the maximum.

Plugin Name:

Author: ActualBuca Plugin Description: Mace chance config

Kodari AI
KodariOct 11 at 2:53 pm 1
UnstableMaceChance
Folia-compatible Minecraft plugin that lets server admins configure the drop chance of a Heavy Core from an Ominous Vault. Features a config.yml with a customizable chance value and a /unstablemacechance reload command to apply changes without restarting. Optimized for maximum performance using minimal event listeners, cached configuration values, and thread-safe access patterns. The plugin intercepts the Ominous Vault loot generation event, applies the configured probability check, and conditionally adds the Heavy Core item to the loot table. Includes proper Folia region scheduling for safe item manipulation and a lightweight command handler with permission checks.
  • Use Maven with Paper API and declare Folia compatibility in plugin.yml.

  • Handle only the ominous vault reward loot table, replacing its heavy-core result with the configured roll.

  • Cache the chance for efficient event handling and expose /unstablemacechance reload.

Created the Maven plugin with Folia support. Configure heavy-core-chance from 0–100 in config.yml; /unstablemacechance reload applies changes without restarting.

1

make it so I can make it 0.1, 0.02 and etc too

Kodari AI
KodariOct 11 at 2:57 pm 1
  • Keep the chance as a double so fractional percentages like 0.1 and 0.02 work.

  • Clarify in the config that those values mean 0.1% and 0.02%; no Gradle files will be added.

Fractional percentages are supported: set heavy-core-chance: 0.1 for 0.1%, or heavy-core-chance: 0.02 for 0.02%. Updated the config comment to clarify this; the chance is already read and applied as a decimal value.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
4 123
src/main/java/com/actualbuca/unstablemacechance/UnstableMaceChancePlugin.java
package com.actualbuca.unstablemacechance;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.concurrent.ThreadLocalRandom;

public final class UnstableMaceChancePlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final double DEFAULT_CHANCE = 7.5;
    private static final String OMINOUS_VAULT_LOOT_TABLE = "minecraft:chests/trial_chambers/reward_ominous";
    private static final XMaterial HEAVY_CORE = XMaterial.matchXMaterial("HEAVY_CORE").orElse(null);

    private volatile double heavyCoreChance;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        reloadChance();
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("unstablemacechance").setExecutor(this);
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onLootGenerate(LootGenerateEvent event) {
        if (!OMINOUS_VAULT_LOOT_TABLE.equals(event.getLootTable().getKey().toString()) || HEAVY_CORE == null) {
            return;
        }

        event.getLoot().removeIf(item -> XMaterial.matchXMaterial(item.getType()) == HEAVY_CORE);
        double chance = heavyCoreChance;
        if (chance > 0.0 && ThreadLocalRandom.current().nextDouble(100.0) < chance) {
            ItemStack heavyCore = HEAVY_CORE.parseItem();
            if (heavyCore != null) {
                event.getLoot().add(heavyCore);
            }
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            reloadConfig();
            reloadChance();
            sender.sendMessage("Heavy core chance reloaded: " + heavyCoreChance + "%");
            return true;
        }

        sender.sendMessage("Usage: /unstablemacechance reload");
        return true;
    }

    private void reloadChance() {
        double configuredChance = getConfig().getDouble("heavy-core-chance", DEFAULT_CHANCE);
        if (!Double.isFinite(configuredChance) || configuredChance < 0.0 || configuredChance > 100.0) {
            getLogger().warning("heavy-core-chance must be between 0 and 100; using " + DEFAULT_CHANCE + ".");
            configuredChance = DEFAULT_CHANCE;
        }
        heavyCoreChance = configuredChance;
    }
}