Itzalphadp

Act as an expert Minecraft Spigot/Paper Plugin Developer. Write a complete, production-ready Spigot/Paper plugin (compatible with 1.20+) for a Per-World Lifesteal System with Multiverse support.

Key Requirements & Features:

  1. World Whitelisting:

- Read a list of enabled-worlds from config.yml. - Lifesteal mechanics (gaining/losing hearts on death/kill) must strictly apply ONLY inside these enabled worlds.

  1. Health Separation Logic (Per-World Health):

- When a player leaves an enabled Lifesteal world (via PlayerChangedWorldEvent or PlayerQuitEvent), save their current Lifesteal max health to a data file. - Instantly reset the player's max health back to 20.0 HP (10 default hearts) when they switch to a non-Lifesteal world (like Lobby, Spawn, or Creative). - When the player re-enters an enabled Lifesteal world, restore their saved Lifesteal max health automatically.

  1. Core Lifesteal Mechanics:

- When a player is killed by another player in an enabled world: * Reduce victim's max health by 2.0 HP (1 Heart). * Increase killer's max health by 2.0 HP (1 Heart). - Respect min-hearts and max-hearts limits set in config.yml.

  1. Data Storage:

- Store player health data in a data.yml file so health settings persist across server restarts.

  1. Code Structure Deliverables:

- Complete plugin.yml. - Complete config.yml with default enabled worlds, min-hearts, and max-hearts options. - Fully written, functional Java classes with proper event handling and clean code. Do not use pseudocode or placeholders.

Kodari AI
KodariSep 21 at 6:18 pm 1
PerWorldLifesteal
A Spigot/Paper plugin providing per-world lifesteal mechanics with Multiverse support. Players gain and lose hearts when killing or being killed only in whitelisted worlds. Health is saved per-world and automatically restored when players switch between lifesteal and non-lifesteal worlds. Features configurable enabled worlds, minimum and maximum heart limits, persistent data storage in data.yml, and automatic health reset to 10 hearts when leaving enabled worlds. Includes complete event handling for player deaths, world changes, and server quit events to ensure health states are always correctly managed.
  1. Create the Gradle project and plugin metadata.

  2. Add configuration and persistent data.yml storage.

  3. Implement separated per-world health management and lifesteal events.

  4. Register listeners, initialize online players, and persist data on shutdown.

Created a complete Per-World Lifesteal plugin with:

  • Enabled-world whitelist from config.yml

  • Per-player persistent health in data.yml

  • Health reset to 20 HP in non-lifesteal worlds

  • Automatic health restoration when entering lifesteal worlds

  • Configurable minimum and maximum hearts

  • 2 HP heart transfer on player kills

  • Multiverse-compatible world change handling

  • Join, quit, death, and shutdown persistence

  • Gradle build configuration targeting Paper 1.20.6+ Java 17

Main class: com.kodari.perworldlifesteal.PerWorldLifestealPlugin

Itzalphadp

Fix the data persistence issue in PerWorldLifestealPlugin:

  1. Update PlayerJoinEvent to use a 1-tick delay (Bukkit.getScheduler().runTaskLater(..., 1L)) before checking the player's world and restoring max health from data.yml.
  2. In PlayerQuitEvent, check if the player was in an enabled lifesteal world, save their current max health under players.<UUID> in data.yml, and call saveData().
  3. Re-compile the project into a updated .jar file.
Kodari AI
KodariSep 22 at 6:17 am 1
  1. Delay join health handling by one server tick and guard against offline players.

  2. Preserve quit-time enabled-world checks and persist players.<UUID>.max-health through saveData().

  3. Update all persistence callers and produce the project build artifact through the configured build workflow.

Implemented the persistence fix:

  • PlayerJoinEvent now delays health restoration by 1 tick using Bukkit.getScheduler().runTaskLater(..., 1L).

  • Delayed restoration checks that the player is still online.

  • PlayerQuitEvent continues saving only when the player is in an enabled lifesteal world.

  • Health is stored under players.<UUID>.max-health.

  • Persistence now uses saveData() consistently.

  • Updated listener registration to pass the plugin scheduler context.

The project environment does not include Gradle/Javac, so I could not generate the updated .jar directly here. The modified project is ready to build with:

Shell
./gradlew clean build

The resulting JAR will be located in:

Plain Text
build/libs/
Itzalphadp

​"Please run ./gradlew clean build in the terminal to compile the code and provide me the updated .jar file from the build/libs/ folder."

Kodari AI
KodariSep 22 at 6:21 am 1

I can’t run ./gradlew clean build in this environment because Gradle/build tools are unavailable. No updated JAR can be generated here.

Run locally from the project root:

Shell
./gradlew clean build

The compiled plugin will be at:

Plain Text
build/libs/PerWorldLifesteal-*.jar
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
9 326
src/main/java/com/kodari/perworldlifesteal/PerWorldLifestealPlugin.java
package com.kodari.perworldlifesteal;

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

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

public final class PerWorldLifestealPlugin extends JavaPlugin {

    private LifestealManager lifestealManager;

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

        HealthDataStore dataStore = new HealthDataStore(this);
        dataStore.load();

        Set<String> enabledWorlds = new HashSet<>();
        for (String worldName : getConfig().getStringList("enabled-worlds")) {
            if (worldName != null && !worldName.isBlank()) {
                enabledWorlds.add(worldName.toLowerCase(Locale.ROOT));
            }
        }

        double minHearts = getConfig().getDouble("min-hearts", 1.0D);
        double maxHearts = getConfig().getDouble("max-hearts", 20.0D);
        if (!Double.isFinite(minHearts) || minHearts <= 0.0D) {
            minHearts = 1.0D;
        }
        if (!Double.isFinite(maxHearts) || maxHearts < minHearts) {
            maxHearts = Math.max(20.0D, minHearts);
        }

        lifestealManager = new LifestealManager(
                dataStore,
                enabledWorlds,
                minHearts * 2.0D,
                maxHearts * 2.0D
        );

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

        for (Player player : Bukkit.getOnlinePlayers()) {
            lifestealManager.handleJoin(player);
        }
    }

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