Codrin

Hello am here to say if you can make me and plugin about Immortality as am making my first ever scripted smp I would like one because as protags I don't want main characters to die which will ruin the story line so make me so when you get to 0.5 hearts from then any player can't hit the player that's in Immortality mode and make it like unstable smp where sometime you regen not all the time and make it look real and not regening all the time and also so you can pop totems because that will look like vanilla minecraft only if they are holding a totem. And also when totem pop make sure it doesn't regen instantly I want it like vanilla minecraft but when 0.5 hearts they can't mace,sword or anything that takes damage and also to when they reach 2 hearts they can take some regen and make sure it doesn't show the particles when regening because that is not vanilla minecraft and also don't make it obvious for people that watch the video because that will look like scripted content

Commands for Immortality /Immortality (player) /Immortality (list) /Immortality (remove) Make sure everything works

Another mode

So I want another more for the Immortality So basically what I want is that there's a mode where they can stay on half a heart And nobody can mace or anything but they can punch but they won't die also no regen since they can only stay on half a heart make sure this is prefect because if not it will ruin the event

Here are the commands /Violent (Player) /Violent (Remove) /Violent (List) Please make sure everything works

Kodari AI
KodariOct 9 at 6:58 pm 2
ImmortalitySystem
A Minecraft plugin providing two protected-player modes for scripted SMPs. Immortality mode activates when a player drops to 0.5 hearts, preventing all damage sources (swords, maces, projectiles, etc.) until they naturally regenerate to 2 hearts, at which point limited regen resumes. Totems still pop normally with vanilla behavior and no instant regen. No particles or visual indicators reveal the protection. Violent mode locks players permanently at half a heart with no regeneration, allowing only unarmed punches that deal no lethal damage. Both modes include admin commands for adding, removing, and listing protected players, ensuring seamless scripted storytelling without breaking immersion.
  1. Create the plugin scaffold and persistent, intermittent-healing Immortality mode with its commands.

  2. Add the persistent half-heart Violent mode, bare-hand-only PvP, and its commands.

Created the Immortality plugin with persistent modes and admin-only commands (operators by default).

  • /immortality <player> enables intermittent, particle-free healing; lethal damage stops at half a heart. Totems still work, with vanilla regeneration preserved after a pop.

  • /immortality list lists players in the mode. /immortality remove [player] removes the mode from the named player, or from you if no player is given.

  • /violent <player> holds the player at half a heart, blocks damage and healing, and allows bare-hand hits while blocking hits with held items.

  • /violent list lists players in the mode. /violent remove [player] removes the mode from the named player, or from you if no player is given.

