Himalaya Dhungana
📎 1 file 18,778 chars
📄
pasted-code-1788278813482.txt
txt 64 lines
▶
I want to create a **custom, production-ready Minecraft PvP Duels plugin for Minecraft 1.21+**, designed to support multiple competitive duel modes, configurable arenas, round-based matches, player challenges, GUIs, persistent data, and a database system. The plugin should be modular, highly configurable, optimized for performance, and easy to extend with new duel modes in the future. It should work on modern Paper/Spigot-based servers and use clean, maintainable code with proper separation between duel logic, arena management, matchmaking/challenges, kits, GUIs, database operations, commands, events, and utilities.

The plugin should support the following duel modes: **Sword, Axe, UHC, Netherite Pot (NethPot), Diamond Pot (DiaPot), Crystal, Flat Crystal, SMP, Minecart, Mace, and Spear/Mace**. Each mode should have its own configurable kit, inventory, armor, weapons, enchantments, potion effects, food, health, hunger, game rules, allowed items, disabled items, and other PvP-specific settings. The system should make it possible to easily create additional modes later without rewriting the core duel system. Kit configurations should be stored in configuration files or the database and should support custom items, enchantments, potion effects, attributes, offhand items, and item durability. Modes should also be able to define their own special rules, such as whether natural regeneration is enabled, whether building is allowed, whether certain blocks can be placed/broken, whether end crystals are allowed, whether TNT/minecarts are allowed, and whether specific commands or items are disabled during a match.

The plugin needs a complete **arena management and configuration system**. Administrators should be able to create, edit, delete, enable, disable, clone, reset, and list arenas. An arena should support one or more spawn points depending on the duel format, including Team/Player spawn positions, spectator locations, lobby locations, boundaries, minimum and maximum coordinates, region/world information, and mode compatibility. Arenas should be assignable to specific duel modes, and the plugin should automatically select an available arena when a duel begins. Arena states should include available, occupied, resetting, disabled, and maintenance. The system should prevent two matches from using the same arena simultaneously unless the arena is explicitly configured to support multiple matches. There should also be an arena reset system so arenas can automatically return to their original state after a duel, preferably using a safe and efficient rollback/reset mechanism. Arena configuration should support world-specific settings and optional per-arena rules.

The plugin should implement a complete **duel lifecycle system**, including challenge creation, challenge acceptance, challenge denial, challenge expiration, match preparation, countdown, teleportation, kit application, match start, active combat, round completion, next-round preparation, match completion, rewards/stat updates, arena reset, and player return to the appropriate location. Players should be protected from taking damage and interacting incorrectly during preparation/countdown phases. The plugin should correctly handle disconnects, reconnects, deaths, timeouts, server restarts, teleport failures, world unloads, and other unexpected situations without leaving arenas or players stuck in an invalid state.

The duel system should support **round-based matches**, allowing configurable formats such as first-to-1, first-to-2, first-to-3, first-to-4, first-to-5, or other configurable round counts. Each round should have its own win/loss result, countdown, kit reset, inventory reset, health reset, and player positioning. The plugin should display the current score, such as `Player A 2 - 1 Player B`, throughout the match. Administrators should be able to configure whether a player must win a specific number of rounds, whether draws are possible, what happens when the maximum number of rounds is reached, and whether a final-round system or sudden-death system is enabled. The system should also support optional round delays and configurable time limits.

There should be a complete **player challenge and acceptance system**. Players should be able to challenge another player to a specific duel mode and optionally select an arena, round format, kit, and other configurable settings. Challenges should be sent through commands and/or a GUI. The receiving player should receive a clickable invitation with options to accept or deny. Challenges should have an expiration timer, configurable cooldowns, and anti-spam protection. Players should not be able to challenge themselves, challenge players who are offline, challenge players already in a duel, or accept multiple challenges simultaneously. The plugin should properly validate all conditions before creating or accepting a challenge. There should also be options for `/duel`, `/duel `, `/duel accept`, `/duel deny`, `/duel spectate`, `/duel leave`, `/duel rematch`, and administrative commands.

