noobentity

create me a minecraft plugin in which if i kill a player i get a heart and strength 1 and i kill again a player i get another heart and strength 2 it will always repeat and kill player gets you more stronger and stronger

Kodari AI
KodariNov 8 at 6:18 am 1
KillStreakPower
KillStreakPower is a Minecraft Bukkit/Spigot plugin that rewards players for player kills. Each time a player kills another player, they permanently gain one additional heart (max health increased by 2) and one level of Strength effect. The rewards stack indefinitely, so consecutive or cumulative kills make the player progressively stronger with more health and higher Strength levels. The plugin tracks kill counts per player, applies the permanent max health bonus, and refreshes the Strength effect on each kill. Configurable via config.yml for maximum heart cap and Strength level cap. Includes death message customization and permission support for bypassing caps.
  • Save each player’s kill count across restarts.

  • Add one maximum heart and one Strength level per player kill.

  • Restore the bonuses after respawn and when players join.

Created the plugin. Player kills permanently increase maximum health and Strength, with kill counts saved across restarts.

Bonuses cap at 1,024 health and Strength 256.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 119
src/main/java/com/kodari/killstrength/KillStrengthPlugin.java
package com.kodari.killstrength;

import com.cryptomorin.xseries.XAttribute;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;

public final class KillStrengthPlugin extends JavaPlugin implements Listener {
    private File dataFile;
    private YamlConfiguration data;

    @Override
    public void onEnable() {
        dataFile = new File(getDataFolder(), "kills.yml");
        data = YamlConfiguration.loadConfiguration(dataFile);
        getServer().getPluginManager().registerEvents(this, this);
        for (Player player : getServer().getOnlinePlayers()) {
            applyBonuses(player);
        }
        getServer().getScheduler().runTaskTimer(this, () -> {
            for (Player player : getServer().getOnlinePlayers()) {
                applyBonuses(player);
            }
        }, 100L, 100L);
    }

    @EventHandler
    public void onDeath(PlayerDeathEvent event) {
        Player victim = event.getEntity();
        Player killer = victim.getKiller();
        if (killer == null || killer.getUniqueId().equals(victim.getUniqueId())) {
            return;
        }
        String key = killer.getUniqueId().toString();
        long kills = data.getLong(key, 0L);
        if (kills < Long.MAX_VALUE) {
            kills++;
        }
        data.set(key, kills);
        saveKills();
        applyBonuses(killer);
        killer.sendMessage("\u00a7cPlayer kill! \u00a7aTotal kills: " + kills + " \u00a77(+1 heart and Strength level per kill)");
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        applyBonuses(event.getPlayer());
    }

    @EventHandler
    public void onRespawn(PlayerRespawnEvent event) {
        Player player = event.getPlayer();
        getServer().getScheduler().runTask(this, () -> applyBonuses(player));
    }

    private void applyBonuses(Player player) {
        long kills = Math.max(0L, data.getLong(player.getUniqueId().toString(), 0L));
        if (kills == 0L) {
            return;
        }
        XAttribute.of("max_health").ifPresent(attribute -> {
            AttributeInstance health = player.getAttribute(attribute.get());
            if (health != null) {
                health.setBaseValue(Math.min(1024.0, health.getDefaultValue() + Math.min(kills, 512L) * 2.0));
            }
        });
        int amplifier = (int) Math.min(kills - 1L, 255L);
        XPotion.matchXPotion("STRENGTH")
                .map(potion -> potion.buildPotionEffect(220, amplifier))
                .ifPresent(effect -> player.addPotionEffect(effect, true));
    }

    private void saveKills() {
        if (!getDataFolder().exists() && !getDataFolder().mkdirs()) {
            getLogger().severe("Could not create the plugin data folder.");
            return;
        }
        try {
            data.save(dataFile);
        } catch (IOException exception) {
            getLogger().severe("Could not save player kills: " + exception.getMessage());
        }
    }
}