Maximilian
📎 1 file 1,680 chars
đź“„
pasted-code-1790543223623.txt
txt 81 lines
â–¶
Create a Paper 1.21.x Minecraft plugin called EnchainSMP.

The main feature is that any enchantment can be applied to any item, while keeping vanilla max levels.

Core Features

Every 15 minutes, every online player receives 1 random enchantment book.

The enchantment is different for every player.

Each enchantment can only be given once to a player until they have collected them all.

After collecting every enchantment, the pool resets automatically.

The book should display the enchantment name and its vanilla level.

Enchanting System

Players can combine the random enchantment book with any item in an anvil.

Ignore vanilla item restrictions (Sharpness on sticks, Protection on helmets, etc.).

Never exceed vanilla limits:

Sharpness V

Protection IV

Unbreaking III

Mending I

etc.

Do not create illegal levels like Sharpness X or Fortune X.

Spear Compatibility

Riptide must fully work on custom spear items.

The spear should behave like a trident for Riptide while still being a spear.

Loyalty, Channeling, and Impaling should also function correctly on spears.

Universal Item Support

Any enchantment should work on any item:

Weapons

Tools

Armor

Blocks

Food

Custom items

Preserve all enchantment effects whenever possible.

Commands

/enchain reload — reload config

/enchain give   — give a specific enchant book

/enchain reset  — reset collected enchantments

Config

Change reward interval (default 900 seconds)

Enable/disable broadcast messages

Customize messages

Support permissions

The code should be clean, optimized, and ready to compile as a Paper plugin with no enchantment level exceeding vanilla limits.
Kodari AI
KodariSep 27 at 9:08 pm 1
EnchainSMP
EnchainSMP is a Paper 1.21.x plugin that revolutionizes enchantment gameplay by allowing any enchantment to be applied to any item while strictly maintaining vanilla maximum levels. Every 15 minutes, each online player receives a unique random enchantment book, with the pool resetting after all enchantments are collected. Players combine these books with any item in an anvil, bypassing vanilla item restrictions entirely. The plugin includes full spear compatibility, making Riptide, Loyalty, Channeling, and Impaling function correctly on custom spear items. Commands include /enchain reload, /enchain give, and /enchain reset, with configurable reward intervals, broadcast messages, and permission support.
  1. Set up the Paper 1.21.4/Java 21 plugin project and configurable messages.

  2. Add persistent, unique-per-cycle enchantment rewards and /enchain admin commands.

  3. Add anvil handling that applies enchantments to unrestricted items without exceeding their maximum levels.

Created the EnchainSMP Paper 1.21.4 project with scheduled enchantment-book rewards, saved collection tracking, /enchain commands, configurable messages, and anvil support for applying enchantments without exceeding their maximum levels.

Spear caveat: Enchantments are stored on unrestricted items, but Minecraft only activates their effects on item types it natively supports. Custom spear behavior—such as Riptide, Loyalty, and Channeling—is not emulated here; it requires a trident-backed spear or integration with the spear’s item plugin.

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

import com.kodari.enchainsmp.command.EnchainCommand;
import com.kodari.enchainsmp.data.PlayerCollectionStore;
import com.kodari.enchainsmp.enchant.EnchantmentService;
import com.kodari.enchainsmp.listener.AnvilEnchantListener;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.Objects;

public final class EnchainSMPPlugin extends JavaPlugin {
    private PlayerCollectionStore collectionStore;
    private EnchantmentService enchantmentService;
    private BukkitTask rewardTask;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        collectionStore = new PlayerCollectionStore(this);
        collectionStore.load();
        enchantmentService = new EnchantmentService(this, collectionStore);

        Bukkit.getPluginManager().registerEvents(new AnvilEnchantListener(this), this);
        PluginCommand command = Objects.requireNonNull(getCommand("enchain"), "enchain command is missing from plugin.yml");
        EnchainCommand executor = new EnchainCommand(this);
        command.setExecutor(executor);
        command.setTabCompleter(executor);
        scheduleRewards();
    }

    @Override
    public void onDisable() {
        if (rewardTask != null) {
            rewardTask.cancel();
        }
    }

    public EnchantmentService getEnchantmentService() {
        return enchantmentService;
    }

    public PlayerCollectionStore getCollectionStore() {
        return collectionStore;
    }

    public void reloadPluginConfiguration() {
        reloadConfig();
        scheduleRewards();
    }

    private void scheduleRewards() {
        if (rewardTask != null) {
            rewardTask.cancel();
        }
        long intervalSeconds = Math.max(1L, getConfig().getLong("reward-interval-seconds", 900L));
        long intervalTicks = Math.min(intervalSeconds, Integer.MAX_VALUE / 20L) * 20L;
        rewardTask = Bukkit.getScheduler().runTaskTimer(this, enchantmentService::rewardOnlinePlayers, intervalTicks, intervalTicks);
    }
}