drug2_
📎 1 file 6,345 chars
📄
pasted-code-1788468705255.txt
txt 90 lines
▶
Act as an expert, top-tier Java developer for Minecraft server networks. I need you to write a massive, highly professional, premium practice/duels core plugin called "MonarchPractice". 

TARGET API: Paper 1.21.1 (1.21.x).
STRICT RULE: Do NOT split this into multiple files. Put absolutely everything (classes, objects, listeners, commands, scoreboards) inside ONE single monolithic file named `MonarchPractice.java`. Do not skip or truncate any lines. Write the full 1000+ lines of code if necessary. 

DEPENDENCIES: 
- Multiverse-Core (API not strictly needed in gradle, we will use console commands to generate).
- VoidGen.
- DO NOT use PlaceholderAPI. We will handle all placeholders (like queue sizes and opponent names) natively within the plugin.

Here is the exact feature-set and logic you must implement:

1. SPAWN & HOTBAR SYSTEM
- Command `/monarchpractice setspawn` (Admin) sets the lobby location.
- Command `/spawn` TPs the player there.
- When in the spawn world (and ONLY in the spawn world), players are in Adventure mode and have a fixed hotbar. They cannot drop these items, and right-clicking the firework does not launch it.
- Slot 1: Netherite Sword named "&6🗡 Duels Queue"
- Slot 4: Totem of Undying named "&a🏹 Free For All"
- Slot 5: Firework Rocket named "&b⚑ Party Create"
- Slot 6: Knowledge Book named "&d🌊 Kit Layouts"
- Slot 9: Grindstone named "&7⚙ Settings"

2. DUEL QUEUE GUI (Sword Click)
- Clicking the sword opens a 5x9 (45 slot) Chest GUI titled "&6Duels".
- Border: Slots 0-8, 9, 17, 18, 26, 27, 35, 36-44 are Black Stained Glass Panes with no name.
- Slot 40 (Bottom center): Arrow named "&6Next Page".
- The 23 empty inner slots display available kits. 
- Kit Icon Format: 
  - Name: "&6"
  - Lore Line 1: "&7Duels Queue"
  - Lore Line 2: "" (Empty)
  - Lore Line 3: "&fClick to queue for"
  - Lore Line 4: "&f potion!"
  - Lore Line 5: "" (Empty)
  - Lore Line 6: "&6✦ In Fight: &7"
  - Lore Line 7: "&6✦ In Queue: &7"
  - Lore Line 8: "" (Empty)
  - Lore Line 9: "&6➔ &nCLICK&6 to Queue" (The word CLICK is underlined).

3. KIT MANAGEMENT
- `/kit create  `: Creates a kit saving the admin's exact inventory and armor. Underscores in the name become spaces.
- `/kit assignarena  `: Links a specific arena to a kit.
- `/kit setproperty   `: 
  - Properties: `Hunger` (if false, hunger stays 20), `NaturalRegeneration` (if false, vanilla saturation healing is disabled, only pots/gapples heal), `AutoTNT` (if true, placed TNT instantly ignites without flint & steel), `AutoPot` (if true, auto-splashes speed/fire res at match start). All true by default except AutoTNT.

4. ARENA MANAGEMENT
- `/arena create `: Dispatches console command `mv create  normal -g VoidGen` to create a void world.
- `/arena teleport `: TPs to 0,100,0 of that world to build.
- `/arena wand`: Gives a golden axe. Left/Right click blocks to set Pos1/Pos2.
- `/arena set `: Sets the boundary. The plugin then prompts the user to use the wand again to left/right click to set Spawn1/Spawn2, followed by a confirm command to finalize the arena.
- `/arena copy  `: Dispatches `mv clone  `, then automatically copies the Pos1/Pos2/Spawn1/Spawn2 coordinates to the new arena object in the new world.
- `/arena autoreset afterduels ` & `/arena autoreset time `: Configurations for auto-reset. 
- Arena Rules: Players cannot break arena floor blocks. They can only place blocks, or break blocks that were placed during the match (and cobwebs). Escaping the Pos1/Pos2 boundary instantly TPs the player back to their last valid location inside the bounds.
- Auto-Reset Logic: When an arena resets, the blocks placed during matches are removed gradually (e.g., 5 blocks per tick) to prevent server lag.

