mwgameryt._73669

Role: Act as an expert Java 21 plugin developer for the PaperMC/Spigot API.

Task: Write a highly optimized, production-ready Java plugin implementing a custom "Card SMP" ability system. Ensure the code is modular, fully commented, and registers all commands, subcommands, and event listeners properly in the main class.

Core Architecture Constraints: * Item Security: Every custom item must be secured using a PersistentDataContainer (PDC) with a custom NamespacedKey (e.g., card_type). Do NOT rely on display names or lore to identify items. * Texture Pack Integration: Every item must have a unique CustomModelData integer assigned via ItemMeta#setCustomModelData() so it can be linked to a custom resource pack. * Targeting & UI: Ensure all cooldown notifications are sent via player.sendActionBar(). Every Area of Effect (AoE) ability must explicitly filter out the caster (if (target != caster)).

CRITICAL BUG FIX (Apply to all cards): All BukkitRunnables must include an internal tick counter. When the specified duration ends, you must explicitly call this.cancel() and fully revert all applied states (e.g., restore walkSpeed to 0.2f, flySpeed to 0.1f, and remove NoAI NBT tags). Do not leave permanent stat changes or infinite loops.

Command Framework (/cardsmp):

Implement a command executor with the following subcommands:

  1. /cardsmp start: Initializes the server's tracking systems and enables card usage globally.
  2. /cardsmp INVENTORY GUI: Opens a Bukkit Inventory INVENTORY GUI (27 slots) displaying all 6 cards. Clicking a card in the INVENTORY GUI gives it to the player and closes the menu.
  3. /cardsmp give <player> <card>: Admin command to bypass the INVENTORY GUI and give a specific card directly to a target's inventory.
  4. /cardsmp reset: Instantly clears all active card cooldowns globally and terminates any active tracking entities or BukkitRunnables.
  5. /cardsmp reroll: Takes the custom card currently held in the player's main hand, removes it, and gives them a random different card from the remaining 5 options.

Mechanics & Item Mapping (Must include PDC and CustomModelData):

  1. Time Card (Item: Light Blue Dye | ModelData: 1):

* Cooldown: 60 seconds. * Effect: Freeze all entities within a 50-block radius (excluding caster) for 15 seconds. Set target walk/fly speeds to 0 and apply the NoAI NBT tag to mobs. Revert to default speeds and remove NoAI after exactly 15 seconds via runnable cancellation.

  1. Gravity Card (Item: Black Dye | ModelData: 2):

* Cooldown: 45 seconds. * Effect: Creates a miniature black hole. Continuously pulls all entities and items within an 8-block radius (excluding caster) toward the center for 5 seconds using vector math. Ends with a force-2, terrain-safe explosion (createExplosion with block damage disabled). Simulate using PORTAL, SQUID_INK, and END_ROD particles via World#spawnParticle (strictly capped at 1 spawn per 5 ticks). Cancel runnable at 5 seconds.

  1. Glitch Card (Item: Gray Dye | ModelData: 3):

* Cooldown: 45 seconds. * Effect: Forces all players within a 15-block radius (excluding caster) to drop their held main-hand item once per second for 30 seconds. Cancel runnable at 30 seconds.

  1. Thunder Card (Item: Yellow Dye | ModelData: 4):

* Cooldown: 30 seconds. * Effect: Spams lightning strikes at all entities within a 10-block radius (excluding caster). Use a BukkitRunnable to execute the World#strikeLightning method exactly 1 time per tick (20 times per second) for 10 seconds. Cancel runnable at 10 seconds.

  1. Soul Card (Item: White Dye | ModelData: 5):

* Cooldown: 40 seconds. * Effect: Grants the caster 10 seconds of absolute damage immunity via the EntityDamageEvent. Track and accumulate all canceled damage values in a HashMap. When the 10-second BukkitRunnable ends, cancel immunity and instantly apply 100% of the accumulated damage directly to the caster via player.damage().

  1. Demon Card (Item: Red Dye | ModelData: 6):

* Passive Trigonometric Tracking: Run a background BukkitRunnable using PlayerItemHeldEvent. You MUST create an explicit ItemStack array containing the 5 other specific cards to ensure they are visually distinct in the orbit:

