flekmoon
📎 1 file 14,847 chars
📄
pasted-code-1772572222420.txt
txt 598 lines
▶
Create a production-ready SkyPvP plugin for a Paper 1.8.x (1.8.8-compatible) Minecraft server that runs the entire SkyPvP mode inside one specific configured world (NOT a separate server). The mode must behave like a dedicated SkyPvP server while sharing the same JVM/server with other worlds/modes. The plugin must be high performance, event-driven, thread-safe, and use async MySQL for all persistent data (never block the main thread). Everything must be configurable via YAML and all messages must be customizable.

Target Platform

Server: Paper 1.8.x (assume 1.8.8 NMS compatibility)

API: Bukkit/Spigot/Paper 1.8

Java: Compatible with Java 8 baseline (safe for 1.8 server ecosystems)

Must avoid heavy allocations, avoid memory leaks, and be stable for long uptime.

Core Mode Rules

SkyPvP is confined to one world only, defined in config.yml (e.g., skypvp-world: "SkyPvP").

Plugin features only apply inside that world, except /skypvp join which can be executed anywhere (teleports into SkyPvP).

Broadcasts related to killstreaks must broadcast to SkyPvP world only (not global server).

Data & Storage Requirements (MySQL + Async)

Persist ALL of the following to MySQL:

Player “mode initialization” flag (first time join tracking)

SkyPvP inventory snapshot:

Inventory contents

Armor contents

Active potion effects

Exact SkyPvP last location:

world name (SkyPvP world)

x, y, z, yaw, pitch

Statistics:

kills, deaths

current killstreak, highest killstreak

prestige level

K/D ratio computed dynamically (store kills/deaths, compute ratio on read)

Mode economy (coins balance)

Performance / Concurrency Rules

Use a connection pool (HikariCP recommended).

All SQL operations must be executed asynchronously (Bukkit async scheduler or your own executor).

Never access Bukkit API from async threads except for safe immutable data; all player/world/inventory operations must occur on the main thread.

Implement a Storage abstraction layer:

Storage interface (methods for save/load stats, economy, player snapshot, initialized flag)

MySqlStorage implementation

Implement a Repository/DAO style with prepared statements and batched writes when possible.

Implement safe caching where beneficial (e.g., in-memory session cache while player is in SkyPvP) but avoid stale data and memory leaks:

Use ConcurrentHashMap for online SkyPvP participants

Remove session on leave/kick/quit

Ensure server shutdown persists data for all online SkyPvP players (onDisable flush with timeout, best-effort).

YAML Configuration Files

config.yml

world name

spawn location

lobby location

gamemode after respawn (SURVIVAL or ADVENTURE)

spectator seconds

combat time seconds

post-kill combat extra time (10 seconds fixed but keep configurable too)

custom void Y-level

MySQL credentials + pool settings

messages.yml

Every message in the plugin including command help text

Placeholders support (at minimum internal placeholders; optionally PlaceholderAPI hook if present)

killstreaks.yml

Milestones keyed by kill count (e.g., 5, 10, 15)

Each milestone supports:

message to player

broadcast to SkyPvP world only

titles (1.8 compatible title API)

coin rewards

console commands list (with placeholder replacement)

prestige.yml

Prestige thresholds (kills required per prestige level or list of thresholds)

Prestige-up message template(s)

Commands, Permissions, and Behavior
Root Command: /skypvp

Subcommands:

/skypvp join

/skypvp leave

/skypvp setlobby (admin)

/skypvp setspawn (admin) (required even if not explicitly requested; needed for spawn)

/skypvp setkit (admin)

/skypvp coins

/skypvp pay  

/skypvp coins add   (admin)

/skypvp coins set   (admin)

/skypvp coins remove   (admin)

Optional but recommended: /skypvp stats (player view stats) for verifying system

Permissions:

skypvp.use (join/leave/coins/pay/stats)

skypvp.admin (setkit/setspawn/setlobby/coins admin)

Ensure help output in messages.yml and respects permissions.

1) /skypvp join (Strict Logic)

When player runs /skypvp join:

IF FIRST TIME (not initialized in DB):

Teleport to configured SkyPvP spawn.

Give default kit (from kit system).

Mark initialized=true in DB (async write).

Set their “SkyPvP session” active in memory.

IF NOT FIRST TIME:

Load SkyPvP snapshot from DB (async load).

On main thread:

Restore inventory + armor

Restore active potion effects

Teleport to last saved SkyPvP location (x,y,z,yaw,pitch)

Set their “SkyPvP session” active in memory.

Must store/restore:

Inventory + armor