The plugin should contain a polished **GUI system** using Minecraft inventories. GUIs should allow players to select duel modes, view mode information, select kits, choose round formats, select arenas where permitted, send challenges, accept challenges, view statistics, and configure available options. The GUI should use configurable item names, lore, materials, slots, sounds, and messages. All GUI layouts should be configurable so server owners can customize them. The GUI system should prevent players from taking unauthorized items, moving items, or exploiting inventory interactions. Confirmation menus should be available for potentially destructive actions such as leaving a duel, deleting an arena, or resetting an arena.

The plugin should include a **spectator system**. Spectators should be able to watch active matches without interfering with them. Spectators should have appropriate permissions and restrictions, should not be able to damage or interact with active players, and should be placed in spectator mode or another configurable spectator state. There should be spectator teleportation, optional spectator GUI, match selection, and automatic removal of spectators when a match ends. The plugin should optionally hide spectators from active players and prevent spectators from affecting combat, redstone, entities, containers, blocks, projectiles, and other gameplay mechanics.

The plugin should have a comprehensive **statistics and player profile system**. It should track wins, losses, draws, kills, deaths, rounds won, rounds lost, winstreaks, highest winstreak, total duels, mode-specific statistics, ELO/rating if enabled, and other configurable statistics. Players should be able to view their own and other players' statistics through commands and GUIs. The plugin should support leaderboards by overall statistics and individual modes. Statistics should be stored persistently in a database and updated safely after matches. The system should avoid duplicate or incorrect stat updates if a match ends unexpectedly.

A persistent **database layer** should be implemented using a reliable database such as **MySQL/MariaDB**, with SQLite available as an optional lightweight alternative for smaller servers. Database credentials, host, port, database name, username, password, pool size, and other connection settings should be configurable. Database operations should be asynchronous wherever possible so database queries never block the Minecraft main server thread. The plugin should use a connection pool such as HikariCP and have a clean repository/service architecture. The database should store player profiles, statistics, mode statistics, ELO/rating where enabled, match history, round results, arena information if desired, and other persistent configuration/data that needs to survive restarts. The system should gracefully handle database connection failures and reconnect when possible.

The plugin should include a **match history system** that records completed matches, including players, duel mode, winner, loser, rounds won, rounds lost, arena, duration, timestamp, and relevant match metadata. Players should be able to view recent match history through a command or GUI. Match history should be configurable so server owners can control how much historical data is retained.

The plugin should support an optional **ELO/rating and competitive ranking system**. Each duel mode should optionally have its own rating. The rating calculation should be configurable, including starting rating, K-factor, win/loss adjustments, placement matches if desired, and rating boundaries. There should be optional ranks/divisions based on rating. ELO should be completely disableable if the server only wants casual statistics.

The plugin should have a robust **matchmaking system**, even if direct player challenges are the primary method. Players should optionally be able to queue for a specific mode and round format. The matchmaking system should find suitable opponents, prevent duplicate queue entries, respect configurable rating ranges, and automatically assign an available compatible arena. Queue status should be shown to the player through messages or a GUI. Players should be able to leave the queue at any time.

The plugin should provide extensive **commands and permissions**. There should be separate player and administrator commands for duel management, challenges, queues, arenas, kits, statistics, leaderboards, spectators, reloads, debugging, and maintenance. Permissions should be granular, such as permissions for challenging, spectating, creating arenas, deleting arenas, editing kits, forcing matches, bypassing cooldowns, managing queues, viewing admin information, and using debug tools. All commands should provide useful tab completion and clear error messages.

The plugin should include a complete **configuration system** with separate configuration files where appropriate, such as `config.yml`, `messages.yml`, `menus.yml`, `modes.yml`, `kits.yml`, and arena-related configuration. Messages should support placeholders such as player names, mode names, round scores, arena names, ratings, and remaining time. Messages, titles, action bars, boss bars, sounds, particles, countdowns, GUI names, and item descriptions should all be customizable. The plugin should support color codes and modern Minecraft text components where appropriate.

