Inq Deepu

Act as an expert Minecraft Spigot/Paper Plugin Developer. Fix the data persistence and rejoin bug in my custom PerWorldLifesteal plugin for Paper 1.20+.

Bug Description:

When players leave and rejoin the server while inside a Whitelisted Lifesteal world, their max health resets back to default 20.0 HP (10 Hearts) instead of restoring their saved hearts from data.yml.

Requirements & Fixes to Implement:

  1. Data Management (data.yml):

- Use UUIDs as keys (players.<UUID>) in data.yml to store max health values (e.g., 30.0 for 15 hearts). - Ensure a robust saveData() method that writes to disk immediately whenever health changes, on PlayerQuit, and on Server Shutdown (onDisable).

  1. Delayed Health Restoration on Join (CRITICAL FIX):

- In PlayerJoinEvent, do NOT set health immediately on the main thread frame. - Use Bukkit.getScheduler().runTaskLater(plugin, () -> { ... }, 1L) (1-tick delay) to allow Paper/Spigot to fully process the player join and world loading. - Inside the delayed task, check if the player's current world is in enabled-worlds from config.yml. - If YES: Fetch saved HP from data.yml (default 20.0 if new) and set Attribute.GENERIC_MAX_HEALTH base value. - If NO: Set Attribute.GENERIC_MAX_HEALTH base value to 20.0 HP (10 Hearts).

  1. Instant Save on Quit & World Change:

- In PlayerQuitEvent: If the player is leaving from a Whitelisted Lifesteal world, save their current Attribute.GENERIC_MAX_HEALTH base value to data.yml and call saveData() immediately. - In PlayerChangedWorldEvent: * When moving FROM Lifesteal world TO Non-Lifesteal world: Save current Lifesteal HP to data.yml, call saveData(), then set current max health to 20.0 HP. * When moving FROM Non-Lifesteal world TO Lifesteal world: Load saved HP from data.yml and set max health.

  1. Lifesteal Combat Mechanics:

- Handle PlayerDeathEvent: When a player is killed by another player inside a whitelisted world, deduct 2.0 HP (1 heart) from the victim and add 2.0 HP (1 heart) to the killer (respecting min-hearts and max-hearts from config.yml). - Immediately update both players' values in data.yml and call saveData().

Output Deliverables:

Provide the complete, fully written Java source code for all classes (PerWorldLifestealPlugin, LifestealListener, LifestealManager, HealthDataStore), along with full imports and no pseudocode or placeholders, so it can be re-compiled straight into a working .jar file.

Kodari AI
KodariSep 22 at 7:18 am 1
PerWorldLifesteal
A comprehensive Minecraft plugin that implements per-world health management with lifesteal combat mechanics. Features UUID-based health persistence in data.yml, delayed health restoration on player join to prevent rejoin bugs, instant health saving on quit and world changes, and heart-stealing combat where killers gain hearts from victims within whitelisted worlds. Includes configurable min/max heart limits and automatic health reset in non-whitelisted worlds.

I’ll create a complete Paper plugin project with:

  1. UUID-backed HealthDataStore persistence and immediate disk saves.

  2. LifestealManager for world checks, health restoration, clamping, and combat updates.

  3. Event handling for delayed joins, quit, world changes, deaths, and shutdown.

  4. Paper resources and Gradle metadata needed to compile and load the plugin.

Created the complete PerWorldLifesteal plugin project with:

  • UUID-based data.yml persistence under players.<UUID>.

  • Immediate saves on health changes, quit, world changes, and shutdown.

  • One-tick delayed health restoration after joining.

  • Lifesteal/non-lifesteal world transitions.

  • Player death health transfer with configurable min-hearts and max-hearts.

  • Full Java classes:

    • PerWorldLifestealPlugin

    • LifestealListener

    • LifestealManager

    • HealthDataStore

  • plugin.yml, config.yml, build.gradle, and settings.gradle.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
8 305
src/main/java/com/example/perworldlifesteal/PerWorldLifestealPlugin.java
package com.example.perworldlifesteal;

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

public final class PerWorldLifestealPlugin extends JavaPlugin {

    private HealthDataStore healthDataStore;
    private LifestealManager lifestealManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        this.healthDataStore = new HealthDataStore(this);
        this.lifestealManager = new LifestealManager(this, healthDataStore);

        Bukkit.getPluginManager().registerEvents(new LifestealListener(this, lifestealManager), this);
    }

    @Override
    public void onDisable() {
        if (lifestealManager != null) {
            lifestealManager.saveOnlinePlayers();
        }

        if (healthDataStore != null) {
            healthDataStore.saveData();
        }
    }
}