5. MATCHMAKING & QUEUE FLOW
- Player clicks a kit in the GUI -> Menu closes.
- Action Bar updates: `&6 1v1 ┇ 00:00` (Timer counts up every second).
- When 2 players queue for the same kit: 
  - Blindness effect applied.
  - Sound plays.
  - Title appears: "&6&l⚔ Opponent Found ⚔"
  - Subtitle: "&7Teleporting in 3..." -> 2... 1.
  - Action bar shows teleporting status.
- If no arena is assigned/ready, send error and cancel. Otherwise, TP to arena Spawn1 and Spawn2. Give kits.

6. IN-MATCH LOGIC
- Pre-Match Freeze (5 seconds): Players are COMPLETELY frozen (position and camera/head movement locked). They cannot use bows/crossbows or hit each other. They CAN move items in their inventory.
- Sneak-to-Skip: Action bar shows "Sneak to cancel countdown 0/2". If a player sneaks, it goes to 1/2. If both sneak, the 5-second countdown instantly ends.
- Match Start: Chat says "&aFight!". 
- AutoPot logic: If Kit property `AutoPot` is true, a splash potion sound plays, particles appear, and players are instantly buffed with the exact potion effects stored in the kit (e.g., Speed, Fire Res) without having to throw them manually.

7. MATCH END & POST-MATCH
- On kill: Loser is put in Spectator mode for 3 seconds. They cannot fly out of the arena bounds.
- Titles: Winner gets "&a&lYou Won!!!", Loser gets "&c&lYou Lost!!!".
- Chat: "Teleporting back to spawn in 3... 2... 1".
- After 3s: TP back to spawn, game mode adventure, give spawn hotbar.
- Clickable Chat Message to both players:
  "&6The duel has ended!
   &6Winner:  &a&n[Click here to view inventory]
   &6Loser:  &c&n[Click here to view inventory]"
- Clicking the link runs a command that opens a GUI showing that player's exact inventory/armor states and durabilities from the moment the match ended.
- Save Wins, Losses, and Playtime (in seconds) to a data file.

8. CUSTOM SCOREBOARDS (scoreboard.yml)
- Spawn Scoreboard: Shows Wins, Losses, and Playtime.
- Duel Scoreboard: Shows Opponent Name and Kit Name.
- Must be fully configurable in the `scoreboard.yml` file.

Please write the complete `MonarchPractice.java` file implementing all of this natively without relying on any external APIs other than standard Paper/Spigot. Ensure the code is clean, highly optimized, and handles all edge cases.
Kodari AI
KodariSep 3 at 9:03 pm 3
MonarchPractice
A premium duels and practice core plugin for Paper 1.21.1. Features a spawn hotbar system with queue GUIs, kit management with configurable properties, arena creation via Multiverse-Core with boundary enforcement and auto-reset, matchmaking with countdown and freeze mechanics, spectator mode on death, clickable post-match inventory viewing, and fully configurable scoreboards. All functionality is implemented natively in a single monolithic file without external APIs.
  1. Create the Paper 1.21.1 Gradle project and plugin metadata.

  2. Add the complete single-file MonarchPractice.java implementation with nested managers, data models, listeners, commands, GUIs, matchmaking, arenas, stats, and scoreboards.

  3. Add default configuration and configurable scoreboard resources.

Created the complete MonarchPractice project from scratch:

  • src/main/java/com/monarchpractice/MonarchPractice.java

  • src/main/resources/plugin.yml

  • src/main/resources/config.yml

  • src/main/resources/scoreboard.yml

  • build.gradle

  • settings.gradle