The plugin should include **countdowns, titles, action bars, boss bars, sounds, particles, and visual feedback** for important events. Before a match starts, players should receive a configurable countdown such as 5, 4, 3, 2, 1, GO. During matches, the plugin should optionally display the current round, score, remaining time, mode, opponent, and other information through a scoreboard, boss bar, action bar, or configurable HUD. When a round or match ends, players should receive clear winner/loser information.

There should be a configurable **duel timeout system**. Server owners should be able to specify maximum match duration, maximum round duration, and what happens when the timer expires. Timeout behavior could include determining a winner based on health, damage dealt, configured score, sudden death, or declaring a draw. This should be configurable per mode.

The plugin must properly handle **combat and gameplay restrictions**. During active duels, only the configured mechanics for the selected mode should be allowed. The system should prevent players from exploiting commands, teleporting away, changing gamemodes, opening unauthorized inventories, using restricted items, escaping arena boundaries, or interfering with other matches. Depending on the mode, it should handle block placement/breaking, entities, projectiles, explosions, fire, fluids, containers, item drops, item pickups, death mechanics, and environmental damage. The plugin should provide per-mode configuration for these behaviors rather than hard-coding them globally.

The plugin should support **anti-exploit and anti-cheese protections**, including configurable arena boundaries, void protection, teleport protection, command restrictions, inventory protection, combat logging detection, illegal item prevention, and prevention of players entering another active match's arena. If a player disconnects during an active duel, the plugin should have a configurable behavior such as immediately declaring the opponent the winner, applying a grace period, or treating it as a loss.

The plugin should include a **rematch system**. After a duel ends, both players should optionally receive a rematch request through a GUI or clickable message. If both players accept within a configurable period, the plugin should automatically create another match using the same mode, kit, round format, and optionally the same arena or a newly selected arena. Rematch requests should expire and should not interfere with other challenges.

The plugin should optionally support **party/team duels** in the future, so the architecture should not assume that every match always contains exactly two players. Even if the first version only supports 1v1, the internal duel/match architecture should be extensible toward 2v2, FFA, tournaments, and team-based formats without requiring a complete rewrite.

The plugin should include **event handling and lifecycle safety**. All listeners should correctly identify whether a player is inside a duel and which match they belong to. Player death, damage, quit, join, teleport, world change, inventory click, item pickup/drop, block interaction, block break/place, entity damage, projectile events, explosions, and command preprocessing should be handled only when relevant. The plugin should avoid unnecessary event processing for players who are not participating in duels.

The plugin should be designed for **high performance and scalability**. Avoid unnecessary synchronous database queries, excessive repeating tasks, inefficient loops, and memory leaks. Use scheduled tasks carefully, cancel tasks when matches end, and ensure arenas and player references are cleaned up. The system should support many simultaneous matches on a server. Match state should be managed cleanly with states such as WAITING, COUNTDOWN, IN_PROGRESS, ROUND_END, FINISHED, RESETTING, and CANCELLED.

The plugin should include **logging and debugging tools**. Administrators should be able to enable debug mode and receive useful information about match creation, arena allocation, kit application, database operations, round transitions, resets, and errors. Errors should be handled gracefully and logged with enough context to diagnose problems. The plugin should never silently fail and leave a player or arena permanently locked.

The plugin should support **permissions and placeholders integration**, preferably through PlaceholderAPI if available. Placeholders should expose player wins, losses, winstreak, rating, mode statistics, current opponent, current duel mode, round score, queue status, and other useful information. PlaceholderAPI should be optional so the plugin does not depend on it unless installed.

The plugin should optionally support **economy/reward integrations** such as Vault, allowing server owners to reward winners with money, points, tokens, items, or commands. Rewards should be configurable per mode and should support winner rewards, participation rewards, streak rewards, and optional penalties. These integrations should be optional and should not prevent the plugin from running if the dependency is missing.