Potion effects

Exact location (including yaw/pitch)

Saving Conditions (Must Always Save on These)

The plugin must persist a SkyPvP player snapshot (inventory, armor, effects, last location) to MySQL when:

Player executes /skypvp leave

Player disconnects (quit)

Player is kicked

Server shuts down / plugin disables

Implementation details:

Use listeners: PlayerQuitEvent, PlayerKickEvent

Also handle world change if you allow leaving via other means: if player teleports out of SkyPvP world without /skypvp leave, you must still save snapshot and end session (configurable: either prevent leaving or auto-save & treat as leave).

Ensure the final location saved is the player’s actual SkyPvP world position at the time of leaving.

2) Statistics System (MySQL)

Track per-player:

kills

deaths

K/D ratio (computed automatically, avoid division by zero)

current killstreak

highest killstreak

total prestige level

Rules:

Update stats reliably on every kill/death/void death.

Must never “miss” kill awards due to timing or combat edge cases.

3) Combat System (CRITICAL, Must Be Reliable)

When Player A damages Player B (in SkyPvP world only):

Both enter combat.

Start/refresh a combat timer for both (configurable duration).

Store “last attacker” mapping for B (UUID of attacker, and timestamp).

While in combat:

/skypvp leave is blocked and sends configurable message.

If they disconnect, apply combat log penalty (configurable actions):

Count as death

Award kill to last attacker (if valid)

Optionally drop inventory (but for this plugin, follow your death rules; ensure kit items handling remains correct)

Reset killstreak

On kill:

Victim receives configurable message:

"You were killed by  who had  hearts remaining."

Killer receives configurable message:

"You killed  and you have  hearts remaining."

After kill:

Killer remains in combat for 10 seconds (configurable but default 10)

Victim leaves combat instantly

Victim receives:

"You are no longer in combat. You may logout" (configurable)

Combat must be implemented with a CombatManager that:

Tracks combat end timestamps per player

Provides isInCombat(UUID) and getRemainingSeconds(UUID)

Handles scheduling a lightweight repeating task or per-player delayed tasks without task spam

Use safe checks to avoid memory leaks (remove on quit/leave).

4) Void System (Configurable Height)

Config: custom-void-y: 

When player’s Y position drops below this level (SkyPvP world only):

If NOT in combat:

Count as death only (no special message)

Trigger respawn sequence

If IN combat:

Award kill to last attacker (must be valid within combat rules)

Trigger respawn sequence

Implementation:

Use a lightweight repeating task that checks only players currently in SkyPvP world (or only session players) every few ticks, OR use PlayerMoveEvent with careful optimization (avoid heavy logic per move). Prefer scheduled check to reduce event spam.

5) Respawn Sequence (STRICT ORDER, Must Always Execute)

The respawn logic must always execute in this exact order:

Player dies.

Set gamemode to SPECTATOR.

Clear inventory and potion effects.

Allow flying around death area (do NOT teleport immediately).

Wait configurable seconds (spectator-seconds).

Teleport to SkyPvP spawn.

Set gamemode to SURVIVAL or ADVENTURE (configurable).

Give default kit.

Reset killstreak counter.

Requirements:

Works for normal deaths and void deaths.

Must not break if the player respawns automatically; you must control the process via events:

Listen to PlayerDeathEvent and PlayerRespawnEvent

Suppress default death messages (and ensure console doesn’t log them)

Ensure the player is placed into spectator without teleporting immediately

Ensure that “clear inventory” happens after death but before kit re-give.

Kit is given only after step 7 completes.

6) Prestige System (Automatic)

Configurable kill thresholds (prestige.yml).

When a player reaches the configured threshold:

Automatically increase prestige level

Send configurable prestige message

Persist prestige in DB async

No commands needed.

Decide how thresholds work:

Option A: kills required per prestige level (list/map)

Option B: formula-based (base + increment)

Implement the config as a list/map and document it.

7) Killstreak System

Milestones configured in killstreaks.yml (e.g., 5, 10, 15…).
At each milestone:

Send custom message to player

Broadcast custom message to SkyPvP world only

Optionally execute console commands

Optionally give coins

Optionally send titles/messages
All fully configurable, with placeholders like:

{player}, {kills}, {killstreak}, {prestige}, {coins}

8) Kit System (NBT Tagging + No Drops)

Default kit rules:

Given only:

On first /skypvp join

After respawn sequence completes

Default kit items cannot be dropped.

Identify kit items using NBT tags (1.8 NMS/CraftItemStack):

Add a boolean tag like skypvp_kit=true

On item drop, cancel if tagged

