theRealBTVR

I want a plugin that works on JAVA 26.3. I want it to be where if you get killed by any player you gain a negative effect in which the operators can change the loot pool of what you can get, as well as your head dropping. But if you kill a player, You gain a random positive effect that the operators can decide the loot pool. If you get killed by a mob, fall damage, anything other than a player, you dont gain or lose any effects. If you kill a player while having a negative effect, You lose a negative effect. If you have all the possible negative effects you can, you get banned from the server.

Kodari AI
KodariTue at 11:49 pm 2
PlayerCombatEffects
A Minecraft plugin for Java 26.3 that applies effects on player kills and deaths. When a player is killed by another player, the victim receives a random negative effect from an operator-configurable loot pool and drops their head. The killer receives a random positive effect from a separate configurable loot pool. Deaths by mobs, fall damage, or other non-player causes grant no effects. Killing a player while having a negative effect removes one negative effect. If a player accumulates all possible negative effects, they are automatically banned from the server. Operators can edit both loot pools via configuration files.
  • Track configured positive and negative effects across deaths and reconnects.

  • Drop the victim’s head and ban players who collect every configured negative effect.

  • Add a reload command so operators can change the effect pools.

Created the plugin with persistent effect pools, player-head drops on PvP deaths, and bans when a player collects every configured negative effect.

Operators can edit config.yml and run /playereffects reload. An empty negative pool disables bans. Non-player deaths don’t change tracked effects.

theRealBTVR

Is there commands for it?

Kodari AI
KodariTue at 11:52 pm 1

Yes. The plugin currently has one command:

  • /playereffects reload — reloads the effect pools after you edit config.yml.

It requires the playereffects.admin permission, which operators have by default.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 252
src/main/java/com/kodari/playereffects/PlayerEffectsPlugin.java
package com.kodari.playereffects;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public final class PlayerEffectsPlugin extends JavaPlugin implements Listener {
    private File dataFile;
    private YamlConfiguration data;
    private List<String> positivePool = List.of();
    private List<String> negativePool = List.of();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        dataFile = new File(getDataFolder(), "players.yml");
        data = YamlConfiguration.loadConfiguration(dataFile);
        loadPools();
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("playereffects").setExecutor((sender, command, label, args) -> {
            if (args.length != 1 || !args[0].equalsIgnoreCase("reload")) {
                sender.sendMessage(ChatColor.RED + "Usage: /playereffects reload");
                return true;
            }
            reloadConfig();
            loadPools();
            sender.sendMessage(ChatColor.GREEN + "Player effect pools reloaded.");
            return true;
        });
        getServer().getScheduler().runTaskTimer(this, () -> {
            for (Player player : Bukkit.getOnlinePlayers()) {
                applyEffects(player);
            }
        }, 1L, 200L);
    }

    private void loadPools() {
        negativePool = readPool("negative-effects");
        positivePool = readPool("positive-effects");
    }

    private List<String> readPool(String path) {
        Set<String> names = new LinkedHashSet<>();
        Set<PotionEffectType> types = new LinkedHashSet<>();
        for (String value : getConfig().getStringList(path)) {
            String name = value.trim().toUpperCase(Locale.ROOT);
            PotionEffect effect = createEffect(name);
            if (effect == null) {
                getLogger().warning("Unknown effect in " + path + ": " + value);
            } else if (types.add(effect.getType())) {
                names.add(name);
            }
        }
        return List.copyOf(names);
    }

    private PotionEffect createEffect(String name) {
        int amplifier = Math.max(0, Math.min(255, getConfig().getInt("amplifier", 0)));
        return XPotion.matchXPotion(name)
                .map(effect -> effect.buildPotionEffect(Integer.MAX_VALUE, amplifier))
                .orElse(null);
    }

    private Set<String> effects(UUID id, String category) {
        return new LinkedHashSet<>(data.getStringList(id + "." + category));
    }

    private void saveEffects(UUID id, String category, Set<String> effects) {
        data.set(id + "." + category, new ArrayList<>(effects));
    }

    private void saveData() {
        try {
            data.save(dataFile);
        } catch (IOException ex) {
            getLogger().severe("Could not save player effects: " + ex.getMessage());
        }
    }

    private String randomEntry(List<String> choices) {
        return choices.get(ThreadLocalRandom.current().nextInt(choices.size()));
    }

    private void applyEffects(Player player) {
        Set<String> all = effects(player.getUniqueId(), "positive");
        all.addAll(effects(player.getUniqueId(), "negative"));
        for (String name : all) {
            PotionEffect effect = createEffect(name);
            if (effect != null) {
                player.addPotionEffect(effect, true);
            }
        }
    }

    @EventHandler
    public void onDeath(PlayerDeathEvent event) {
        Player victim = event.getEntity();
        EntityDamageEvent cause = victim.getLastDamageCause();
        if (!(cause instanceof EntityDamageByEntityEvent damage)) {
            return;
        }
        Entity attacker = damage.getDamager();
        if (attacker instanceof Projectile projectile && projectile.getShooter() instanceof Player shooter) {
            attacker = shooter;
        }
        if (!(attacker instanceof Player killer) || killer.getUniqueId().equals(victim.getUniqueId())) {
            return;
        }

        ItemStack head = XMaterial.matchXMaterial("PLAYER_HEAD").map(XMaterial::parseItem).orElse(null);
        if (head != null && head.getItemMeta() instanceof SkullMeta meta) {
            meta.setOwningPlayer(victim);
            head.setItemMeta(meta);
            event.getDrops().add(head);
        }

        UUID victimId = victim.getUniqueId();
        Set<String> victimNegative = effects(victimId, "negative");
        List<String> availableNegative = new ArrayList<>(negativePool);
        availableNegative.removeAll(victimNegative);
        if (!availableNegative.isEmpty()) {
            String added = randomEntry(availableNegative);
            victimNegative.add(added);
            victim.sendMessage(ChatColor.RED + "You gained a negative effect: " + added);
        }
        saveEffects(victimId, "negative", victimNegative);

        UUID killerId = killer.getUniqueId();
        Set<String> killerNegative = effects(killerId, "negative");
        if (!killerNegative.isEmpty()) {
            String removed = randomEntry(new ArrayList<>(killerNegative));
            killerNegative.remove(removed);
            saveEffects(killerId, "negative", killerNegative);
            PotionEffect removedEffect = createEffect(removed);
            if (removedEffect != null) {
                killer.removePotionEffect(removedEffect.getType());
            }
            killer.sendMessage(ChatColor.GREEN + "You lost a negative effect: " + removed);
        }
        Set<String> killerPositive = effects(killerId, "positive");
        List<String> availablePositive = new ArrayList<>(positivePool);
        availablePositive.removeAll(killerPositive);
        if (!availablePositive.isEmpty()) {
            String added = randomEntry(availablePositive);
            killerPositive.add(added);
            saveEffects(killerId, "positive", killerPositive);
            killer.sendMessage(ChatColor.GREEN + "You gained a positive effect: " + added);
        }
        saveData();
        applyEffects(killer);

        if (!negativePool.isEmpty() && victimNegative.containsAll(negativePool)) {
            String reason = ChatColor.translateAlternateColorCodes('&', getConfig().getString("ban-reason", "You collected every negative effect."));
            Bukkit.getBanList(BanList.Type.NAME).addBan(victim.getName(), reason, null, getName());
            getServer().getScheduler().runTask(this, () -> {
                if (victim.isOnline()) {
                    victim.kickPlayer(reason);
                }
            });
        }
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        getServer().getScheduler().runTask(this, () -> applyEffects(event.getPlayer()));
    }

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