Mode assignments are saved across restarts.

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

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.StringJoiner;
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public final class ImmortalityPlugin extends JavaPlugin implements Listener {
    private static final double HALF_HEART = 1.0;
    private static final double LOW_HEALTH_THRESHOLD = 4.0;
    private static final long TOTEM_REGEN_MILLIS = 40_000L;

    private final Set<UUID> immortalityPlayers = new HashSet<>();
    private final Set<UUID> violentPlayers = new HashSet<>();
    private final java.util.Map<UUID, Long> totemRegenUntil = new java.util.HashMap<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadModes();
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("immortality").setExecutor(this);
        getCommand("violent").setExecutor(this);
        getServer().getScheduler().runTaskTimer(this, this::applyIntermittentHealing, 20L, 20L);
    }

    @Override
    public void onDisable() {
        saveModes();
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        boolean immortality = command.getName().equalsIgnoreCase("immortality");
        return handleModeCommand(sender, args, immortality);
    }

    private boolean handleModeCommand(CommandSender sender, String[] args, boolean immortality) {
        String modeName = immortality ? "Immortality" : "Violent";
        Set<UUID> modePlayers = immortality ? immortalityPlayers : violentPlayers;

        if (args.length == 0) {
            sender.sendMessage("§cUsage: /" + (immortality ? "immortality" : "violent") + " <player|list|remove [player]>");
            return true;
        }

        if (args[0].equalsIgnoreCase("list")) {
            sendPlayerList(sender, modeName, modePlayers);
            return true;
        }

        if (args[0].equalsIgnoreCase("remove")) {
            UUID targetId;
            if (args.length >= 2) {
                targetId = findStoredPlayer(args[1], modePlayers);
                if (targetId == null) {
                    sender.sendMessage("§cNo " + modeName + " player named " + args[1] + " was found.");
                    return true;
                }
            } else if (sender instanceof Player player) {
                targetId = player.getUniqueId();
            } else {
                sender.sendMessage("§cUsage: /" + (immortality ? "immortality" : "violent") + " remove <player>");
                return true;
            }

            modePlayers.remove(targetId);
            saveModes();
            Player target = Bukkit.getPlayer(targetId);
            String targetName = target == null ? getOfflineName(targetId) : target.getName();
            sender.sendMessage("§aRemoved " + targetName + " from " + modeName + " mode.");
            if (target != null && target != sender) {
                target.sendMessage("§eYour " + modeName + " mode has been removed.");
            }
            return true;
        }

        Player target = Bukkit.getPlayerExact(args[0]);
        if (target == null) {
            sender.sendMessage("§cThat player must be online to enable " + modeName + " mode.");
            return true;
        }

        UUID targetId = target.getUniqueId();
        modePlayers.add(targetId);
        if (immortality) {
            violentPlayers.remove(targetId);
        } else {
            immortalityPlayers.remove(targetId);
            target.setHealth(HALF_HEART);
        }
        saveModes();
        sender.sendMessage("§aEnabled " + modeName + " mode for " + target.getName() + ".");
        if (target != sender) {
            target.sendMessage("§eYour " + modeName + " mode has been enabled.");
        }
        return true;
    }

    private void sendPlayerList(CommandSender sender, String modeName, Set<UUID> players) {
        if (players.isEmpty()) {
            sender.sendMessage("§eNo players are currently in " + modeName + " mode.");
            return;
        }

        TreeSet<String> names = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        for (UUID id : players) {
            names.add(getOfflineName(id));
        }
        StringJoiner joinedNames = new StringJoiner("§7, §f");
        names.forEach(joinedNames::add);
        sender.sendMessage("§e" + modeName + " players: §f" + joinedNames);
    }

    private UUID findStoredPlayer(String name, Set<UUID> players) {
        Player online = Bukkit.getPlayerExact(name);
        if (online != null && players.contains(online.getUniqueId())) {
            return online.getUniqueId();
        }
        for (UUID id : players) {
            String storedName = Bukkit.getOfflinePlayer(id).getName();
            if (storedName != null && storedName.equalsIgnoreCase(name)) {
                return id;
            }
        }
        return null;
    }

    private String getOfflineName(UUID id) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(id);
        return player.getName() == null ? id.toString() : player.getName();
    }

    private void loadModes() {
        immortalityPlayers.clear();
        violentPlayers.clear();
        readIds("modes.immortality", immortalityPlayers);
        readIds("modes.violent", violentPlayers);
    }

    private void readIds(String path, Set<UUID> destination) {
        for (String value : getConfig().getStringList(path)) {
            try {
                destination.add(UUID.fromString(value));
            } catch (IllegalArgumentException ignored) {
                getLogger().warning("Ignoring invalid player UUID in " + path + ": " + value);
            }
        }
    }

    private void saveModes() {
        getConfig().set("modes.immortality", new ArrayList<>(immortalityPlayers.stream().map(UUID::toString).toList()));
        getConfig().set("modes.violent", new ArrayList<>(violentPlayers.stream().map(UUID::toString).toList()));
        saveConfig();
    }

    private void applyIntermittentHealing() {
        long now = System.currentTimeMillis();
        for (UUID id : immortalityPlayers) {
            Player player = Bukkit.getPlayer(id);
            if (player == null || player.isDead() || player.getHealth() >= player.getMaxHealth() || isTotemRegenActive(id, now)) {
                continue;
            }

            double chance = player.getHealth() <= LOW_HEALTH_THRESHOLD ? 0.06 : 0.015;
            if (ThreadLocalRandom.current().nextDouble() < chance) {
                player.setHealth(Math.min(player.getMaxHealth(), player.getHealth() + 1.0));
            }
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageEvent event) {
        if (!(event.getEntity() instanceof Player player)) {
            return;
        }

        UUID playerId = player.getUniqueId();
        if (violentPlayers.contains(playerId)) {
            if (event instanceof EntityDamageByEntityEvent byEntity && byEntity.getDamager() instanceof Player attacker) {
                if (!attacker.getInventory().getItemInMainHand().getType().isAir()) {