The plugin should provide **admin match management tools**, including viewing active matches, forcing a match to end, teleporting to a match, cancelling a match, resetting an arena, putting an arena into maintenance mode, viewing match/player state, and recovering stuck arenas. Administrative actions should be permission-protected and logged.

The plugin should include **safe reload behavior**. `/duel reload` should reload configurations and messages without corrupting active matches. Configuration changes that cannot safely be applied during active matches should only take effect for newly created matches. Database connections should not be unnecessarily recreated during ordinary configuration reloads.

The plugin should have a clean and modular architecture, preferably separating components such as `DuelManager`, `MatchManager`, `ArenaManager`, `ArenaResetManager`, `ChallengeManager`, `QueueManager`, `KitManager`, `ModeManager`, `RoundManager`, `SpectatorManager`, `StatsManager`, `DatabaseManager`, `PlayerProfileManager`, `GUIManager`, `RewardManager`, `EloManager`, `MessageManager`, and command/listener packages. Use interfaces where useful so new duel modes, database implementations, arena reset systems, and integrations can be added without modifying large amounts of existing code.

The final implementation should include all necessary plugin metadata and dependency configuration, proper `plugin.yml` or the appropriate modern Paper plugin configuration, commands, permissions, configuration examples, database schema/migrations, default kits and modes, sample arenas, GUI configurations, message configurations, and clear installation/setup instructions. The code should be production-quality rather than a basic prototype. It should be compatible with the latest stable Minecraft 1.21.x versions while avoiding unnecessary version-specific NMS code wherever possible. If NMS is required for a specific feature, isolate it behind an abstraction layer so future Minecraft versions can be supported more easily.

Most importantly, **do not hard-code gameplay behavior that should be configurable**. Duel modes, kits, arenas, round counts, timers, rewards, messages, GUI layouts, sounds, effects, restrictions, database settings, ELO settings, matchmaking settings, and other server-specific behavior should be configurable. The system should be designed as a complete framework for competitive Minecraft duels rather than a collection of hard-coded individual modes.

Before implementing the plugin, first produce a clear project architecture, database schema, class/module structure, event flow, match state machine, configuration structure, command/permission list, and implementation plan. Then implement the plugin in logical modules, ensuring that every module integrates correctly with the core duel system. Include comments and documentation for complex systems, provide sensible defaults, validate configuration values, and ensure that the plugin remains stable if optional dependencies such as Vault or PlaceholderAPI are not installed.
Kodari AI
KodariSep 1 at 3:13 am 3
DuelArenaPro
Production-ready Minecraft PvP duels plugin for 1.21+ with configurable modes, arenas, round-based matches, challenges, GUIs, spectator system, persistent stats, MySQL/SQLite database, ELO ratings, matchmaking, and admin tools. Features modular architecture, per-mode kits and rules, arena reset, match history, rematches, anti-exploit protections, and full configuration customization.
  1. Create the Gradle/Paper project metadata and configurable defaults.

  2. Add the modular duel domain model and managers for modes, kits, arenas, matches, challenges, queues, spectators, statistics, persistence, and GUI flow.

  3. Register commands/listeners and provide admin controls, lifecycle cleanup, and database schema.

  4. Include architecture and setup documentation describing the state machine, event flow, and extension points.

The initial project skeleton is in place. I’m tightening the cross-file integration now: database initialization, resource copying, compatibility-safe item creation, shutdown cleanup, and the architecture/setup reference.

Implemented the initial KodariDuels project foundation:

  • Gradle/Paper 1.21.x project setup with Java 21, XSeries, HikariCP, and optional database manifest.

  • Plugin metadata, default configuration, messages, kits, modes, arenas, and SQL schema.

  • Modular duel models and lifecycle states.

  • Mode, kit, arena, challenge, queue, match, spectator, statistics, database, and arena reset services.

  • Player and administrator commands with tab completion.

  • Duel GUI mode selector.

  • Event handling for combat, deaths, quitting, teleportation, boundaries, inventories, drops, pickups, building, and restricted commands.

  • SQLite/MySQL connection-pool foundation with asynchronous match-history writes.

  • README covering architecture, state flow, configuration, commands, and extension points.

