Saad Saadpro

make me a plugin where you have 3 souls and if you re killed 3 times you are banned but you always stay in spectator mode and the one who killed you last will only be able to see you and the one who killed him in the last will see him in blue and when someone is died a title will pop up " @user has been died the third time"

Kodari AI
KodariOct 22 at 4:51 am 1
SoulSpectatorBans
A Minecraft plugin implementing a 3-soul death system. Players start with 3 souls; each death consumes one. Upon the third death, the player is permanently banned and forced into spectator mode. The killer gains the unique ability to see the banned spectator, while the killer's own killer can see them highlighted in blue. A title announcement displays "@user has been died the third time" when the final soul is lost, creating a chain-of-death visibility mechanic.
  1. Add the plugin build and descriptor.

  2. Implement persistent three-soul tracking, bans, spectator respawns, and killer-only visibility with a blue outline.

  3. Show the requested title when a player loses their third soul.

Created ThreeSouls. Players start with three souls; each death removes one, and the third death shows the requested title and bans them. After a death that doesn’t end in a ban, the player enters spectator mode for the configured five seconds, then returns to survival so they can use their remaining souls. Their last killer is the only player who can see them while they spectate, and the spectator has a blue outline.

Soul counts and last killers are saved in players.yml. The spectator delay and ban message are configurable in config.yml.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 303
src/main/java/com/kodari/souls/ThreeSoulsPlugin.java
package com.kodari.souls;

import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
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.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class ThreeSoulsPlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Integer> souls = new HashMap<>();
    private final Map<UUID, UUID> lastKillers = new HashMap<>();
    private final Map<UUID, UUID> spectating = new HashMap<>();
    private final Set<UUID> transitioningToSurvival = new HashSet<>();
    private final Map<UUID, String> previousTeams = new HashMap<>();

    private File playerDataFile;
    private YamlConfiguration playerData;
    private Team blueTeam;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadPlayerData();
        setupBlueTeam();
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        savePlayerData();
        for (UUID playerId : new HashSet<>(spectating.keySet())) {
            Player player = Bukkit.getPlayer(playerId);
            if (player != null) {
                endSpectating(player);
            }
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        UUID playerId = player.getUniqueId();
        souls.putIfAbsent(playerId, getConfig().getInt("starting-souls", 3));

        if (souls.get(playerId) <= 0) {
            banPlayer(player);
            return;
        }

        for (Map.Entry<UUID, UUID> entry : spectating.entrySet()) {
            Player deadPlayer = Bukkit.getPlayer(entry.getKey());
            if (deadPlayer == null) {
                continue;
            }
            if (player.getUniqueId().equals(entry.getValue())) {
                player.showPlayer(this, deadPlayer);
            } else {
                player.hidePlayer(this, deadPlayer);
            }
        }

        UUID killerId = spectating.get(playerId);
        if (spectating.containsKey(playerId)) {
            for (Player viewer : Bukkit.getOnlinePlayers()) {
                if (viewer.getUniqueId().equals(killerId)) {
                    viewer.showPlayer(this, player);
                } else {
                    viewer.hidePlayer(this, player);
                }
            }
        }
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        Player player = event.getPlayer();
        if (spectating.containsKey(player.getUniqueId())) {
            endSpectating(player);
        }
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player player = event.getEntity();
        UUID playerId = player.getUniqueId();
        int remaining = Math.max(0, souls.getOrDefault(playerId, getConfig().getInt("starting-souls", 3)) - 1);
        souls.put(playerId, remaining);

        Player killer = player.getKiller();
        if (killer != null) {
            lastKillers.put(playerId, killer.getUniqueId());
        }
        UUID killerId = lastKillers.get(playerId);
        savePlayerData();

        if (remaining == 0) {
            sendThirdDeathTitle(player);
            Bukkit.getScheduler().runTask(this, () -> banPlayer(player));
            return;
        }

        for (Player online : Bukkit.getOnlinePlayers()) {
            if (online.getUniqueId().equals(killerId)) {
                online.sendMessage(color("&b" + player.getName() + " is now spectating you."));
            }
        }
    }

    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent event) {
        Player player = event.getPlayer();
        UUID playerId = player.getUniqueId();
        if (souls.getOrDefault(playerId, getConfig().getInt("starting-souls", 3)) <= 0) {
            return;
        }

        UUID killerId = lastKillers.get(playerId);
        Bukkit.getScheduler().runTask(this, () -> {
            if (!player.isOnline() || souls.getOrDefault(playerId, 0) <= 0) {
                return;
            }
            beginSpectating(player, killerId);
            long delay = Math.max(0, getConfig().getLong("spectator-time-seconds", 5)) * 20L;
            Bukkit.getScheduler().runTaskLater(this, () -> {
                if (!player.isOnline() || souls.getOrDefault(playerId, 0) <= 0) {
                    return;
                }
                transitioningToSurvival.add(playerId);
                endSpectating(player);
                player.setGameMode(GameMode.SURVIVAL);
                transitioningToSurvival.remove(playerId);
            }, delay);
        });
    }

    @EventHandler
    public void onGameModeChange(PlayerGameModeChangeEvent event) {
        UUID playerId = event.getPlayer().getUniqueId();
        if (spectating.containsKey(playerId) && !transitioningToSurvival.contains(playerId)
                && event.getNewGameMode() != GameMode.SPECTATOR) {
            event.setCancelled(true);
        }
    }

    private void beginSpectating(Player player, UUID killerId) {
        UUID playerId = player.getUniqueId();
        spectating.put(playerId, killerId);
        player.setGameMode(GameMode.SPECTATOR);
        player.setGlowing(true);

        String name = player.getName();
        Team oldTeam = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(name);
        if (oldTeam != null && oldTeam != blueTeam) {
            previousTeams.put(playerId, oldTeam.getName());
            oldTeam.removeEntry(name);
        }
        if (!blueTeam.hasEntry(name)) {
            blueTeam.addEntry(name);
        }

        for (Player viewer : Bukkit.getOnlinePlayers()) {
            if (viewer.getUniqueId().equals(killerId)) {
                viewer.showPlayer(this, player);
            } else {
                viewer.hidePlayer(this, player);
            }
        }
    }

    private void endSpectating(Player player) {
        UUID playerId = player.getUniqueId();
        spectating.remove(playerId);
        transitioningToSurvival.remove(playerId);
        player.setGlowing(false);

        String name = player.getName();
        blueTeam.removeEntry(name);
        String previousTeamName = previousTeams.remove(playerId);
        if (previousTeamName != null) {
            Team previousTeam = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(previousTeamName);