Index 0: Light Blue Dye (ModelData: 1) Index 1: Black Dye (ModelData: 2) Index 2: Gray Dye (ModelData: 3) Index 3: Yellow Dye (ModelData: 4) Index 4: White Dye (ModelData: 5) When spawning the 5 ItemDisplay entities, assign setItem(array[i]) so all 5 orbiting cards are strictly their correct colors. Orbit them in a continuous, equally spaced circle around the player's chest height (Y + 1.2) using parametric equations: x = x_0 + r cos(theta) and z = z_0 + r sin(theta) where theta = base_angle + (i 2 * PI / 5). Update base_angle every tick. remove() all entities immediately when the item is unequipped or hotbar slot changes. * Active Execution: 60-second cooldown. On Right Click, randomly select one of the five orbiting cards and execute its respective ability method instantly as if the player cast it. Caster must remain immune to any resulting AoE effects. * Cinematic Effect: Upon active trigger, spawn a dense vertical beam of END_ROD particles shooting straight up from the caster. Concurrently, trigger a "Visual Earthquake" by rapidly playing the MINECART_RIDING sound and spawning BLOCK_CRACK particles of stone/dirt at the caster's feet to simulate terrain destruction without causing actual block modifications.

Kodari AI
KodariJun 2 at 7:22 pm 62
CardSMP
A fully featured Card SMP ability plugin for PaperMC. Six unique cards — Time, Gravity, Glitch, Thunder, Soul, and Demon — each with PDC-secured items, CustomModelData for resource pack integration, and complex BukkitRunnable-driven effects that fully self-revert. Features a /cardsmp command suite with a chest GUI selector, admin give/reset, and player reroll. Demon card spawns real ItemDisplay orbit entities using parametric trig, and can randomly fire any other card's ability on demand.

Here’s a complete breakdown of the 21 files:


Architecture

Layer
Files
Core
CardSMPPlugin
,
CardManager
,
CardType
,
CardItem
Abilities
TimeCardAbility
,
GravityCardAbility
,
GlitchCardAbility
,
ThunderCardAbility
,
SoulCardAbility
,
DemonCardAbility
UI
InventoryHandler
,
InventoryButton
,
InventoryGUI
,
GUIManager
,
GUIListener
,
CardSelectGUI
Commands / Events
CardSMPCommand
,
CardListener
Util
ColorUtil

Key design decisions

PDC identity — Every card carries cardsmp:card_type storing CardType#name(). CardManager.getCardType() is the single point of truth; display names are never used to identify items.

Runnable lifecycle — Every BukkitRunnable holds an internal int ticks counter, explicitly calls this.cancel() at the configured duration, and fully reverts its state (walk/fly speed → defaults, mob AI → enabled). CardManager also stores all tasks in activeTasks + entity snapshots in frozenEntities so /cardsmp reset can cancel everything instantly.

Soul Card loop prevention — removeSoulImmunity() is called before player.setHealth(), so the EntityDamageEvent handler never intercepts the rebound damage.

Demon orbit — Five ItemDisplay entities are spawned with matching materials and CustomModelData (the explicit orbitItems[0..4] array). Their positions update every tick via θ = baseAngle + (i × 2π/5) — full parametric trig, no approximations. stopOrbit calls entity.remove() on all five immediately on slot change, quit, or reset.

GUI — The standard lazy-init GUI framework prevents constructor order issues. GUIManager.handleClick cancels all interactions (top and bottom inventory) while a registered GUI is open, preventing item theft from the player’s own inventory.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
21 1,599
src/main/java/com/cardsmp/CardSMPPlugin.java
package com.cardsmp;

import com.cardsmp.command.CardSMPCommand;
import com.cardsmp.inventory.gui.GUIListener;
import com.cardsmp.inventory.gui.GUIManager;
import com.cardsmp.listener.CardListener;
import com.cardsmp.manager.CardManager;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * CardSMP main class.
 *
 * Initialisation order:
 *   1. CardManager  – central state store
 *   2. GUIManager   – tracks open inventory GUIs
 *   3. Event listeners (CardListener, GUIListener)
 *   4. Command executor (/cardsmp)
 */
public class CardSMPPlugin extends JavaPlugin {

    @Getter private CardManager cardManager;
    @Getter private GUIManager  guiManager;

    @Override
    public void onEnable() {
        cardManager = new CardManager(this);
        guiManager  = new GUIManager();

        getServer().getPluginManager().registerEvents(new CardListener(this), this);
        getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);

        getCommand("cardsmp").setExecutor(new CardSMPCommand(this));

        getLogger().info("CardSMP enabled — 6 cards loaded.");
    }

    @Override
    public void onDisable() {
        // Cancel all active runnables and remove Demon orbit entities cleanly
        if (cardManager != null) {
            cardManager.resetAll();
        }
        getLogger().info("CardSMP disabled — all effects cleaned up.");
    }
}