The Java implementation is contained in the single requested monolithic file and includes spawn hotbar handling, kit and arena commands, queue GUI, matchmaking, countdowns, duel logic, arena boundaries, TNT automation, resets, snapshots, stats, clickable inventory viewing, and configurable scoreboards.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 1,173
src/main/java/com/monarchpractice/MonarchPractice.java
package com.monarchpractice;

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import java.io.File;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public final class MonarchPractice extends JavaPlugin implements Listener {
    private final Map<String, Kit> kits = new LinkedHashMap<>();
    private final Map<String, Arena> arenas = new LinkedHashMap<>();
    private final Map<UUID, Stats> stats = new HashMap<>();
    private final Map<UUID, Long> sessions = new HashMap<>();
    private final Map<String, LinkedHashSet<UUID>> queues = new HashMap<>();
    private final Map<UUID, Long> queueJoined = new HashMap<>();
    private final Map<UUID, Match> matches = new HashMap<>();
    private final Map<UUID, Selection> selections = new HashMap<>();
    private final Map<UUID, String> pendingArenaSpawns = new HashMap<>();
    private final Map<String, Snapshot> snapshots = new ConcurrentHashMap<>();
    private final Map<UUID, Scoreboard> boards = new HashMap<>();
    private FileConfiguration data;
    private FileConfiguration scoreboardConfig;
    private Location spawn;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        saveResource("scoreboard.yml", false);
        data = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "data.yml"));
        scoreboardConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "scoreboard.yml"));
        loadAll();
        getServer().getPluginManager().registerEvents(this, this);
        registerCommands();
        new BukkitRunnable() {
            @Override
            public void run() {
                tick();
            }
        }.runTaskTimer(this, 1L, 1L);
    }

    @Override
    public void onDisable() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            saveSession(player.getUniqueId());
        }
        saveAll();
    }

    private void registerCommands() {
        for (String name : Arrays.asList("monarchpractice", "spawn", "kit", "arena", "mpview")) {
            if (getCommand(name) != null) {
                getCommand(name).setExecutor(new Commands());
                getCommand(name).setTabCompleter(new Commands());
            }
        }
    }

    private void loadAll() {
        spawn = getConfig().getLocation("spawn");
        ConfigurationSection kitSection = getConfig().getConfigurationSection("kits");
        if (kitSection != null) {
            for (String key : kitSection.getKeys(false)) {
                Kit kit = Kit.load(key, kitSection.getConfigurationSection(key));
                if (kit != null) kits.put(key, kit);
            }
        }
        ConfigurationSection arenaSection = getConfig().getConfigurationSection("arenas");
        if (arenaSection != null) {
            for (String key : arenaSection.getKeys(false)) {
                Arena arena = Arena.load(key, arenaSection.getConfigurationSection(key));
                if (arena != null) arenas.put(key, arena);
            }
        }
    }

    private void saveAll() {
        getConfig().set("spawn", spawn);
        getConfig().set("kits", null);
        ConfigurationSection kitSection = getConfig().createSection("kits");
        kits.forEach((key, kit) -> kit.save(kitSection.createSection(key)));
        getConfig().set("arenas", null);
        ConfigurationSection arenaSection = getConfig().createSection("arenas");
        arenas.forEach((key, arena) -> arena.save(arenaSection.createSection(key)));
        saveConfig();
        for (Map.Entry<UUID, Stats> entry : stats.entrySet()) {
            entry.getValue().save(data.createSection("players." + entry.getKey()));
        }
        try {
            data.save(new File(getDataFolder(), "data.yml"));
        } catch (Exception exception) {
            getLogger().warning("Could not save data.yml: " + exception.getMessage());
        }
    }

    private void tick() {
        long now = System.currentTimeMillis();
        for (Map.Entry<UUID, Match> entry : new ArrayList<>(matches.entrySet())) {
            if (entry.getKey().equals(entry.getValue().playerOne)) {
                updateMatch(entry.getValue(), now);
            }
        }
        for (Map.Entry<String, LinkedHashSet<UUID>> entry : queues.entrySet()) {
            Kit kit = kits.get(entry.getKey());
            if (kit == null) continue;
            for (UUID uuid : new ArrayList<>(entry.getValue())) {
                Player player = Bukkit.getPlayer(uuid);
                if (player != null) {
                    long seconds = Math.max(0, (now - queueJoined.getOrDefault(uuid, now)) / 1000);
                    actionBar(player, color("&6" + kit.name + " 1v1 &7┇ &f" + formatTime(seconds)));
                }
            }
        }
        if (now % 1000 < 50) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (!matches.containsKey(player.getUniqueId()) && !queueJoined.containsKey(player.getUniqueId()) && isSpawnWorld(player.getWorld())) {
                    giveSpawnItems(player);
                    updateScoreboard(player, null);
                }
            }
            for (Arena arena : arenas.values()) {
                if (!arena.occupied && arena.autoresetTime > 0 && now - arena.lastReset >= arena.autoresetTime * 1000L && !arena.resetting) {
                    resetArena(arena);
                }
            }
        }
    }

    private void updateMatch(Match match, long now) {