Also prevent moving kit items into certain exploits if desired (optional): e.g., prevent dropping via inventory click outside
Admin command:

/skypvp setkit

Saves the executing admin’s current inventory + armor as the default kit (to kit.yml or within config)

Must serialize items safely to YAML (base64 ItemStack serialization recommended)

Preserve enchantments, names, lore, etc.

9) Mode-Specific Economy (Coins)

Coins are separate for SkyPvP only.
Commands:

/skypvp coins (view own coins)

/skypvp pay   (transfer coins, must validate)
Admin:

/skypvp coins add  

/skypvp coins set  

/skypvp coins remove  
Rules:

All updates stored in MySQL async

Use atomic operations to avoid race conditions (transaction or single UPDATE with checks)

Validate non-negative balances and amounts

10) Lobby & Leave System

Admin:

/skypvp setlobby sets the lobby return location (any world)
Player:

/skypvp leave

Only allowed if not in combat

Teleport to lobby

Save SkyPvP snapshot (inventory, armor, effects, location) before leaving (location is last SkyPvP location)

End SkyPvP session in memory
Also ensure /skypvp join can be used from lobby/anywhere.

Message Handling (Must Be Fully Configurable)

Every user-facing string must come from messages.yml (including help, errors, join/leave, combat messages, cooldowns, prestige, coins).

Support color codes &.

Provide a MessageManager with placeholder replacement.

Optionally integrate PlaceholderAPI if present, but must work without it.

Production Plugin Structure (Must Output Full Class Organization)

Generate a complete project layout with packages like:

com.yourname.skypvp.SkyPvPPlugin (main)

com.yourname.skypvp.config

ConfigManager (loads config.yml/messages.yml/killstreaks.yml/prestige.yml/kit.yml)

com.yourname.skypvp.command

SkyPvPCommand (subcommand router)

Subcommand classes: JoinCommand, LeaveCommand, SetKitCommand, SetSpawnCommand, SetLobbyCommand, CoinsCommand, PayCommand, StatsCommand

com.yourname.skypvp.listener

CombatListener (EntityDamageByEntityEvent, etc.)

DeathListener (PlayerDeathEvent, PlayerRespawnEvent)

QuitKickListener (PlayerQuitEvent, PlayerKickEvent)

WorldListener (prevent unwanted behavior outside world)

ItemProtectionListener (PlayerDropItemEvent, InventoryClickEvent as needed)

com.yourname.skypvp.manager

ModeManager (session tracking, join/leave orchestration)

CombatManager

StatsManager

EconomyManager

PrestigeManager

KillstreakManager

KitManager

VoidManager (task-based Y-check)

RespawnManager (strict ordered sequence control)

com.yourname.skypvp.storage

Storage interface

MySqlStorage (HikariCP)

SqlSchema / migrations helper (create tables on startup)

com.yourname.skypvp.model

PlayerSnapshot (inv/armor/effects/location)

PlayerStats

PlayerEconomy

PlayerSession (in-memory state: inMode, inCombat, lastAttacker, etc.)

com.yourname.skypvp.util

ItemSerializer (base64)

LocationUtil

NbtUtil (1.8 NMS tagging)

TaskUtil (main-thread callbacks from async)

Include plugin.yml with commands and permissions.

Database Schema (Must Provide)

Provide table designs (with indexes):

skypvp_players (uuid PK, initialized, last_world, x,y,z,yaw,pitch, inventory_blob, armor_blob, effects_blob, last_updated)

skypvp_stats (uuid PK, kills, deaths, current_killstreak, highest_killstreak, prestige)

skypvp_economy (uuid PK, coins)
Use appropriate data types (e.g., BINARY(16) for UUID optimized if implementing, or CHAR(36) if keeping simple; but be consistent).
Add indexes where needed.

Critical Edge Cases to Handle

Player dies while in combat → ensure correct kill attribution.

Void death while in combat → award kill to last attacker reliably.

Combat timeout: attacker mapping expires with timer.

Player logs out while in combat → penalty applies and awards kill if valid.

Prevent /skypvp leave in combat always.

Ensure kit items are removed on death before respawn kit (strict sequence).

Ensure no death messages are broadcast or logged.

Ensure saving occurs on kick/quit/disable without blocking shutdown.

Ensure only SkyPvP world is affected (no cross-world interference).

Output Expectations for the Generator

Produce:

Full Java source code for all classes above (clean, commented, production style)

Full plugin.yml

Default config.yml, messages.yml, killstreaks.yml, prestige.yml, kit.yml templates

SQL table creation statements (or automatic creation in code)

