Radin mT

make it so you can only get ominous keys and trial keys from trial spawners (depends on the spawner type, ominous gives ominous key only, normal gives trial key only) Paper 1.21.11

Kodari AI
KodariNov 1 at 11:16 pm 1
TrialKeySpawnerLoot
Plugin that modifies Trial Spawner loot drops on Paper 1.21.11. When a Trial Spawner is activated and drops loot, it only drops Ominous Trial Keys from ominous variants and regular Trial Keys from normal variants. The plugin hooks into the spawner's loot generation event, filters out all other items, and ensures the correct key type is granted based on the spawner's ominous state. Supports both trial and ominous trial spawner blocks, with configurable messages and full compatibility with vanilla mechanics.
  1. Create a Paper plugin for Minecraft 1.21.11.

  2. Enforce that normal trial spawners grant only trial keys and ominous spawners grant only ominous keys.

Created the Paper 1.21.11 plugin: normal trial spawners keep only trial keys, ominous spawners keep only ominous trial keys, and other loot-table sources cannot grant either key.

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

import org.bukkit.block.BlockState;
import org.bukkit.block.TrialSpawner;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDispenseLootEvent;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

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

public final class TrialKeySourcePlugin extends JavaPlugin implements Listener {
    private static final String TRIAL_KEY = "trial_key";
    private static final String OMINOUS_TRIAL_KEY = "ominous_trial_key";

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onBlockDispenseLoot(BlockDispenseLootEvent event) {
        BlockState state = event.getBlock().getState();
        boolean isTrialSpawner = state instanceof TrialSpawner;
        boolean isOminous = isTrialSpawner && ((TrialSpawner) state).isOminous();
        List<ItemStack> allowedLoot = new ArrayList<>();

        for (ItemStack item : event.getDispensedLoot()) {
            String itemKey = item.getType().getKey().getKey();
            if (TRIAL_KEY.equals(itemKey) && (!isTrialSpawner || isOminous)) {
                continue;
            }
            if (OMINOUS_TRIAL_KEY.equals(itemKey) && (!isTrialSpawner || !isOminous)) {
                continue;
            }
            allowedLoot.add(item);
        }

        event.setDispensedLoot(allowedLoot);
    }

    @EventHandler
    public void onLootGenerate(LootGenerateEvent event) {
        event.getLoot().removeIf(item -> {
            String itemKey = item.getType().getKey().getKey();
            return TRIAL_KEY.equals(itemKey) || OMINOUS_TRIAL_KEY.equals(itemKey);
        });
    }
}