Szabó Levente

A loot table where, if I put in the player_head item, it grants the effects.

Kodari AI
KodariSep 8 at 9:43 am 1
HeadEffectLoot
HeadEffectLoot is a Minecraft plugin that enhances loot tables by applying custom potion effects when specific items, particularly player heads, are obtained. When a player acquires a player_head item from any loot table, the plugin automatically grants configured status effects such as speed, strength, or regeneration. The plugin provides a simple configuration file where server administrators can define which items trigger effects and what effects to apply, including duration and amplifier levels. It seamlessly integrates with vanilla loot table mechanics, ensuring compatibility with existing dungeon, mob, and chest loot systems while adding a unique gameplay twist that rewards players with temporary buffs for finding special items.
  1. Create the Gradle/plugin metadata and a configurable PLAYER_HEAD loot entry.

  2. Load configured materials and potion effects into typed classes during startup.

  3. Listen for player item pickups and grant effects, optionally consuming one matching item.

Created the EffectLoot plugin.

  • Configures PLAYER_HEAD as loot that grants:

    • Speed for 15 seconds

    • Regeneration for 5 seconds

  • Effects trigger when a player picks up the item.

  • One item is consumed per activation.

  • Loot materials, effects, durations, amplifiers, and consumption behavior are configurable in config.yml.

  • Supports additional loot entries using the same structure.

Szabó Levente

need a commands

Kodari AI
KodariSep 8 at 9:47 am 1
  1. Add an /effectloot command with reload and give <player> <material> [amount].

  2. Register permissions and tab completion, then connect the command to the existing loot configuration and item handling.

Added the /effectloot command.

Commands:

Plain Text
/effectloot give <player> [material] [amount]
/effectloot reload

Examples:

Plain Text
/effectloot give Steve
/effectloot give Steve PLAYER_HEAD 3
/effectloot reload

Alias:

Plain Text
/eloot

Permissions:

Plain Text
effectloot.give
effectloot.reload

Both default to server operators.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
9 400
src/main/java/com/kodari/effectloot/EffectLootPlugin.java
package com.kodari.effectloot;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.java.JavaPlugin;

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

public final class EffectLootPlugin extends JavaPlugin {

    private LootPickupListener pickupListener;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        List<LootEntry> entries = loadLootEntries();
        pickupListener = new LootPickupListener(entries);
        getServer().getPluginManager().registerEvents(pickupListener, this);
        if (getCommand("effectloot") != null) {
            EffectLootCommand command = new EffectLootCommand(this);
            getCommand("effectloot").setExecutor(command);
            getCommand("effectloot").setTabCompleter(command);
        }
        getLogger().info("Loaded " + entries.size() + " effect loot entr" + (entries.size() == 1 ? "y" : "ies") + ".");
    }

    void reloadLootEntries() {
        reloadConfig();
        List<LootEntry> entries = loadLootEntries();
        pickupListener.setEntries(entries);
        getLogger().info("Loaded " + entries.size() + " effect loot entr" + (entries.size() == 1 ? "y" : "ies") + ".");
    }

    private List<LootEntry> loadLootEntries() {
        List<LootEntry> entries = new ArrayList<>();
        ConfigurationSection table = getConfig().getConfigurationSection("loot-table");
        if (table == null) {
            getLogger().warning("No loot-table section was configured.");
            return entries;
        }

        for (String entryKey : table.getKeys(false)) {
            ConfigurationSection entrySection = table.getConfigurationSection(entryKey);
            if (entrySection == null) {
                continue;
            }

            String materialName = entrySection.getString("material", "PLAYER_HEAD");
            XMaterial material = XMaterial.matchXMaterial(materialName).orElse(null);
            if (material == null) {
                getLogger().warning("Skipping loot entry '" + entryKey + "': unknown material " + materialName + ".");
                continue;
            }

            List<LootEffect> effects = loadEffects(entryKey, entrySection.getConfigurationSection("effects"));
            if (effects.isEmpty()) {
                getLogger().warning("Skipping loot entry '" + entryKey + "': no valid effects were configured.");
                continue;
            }

            entries.add(new LootEntry(material, entrySection.getBoolean("consume", true), effects));
        }

        return entries;
    }

    private List<LootEffect> loadEffects(String entryKey, ConfigurationSection effectsSection) {
        List<LootEffect> effects = new ArrayList<>();
        if (effectsSection == null) {
            return effects;
        }

        for (String effectKey : effectsSection.getKeys(false)) {
            ConfigurationSection effectSection = effectsSection.getConfigurationSection(effectKey);
            if (effectSection == null) {
                continue;
            }

            String typeName = effectSection.getString("type", "SPEED");
            XPotion type = XPotion.matchXPotion(typeName).orElse(null);
            if (type == null) {
                getLogger().warning("Skipping effect '" + effectKey + "' in loot entry '" + entryKey
                        + "': unknown potion effect " + typeName + ".");
                continue;
            }

            int durationSeconds = Math.max(1, effectSection.getInt("duration-seconds", 10));
            int amplifier = Math.max(0, effectSection.getInt("amplifier", 0));
            effects.add(new LootEffect(type, durationSeconds * 20, amplifier));
        }

        return effects;
    }
}