Notes in code comments on thread safety (what runs async vs sync)

Make sure the final plugin is complete, compiles, and is suitable for real server use on Paper 1.8.x.
Kodari AI
KodariMar 3 at 9:20 pm 55,985 (v2)

I’ll plan the full architecture before writing a single line:

Plan:

  • 50 Java classes across 9 packages + 6 resource files + build config

  • Storage interface with sync methods called exclusively from async threads, bounced back via TaskUtil

  • Combat via timestamp-based expiry in PlayerSession (no per-player task spam)

  • Void via single repeating sync task over session players

  • NbtUtil + TitleUtil via reflection (version-safe across 1.8.x sub-versions)

  • All messages from messages.yml, all config-driven

  • HikariCP via manifest.kod, no shading

SkyPvP
A full-featured SkyPvP mode plugin that runs inside a single configured world on a shared Paper 1.8.8 server. Features MySQL async persistence (HikariCP), kit-based combat, NBT-tagged item protection, combat logging, void death detection, configurable killstreak milestones, automatic prestige, mode-isolated coin economy, spectator respawn sequences, and complete YAML-driven configuration for all messages and game rules.

The complete SkyPvP plugin has been generated with all 50 files. Here is a summary of every architectural decision made:


Architecture Overview

Data Flow

Plain Text
Player /skypvp join
  → ModeManager.joinMode()
    → [ASYNC] Storage.isInitialized / loadStats / loadEconomy / loadSnapshot
    → [SYNC via TaskUtil] Create PlayerSession, restore inventory + location

Thread Safety Model

Layer
Thread
All Storage methods
Called only from async threads
All Bukkit API (inventory, teleport, gamemode)
Always bounced to main via
TaskUtil.sync()
ConcurrentHashMap<UUID, PlayerSession>
sessions
Thread-safe reads from both threads
onDisable flush
Best-effort sync save before pool shutdown

Key Systems

Combat — Timestamp-based (System.currentTimeMillis() < combatExpiry) stored in PlayerSession. No per-player tasks. One CombatManager provides the entire API.

Void — Single repeating syncTimer every 10 ticks checking only active session UUIDs. No PlayerMoveEvent overhead.

Respawn Sequence — PlayerDeathEvent → clears drops/message → handleDeath() → PlayerRespawnEvent sets location back to death point → 1-tick later → startSpectatorPhase() (SPECTATOR + countdown) → completeRespawn() (teleport + SURVIVAL + kit).

Kit Tags — Fully reflection-based NbtUtil detects server version string at class load via Bukkit.getServer().getClass().getPackage().getName(). Works on v1_8_R1, v1_8_R2, v1_8_R3.

Titles — Same reflection strategy in TitleUtil, falls back to chat message if NMS resolution fails.

Economy Transfer — Single START TRANSACTION / COMMIT / ROLLBACK in MySqlStorage.transferCoins() guaranteeing atomic debit+credit.

Prestige — Automatically triggered after every kill via PrestigeManager.checkPrestige(), reads prestige.yml thresholds map.

Killstreaks — KillstreakManager.checkMilestone() fires on every kill, dispatches message + broadcast + title + coins + console commands from killstreaks.yml.

Build Note

build.gradle depends on org.spigotmc:spigot:1.8.8-R0.1-SNAPSHOT (full server jar, not spigot-api) to compile NMS classes. Run SpigotMC BuildTools for 1.8.8 and mvn install the output before building this project.

flekmoon

[14:23:37 INFO]: [SkyPvP] Enabling SkyPvP v1.0.0 [14:23:37 ERROR]: Error occurred while enabling SkyPvP v1.0.0 (Is it up to date?) java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at org.kodari.libs.c6c9d546.com.zaxxer.hikari.HikariConfig.<clinit>(HikariConfig.java:48) ~[?:?] at com.skypvp.storage.MySqlStorage.initPool(MySqlStorage.java:30) ~[?:?] at com.skypvp.storage.MySqlStorage.<init>(MySqlStorage.java:25) ~[?:?] at com.skypvp.SkyPvPPlugin.onEnable(SkyPvPPlugin.java:56) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[patched_1.8.8.jar:git-PaperSpigot-445] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [patched_1.8.8.jar:git-PaperSpigot-445] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:407) [patched_1.8.8.jar:git-PaperSpigot-445] at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:359) [patched_1.8.8.jar:git-PaperSpigot-445] at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:318) [patched_1.8.8.jar:git-PaperSpigot-445] at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:408) [patched_1.8.8.jar:git-PaperSpigot-445] at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:372) [patched_1.8.8.jar:git-PaperSpigot-445] at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:327) [patched_1.8.8.jar:git-PaperSpigot-445] at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:267) [patched_1.8.8.jar:git-PaperSpigot-445] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:563) [patched_1.8.8.jar:git-PaperSpigot-445] at java.lang.Thread.run(Thread.java:833) [?:?] Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:445) ~[?:?] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:102) ~[patched_1.8.8.jar:git-PaperSpigot-445] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:87) ~[patched_1.8.8.jar:git-PaperSpigot-445] at java.lang.ClassLoader.loadClass(ClassLoader.java:587) ~[?:?] at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] ... 15 more [14:23:37 INFO]: [SkyPvP] Disabling SkyPvP v1.0.0 [14:23:37 INFO]: [SkyPvP] SkyPvP disabled.