The current implementation establishes the extensible 1v1 framework and lifecycle foundation. Advanced systems such as ELO, rewards, PlaceholderAPI, configurable multi-step GUIs, true world snapshot rollback, party duels, and persistent profile/stat loading still need to be added as subsequent modules.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
README.md
settings.gradle
Code
34 1,778
src/main/java/com/kodari/duels/DuelPlugin.java
package com.kodari.duels;

import com.kodari.duels.command.DuelAdminCommand;
import com.kodari.duels.command.DuelCommand;
import com.kodari.duels.listener.DuelListener;
import com.kodari.duels.service.ArenaManager;
import com.kodari.duels.service.ArenaResetManager;
import com.kodari.duels.service.ChallengeManager;
import com.kodari.duels.service.DatabaseManager;
import com.kodari.duels.service.KitManager;
import com.kodari.duels.service.MatchManager;
import com.kodari.duels.service.MessageService;
import com.kodari.duels.service.ModeManager;
import com.kodari.duels.service.QueueManager;
import com.kodari.duels.service.SpectatorManager;
import com.kodari.duels.service.StatsManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class DuelPlugin extends JavaPlugin {
    @Getter private MessageService messages;
    @Getter private ModeManager modeManager;
    @Getter private KitManager kitManager;
    @Getter private ArenaManager arenaManager;
    @Getter private ArenaResetManager arenaResetManager;
    @Getter private DatabaseManager databaseManager;
    @Getter private StatsManager statsManager;
    @Getter private SpectatorManager spectatorManager;
    @Getter private MatchManager matchManager;
    @Getter private ChallengeManager challengeManager;
    @Getter private QueueManager queueManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        saveResourceIfMissing("messages.yml");
        saveResourceIfMissing("modes.yml");
        saveResourceIfMissing("kits.yml");
        saveResourceIfMissing("arenas.yml");
        saveResourceIfMissing("schema.sql");
        messages = new MessageService(this);
        modeManager = new ModeManager(this);
        kitManager = new KitManager(this);
        arenaManager = new ArenaManager(this);
        arenaResetManager = new ArenaResetManager(this);
        databaseManager = new DatabaseManager(this);
        statsManager = new StatsManager(this);
        spectatorManager = new SpectatorManager(this);
        matchManager = new MatchManager(this);
        challengeManager = new ChallengeManager(this);
        queueManager = new QueueManager(this);
        DuelListener listener = new DuelListener(this);
        Bukkit.getPluginManager().registerEvents(listener, this);
        DuelCommand duelCommand = new DuelCommand(this);
        getCommand("duel").setExecutor(duelCommand);
        getCommand("duel").setTabCompleter(duelCommand);
        DuelAdminCommand adminCommand = new DuelAdminCommand(this);
        getCommand("dueladmin").setExecutor(adminCommand);
        getCommand("dueladmin").setTabCompleter(adminCommand);
        getLogger().info("KodariDuels enabled with " + modeManager.all().size() + " modes and " + arenaManager.all().size() + " arenas.");
    }

    @Override
    public void onDisable() {
        if (queueManager != null) queueManager.shutdown();
        if (challengeManager != null) challengeManager.shutdown();
        if (matchManager != null) matchManager.shutdown();
        if (databaseManager != null) databaseManager.close();
    }

    public void reloadPlugin() {
        reloadConfig();
        messages.reload();
        modeManager.reload();
        kitManager.reload();
        arenaManager.reload();
    }

    private void saveResourceIfMissing(String resource) {
        if (!new java.io.File(getDataFolder(), resource).exists()) saveResource(resource, false);
    }
}