karexayush
๐Ÿ“Ž 1 file 1,287 chars
๐Ÿ“„
pasted-code-1788583209774.txt
txt 37 lines
โ–ถ
Create a Minecraft Java server plugin for Paper 1.21.11.

The plugin should contain two main systems:

1. Totem Inventory Limit System

A player must be allowed to have a maximum of only 2 Totems of Undying in their entire inventory.

This limit must include:

Main inventory
Hotbar
Offhand
Rules:
A player can never possess more than 2 Totems of Undying total across their entire inventory, including the offhand.
For example:
2 Totems in inventory = allowed
1 Totem in inventory + 1 Totem in offhand = allowed
2 Totems in inventory + 1 Totem in offhand = NOT allowed
The plugin must prevent players from obtaining or keeping more than 2 Totems.

The limit should work correctly when players:

Pick up Totems from the ground
Receive Totems through commands or other plugins
Move Totems inside their inventory
Shift-click Totems
Drag Totems
Move a Totem into the offhand
Use number-key inventory swapping
Swap items between main hand and offhand
Take Totems from chests, shulker boxes, barrels, etc.
Receive Totems through trading or any other inventory interaction

If a player already has 2 Totems and attempts to obtain another Totem, the extra Totem must not be added to their inventory.

Make sure the system does not accidentally delete legitimate Totems or cause item duplication.
Kodari AI
KodariSep 5 at 4:44 am 1
TotemLimitGuard
A Paper 1.21.11 plugin enforcing a strict maximum of 2 Totems of Undying per player across their entire inventory including main inventory, hotbar, and offhand. It intercepts all acquisition methods: ground pickups, command-given items, inventory movements, shift-clicks, drag operations, offhand swaps, number-key exchanges, chest/shulker/barrel extractions, and trading interactions. The system prevents exceeding the limit without deleting legitimate totems or causing duplication, using event-driven checks and cancellation to reject excess totems while preserving existing ones.

Implemented the Paper 1.21.11 plugin with:

  • Two-Totem maximum across main inventory, hotbar, armor, and offhand.

  • Pickup prevention and partial-stack limiting.

  • Inventory click, shift-click, drag, hotbar swap, offhand, and container interaction protection.

  • Hopper-style item movement protection.

  • Periodic enforcement for Totems added by commands or other plugins.

  • Gradle build configuration and plugin.yml.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 255
src/main/java/com/kodari/totemlimit/TotemLimitPlugin.java
package com.kodari.totemlimit;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class TotemLimitPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        TotemInventoryGuard guard = new TotemInventoryGuard(this);
        Bukkit.getPluginManager().registerEvents(new TotemLimitListener(guard), this);
        Bukkit.getScheduler().runTaskTimer(this, guard::enforceOnlinePlayers, 1L, 1L);
    }
}