Kodari can make mistakes. Review important code before using.
Files
src
.gitignore
build.gradle
manifest.kod
Code
53 3,184
src/main/java/com/skypvp/SkyPvPPlugin.java
package com.skypvp;

import com.skypvp.command.SkyPvPCommand;
import com.skypvp.config.ConfigManager;
import com.skypvp.inventory.gui.GUIListener;
import com.skypvp.inventory.gui.GUIManager;
import com.skypvp.listener.CombatListener;
import com.skypvp.listener.DeathListener;
import com.skypvp.listener.ItemProtectionListener;
import com.skypvp.listener.QuitKickListener;
import com.skypvp.listener.WorldListener;
import com.skypvp.manager.CombatManager;
import com.skypvp.manager.EconomyManager;
import com.skypvp.manager.KillstreakManager;
import com.skypvp.manager.KitManager;
import com.skypvp.manager.ModeManager;
import com.skypvp.manager.PrestigeManager;
import com.skypvp.manager.RespawnManager;
import com.skypvp.manager.StatsManager;
import com.skypvp.manager.VoidManager;
import com.skypvp.storage.MySqlStorage;
import com.skypvp.storage.Storage;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public final class SkyPvPPlugin extends JavaPlugin {

    private ConfigManager configManager;
    private Storage storage;
    private ModeManager modeManager;
    private CombatManager combatManager;
    private StatsManager statsManager;
    private EconomyManager economyManager;
    private PrestigeManager prestigeManager;
    private KillstreakManager killstreakManager;
    private KitManager kitManager;
    private VoidManager voidManager;
    private RespawnManager respawnManager;
    private GUIManager guiManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        saveResourceIfAbsent("messages.yml");
        saveResourceIfAbsent("killstreaks.yml");
        saveResourceIfAbsent("prestige.yml");
        saveResourceIfAbsent("kit.yml");

        configManager = new ConfigManager(this);
        configManager.load();

        storage = new MySqlStorage(this);
        storage.createTables();

        combatManager = new CombatManager(this);
        statsManager = new StatsManager(this);
        economyManager = new EconomyManager(this);
        prestigeManager = new PrestigeManager(this);
        killstreakManager = new KillstreakManager(this);
        kitManager = new KitManager(this);
        respawnManager = new RespawnManager(this);
        modeManager = new ModeManager(this);
        voidManager = new VoidManager(this);
        guiManager = new GUIManager();

        voidManager.startTask();

        registerListeners();
        registerCommands();

        getLogger().info("SkyPvP enabled successfully.");
    }

    @Override
    public void onDisable() {
        if (voidManager != null) {
            voidManager.stopTask();
        }
        if (modeManager != null) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (modeManager.isInMode(player.getUniqueId())) {
                    modeManager.saveAndRemoveSession(player, true);
                }
            }
        }
        if (storage != null) {
            storage.shutdown();
        }
        getLogger().info("SkyPvP disabled.");
    }

    private void registerListeners() {
        PluginManager pm = Bukkit.getPluginManager();
        pm.registerEvents(new CombatListener(this), this);
        pm.registerEvents(new DeathListener(this), this);
        pm.registerEvents(new QuitKickListener(this), this);
        pm.registerEvents(new WorldListener(this), this);
        pm.registerEvents(new ItemProtectionListener(this), this);
        pm.registerEvents(new GUIListener(guiManager), this);
    }

    private void registerCommands() {
        SkyPvPCommand cmd = new SkyPvPCommand(this);
        getCommand("skypvp").setExecutor(cmd);
        getCommand("skypvp").setTabCompleter(cmd);
    }

    private void saveResourceIfAbsent(String name) {
        java.io.File file = new java.io.File(getDataFolder(), name);
        if (!file.exists()) {
            saveResource(name, false);
        }
    }
}