Gopal Kumar
📎 1 file 9,579 chars
đź“„
LostSMP_NameHide_Plugin_Prompt.txt
txt 213 lines
â–¶
PLUGIN PROMPT: LostSMP NameHide (Paper 1.21.11, Java 21)
==============================================================================

PART 1: AI/DEVELOPER KO DENE WALA PROMPT
==============================================================================

Mujhe ek Paper 1.21.11 ka Java plugin chahiye. Plugin ka naam: LostNames
(package: com.kodari.lostnames). Build tool: Maven ya Gradle (jo easy ho),
Java 21, paper-api 1.21.11 dependency. Server offline-mode (cracked) hai,
AuthMe use hota hai, aur LuckPerms + TAB plugin bhi installed hain.
Poora plugin ka code, plugin.yml, config.yml aur build steps do.

------------------------------------------------------------------
1. COMMANDS
------------------------------------------------------------------

a) /namehide on
   - Player ka asli naam chat, join, leave, kill aur death messages
     mein NAHI dikhna chahiye.
   - Uski jagah ek RANDOM HIDDEN NAAM dikhe, jaise "Player-48213" ya
     "User_7391" (format config.yml mein ho: hidden_name_format:
     "Player-%d", digits 4 se 6). Naam random number se bane.
   - Ek baar ON karne par jab tak OFF na ho, wahi hidden naam rahe
     (har message pe naya number nahi). Aur ye player ke ON karne ke
     baad jab tak OFF na kare tab tak SAVE rahe, restart/rejoin ke
     baad bhi.

b) /namehide off
   - Hidden naam band, player ka asli naam wapas dikhne lage har jagah.

c) /namechange 
   - Player apna dikhne wala naam apni marzi ka kar sake, game mein
     sabko wahi naya naam dikhe (chat, join, leave, kill, death).
   - Naam valid hona chahiye: 3 se 16 characters, sirf letters, numbers
     aur underscore.
   - Naam kisi aur ONLINE ya pehle se JOIN ho chuke asli player ke naam
     jaisa NAHI ho sakta, na kisi aur ke already use kiye hue fake naam
     jaisa (duplicate check, case-insensitive). Error message do:
     "Ye naam already use mein hai."
   - Blocked naam list config mein ho (blocked_names: [Admin, Owner,
     Console, Server...]).
   - Cooldown config mein (default 30 second) taaki spam na ho.

d) /namedefault
   - Jo bhi hidden ya changed naam tha, hata ke player ka ORIGINAL asli
     naam wapas set ho jaye (hide bhi off ho jaye).

Teeno commands sirf PLAYER chala sake (console nahi). Tab-complete do:
/namehide -> on, off. Permissions:
- lostnames.use (default: true ya config se) : teeno commands
- lostnames.admin (default: op) : staff commands (neeche point 4)

------------------------------------------------------------------
2. KAHAN KAHAN KAAM KARNA CHAHIYE (SABSE IMPORTANT)
------------------------------------------------------------------
Jab hidden ya changed naam active ho, to ye SAB jagah asli naam ki jagah
fake naam aaye:

A) CHAT: AsyncChatEvent (Paper) ka renderer use karo, sender ka
   displayName fake naam ho. Format:  message. LuckPerms
   prefix/format hai to wo bhi sath chale (prefix rahe, naam fake).

B) JOIN MESSAGE: PlayerJoinEvent mein joinMessage ko fake naam ke sath
   banao (" joined the game"). Player ki saved state join se
   PEHLE apply honi chahiye (PlayerJoinEvent, priority HIGHEST), taaki
   asli naam kabhi leak na ho.

C) LEAVE MESSAGE: PlayerQuitEvent mein quitMessage fake naam ke sath
   (" left the game"). Kick hone par bhi (PlayerKickEvent) fake
   naam hi aaye.

D) DEATH MESSAGE: PlayerDeathEvent ki deathMessage mein VICTIM ka naam
   fake ho. Death message ek Component hota hai (translatable with
   args), isliye poore component mein asli naam ko fake naam se
   replace karo (TextReplacementConfig ya args rebuild). Sab type ki
   death pe kaam kare: mob, fall, lava, void, explosion, etc.

E) KILL MESSAGE (PvP): jab koi player kisi ko maare, to message mein
   KILLER ka naam bhi fake ho aur VICTIM ka bhi (dono ke liye alag
   alag check). Killer ke hathiyaar ka naam wala message ("X was slain
   by Y using [Sword]") me bhi naam replace ho.

F) Advancement messages ("X has made the advancement ...") mein bhi
   naam fake ho.

G) TAB LIST: player.playerListName(fake) set karo. Agar TAB plugin
   installed hai to uske sath conflict na ho; PlaceholderAPI expansion
   do: %lostnames_name% (fake ya asli jo active ho), %lostnames_real%
   (sirf admin ke liye).

H) NAME TAG (sar ke upar naam): ye vanilla mein seedha change nahi
   hota. Option do: (1) scoreboard team banake nametag visibility
   NEVER karo (naam bilkul na dikhe), ya (2) ProtocolLib ya Paper
   packet se fake naam dikhao. Default option (1) rakho, aur config
   mein hide_nametag: true/false ho.

I) Doosre plugin messages: apna ek chhota API do
   LostNamesAPI.getDisplayName(UUID / Player) jisse mere LostSMP
   plugin ke title announcements (revive, bounty, ritual) mein bhi
   fake naam use ho sake. Isko main alag se LostSMP mein connect
   karunga, tum bas API public rakho.

J) Console log mein ASLI NAAM hi rahe (server owner ke records ke
   liye), sirf players ko dikhne wale messages mein fake naam aaye.

------------------------------------------------------------------
3. DATA SAVE
------------------------------------------------------------------
- data.yml (ya per-player file) mein UUID ke hisaab se save karo:
  hidden (true/false), fake_name, original_name.
- Asli naam hamesha player.getName() se hi liya jaye aur kabhi
  overwrite na ho.
- Server restart ke baad aur player rejoin ke baad state wahi rahe.
- /namedefault pe entry clean ho.

------------------------------------------------------------------
4. ADMIN / OWNER KE LIYE (SERVER SAFE RAKHNE KE LIYE)
------------------------------------------------------------------
- /namecheck  : sirf lostnames.admin wale ko
  asli player ka naam dikhaye. (taaki cheating, spam, griefing ya
  rule-break hone par staff pata laga sake.)
- /namereset  : admin kisi bhi player ka naam force default
  kar sake.
- /namelist : admin ko list dikhaye kaun kis fake naam ke sath hai.
- Admins (lostnames.see) ko config option se asli naam bhi chat mein
  fake naam ke bagal mein dikh sake: "Player-4821 (RealName)". Default
  ON admin ke liye.
- Ban/kick/mute jaise punishment commands asli naam pe hi chalein
  (LightBans, AuthMe asli naam use karte hain, unhe touch mat karo).

------------------------------------------------------------------
5. CONFIG.YML (EXAMPLE)
------------------------------------------------------------------
hidden_name_format: "Player-%d"
random_digits: 5
cooldown_seconds: 30
hide_nametag: true
admin_see_real_name: true
min_length: 3
max_length: 16
blocked_names: [Admin, Owner, Console, Server]
messages:
  hide_on: "&aTumhara naam ab hide hai."
  hide_off: "&eTumhara naam wapas normal."
  changed: "&aTumhara naam ab %name% hai."
  default: "&aOriginal naam wapas aa gaya."
  name_taken: "&cYe naam already use mein hai."
  invalid: "&cNaam 3-16 letters/numbers/_ ka hona chahiye."
  cooldown: "&cThoda ruko, %s second baad try karo."

------------------------------------------------------------------
6. TESTING CHECKLIST (har ek test karke batao)
------------------------------------------------------------------
1. /namehide on karke chat bhejo: fake naam dikhe.
2. Relog karo: join message mein fake naam, leave mein bhi fake naam.
3. Kisi mob/lava se maro: death message mein fake naam.
4. Dusre player se PvP kill karwao: killer aur victim dono fake.
5. /namechange Test_123: sab jagah naya naam.
6. Duplicate naam try karo: reject ho.
7. /namedefault: sab asli.
8. Restart ke baad state same rahe.
9. Admin ko /namecheck se asli naam mile.
10. TAB list aur advancement message mein bhi check karo.

Kisi bhi existing plugin (LostSMP, AuthMe, LuckPerms, TAB, LightBans,
Simple Voice Chat) ko BREAK mat karna. Final output: poora source code,
pom.xml/build.gradle, plugin.yml, config.yml, aur jar banane ke steps.


==============================================================================
PART 2: HINDI EXPLANATION (PLUGIN AISE KAAM KAREGA)
==============================================================================

1) /namehide on
   Jaise hi tum ye command chalaoge, tumhara asli naam kahin nahi
   dikhega. Chat mein, join/leave mein, kill ya death message mein
   sabko tumhari jagah ek random naam dikhega, jaise "Player-48213".
   Wo number tab tak same rahega jab tak tum off na karo. Server band
   ho ya tum relog karo, tab bhi hide chalu rahega.

2) /namehide off
   Hide band. Sabko dobara tumhara asli naam dikhega.

3) /namechange 
   Tum apni marzi ka naam rakh sakte ho, jaise /namechange Steve_99.
   Fir chat, join, leave, kill aur death sab jagah wahi naam dikhega.
   Koi dusre player ka naam ya blocked naam (Admin, Owner) nahi le
   sakte, taaki kisi aur ki nakal na ho.

4) /namedefault
   Hide aur change dono hat jaate hain, aur tumhara pehle wala asli
   naam wapas aa jata hai.

5) Kahan kahan lagega
   - Chat
   - Join message (joined the game)
   - Leave message (left the game)
   - Death message (jaise "Steve fell from a high place")
   - Kill message (jaise "A was slain by B", dono ke naam fake)
   - Advancement message, TAB list, aur sar ke upar ka nametag

6) Owner/Admin ke liye
   Console log mein asli naam hi save rehta hai. Admin /namecheck
   command se kisi bhi fake naam ka asli player pata kar sakta hai,
   isse rule todne wale ko pakadna aasan rahega. Ban aur mute asli
   naam pe hi lagenge.

7) Ek zaroori baat
   Server offline-mode mein hai, isliye skin naam se judi hoti hai.
   Naam hide hone par bhi skin wahi dikhegi. Agar skin bhi chhupani
   ho to ye alag feature hai (ProtocolLib ya SkinsRestorer type
   plugin chahiye), ye prompt sirf naam ke liye hai.
Kodari AI
KodariOct 15 at 10:26 am 2
LostNames
LostNames is a Paper 1.21.11 plugin that lets players hide or change their displayed name across the entire server. Commands include /namehide, /namechange, and /namedefault with persistent per-player state saved to data.yml. The plugin replaces real names with fake ones in chat, join/leave messages, death/kill messages, advancements, and TAB list. It provides a public API for other plugins, admin commands for name lookup and reset, configurable blocked names and cooldowns, and optional nametag hiding via scoreboard teams. Designed for offline-mode servers with AuthMe, LuckPerms, and TAB compatibility.
  1. Build the Paper 1.21.11/Java 21 plugin and commands with persistent player names.

  2. Add chat, join/quit, death, advancement, tab-list, nametag, admin, and PlaceholderAPI handling.

  3. Include plugin/config metadata and the public LostNamesAPI.

Implemented LostNames with persistent hidden/custom names, command validation and cooldowns, player-facing chat/join/quit/death/advancement aliases, tab-list names, optional nametag hiding, staff commands, PlaceholderAPI placeholders, and the public LostNamesAPI.

The project includes Gradle configuration, plugin.yml, and config.yml. I haven’t run a live Paper server here, so the attached in-server test checklist still needs verification.

To get the jar in Kodari: click Compile in the desktop top bar (or ⋮ → Compile Project on mobile), click Compile, then Download when the build succeeds.

Gopal Kumar
📎 1 file 3,814 chars
đź“„
pasted-code-1792061494297.txt
txt 70 lines
â–¶
LostNames plugin (Paper 1.21.11, Adventure API): fix the real name showing in kill/death messages. Do not change anything else in the plugin.

BUG:
When a player kills someone in PvP (or dies in any way), the kill/death message shows the player's REAL name instead of the hidden or changed name. Chat, join and leave messages already work correctly.

ROOT CAUSE:
The vanilla death message is a TranslatableComponent. Its arguments contain the victim and killer as entity components. Those carry a HoverEvent (SHOW_ENTITY) that holds the real name and UUID. The name can also be wrapped in team prefix/suffix. Replacing text in one place is not enough.

FIX (implement exactly this):

1. Register the PlayerDeathEvent listener at priority HIGHEST. Make sure the listener class is registered with registerEvents in the main class.

2. Write a scrub function for the death message that does three things:
   a) Removes SHOW_ENTITY hover events from every component, recursively (children and translatable arguments too).
   b) For every player who has hide or change active (all online players, not only the victim, so the killer is covered too), replaces the real name with the fake name. Case-insensitive.
   c) Keeps the weapon item hover (SHOW_ITEM), but also replaces any real name inside its text.

3. Base code:

@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(PlayerDeathEvent e) {
    Component msg = e.deathMessage();
    if (msg == null) return;
    e.deathMessage(scrub(msg));
}

private Component scrub(Component c) {
    if (c.hoverEvent() != null && c.hoverEvent().action() == HoverEvent.Action.SHOW_ENTITY) {
        c = c.hoverEvent(null);
    }
    c = c.clickEvent(null);
    c = c.children(c.children().stream().map(this::scrub).toList());
    if (c instanceof TranslatableComponent t) {
        List args = t.arguments().stream()
            .map(a -> scrub(a.asComponent())).toList();
        c = t.arguments(args);
    }
    for (Player p : Bukkit.getOnlinePlayers()) {
        if (!isNameChanged(p)) continue;
        String real = p.getName();
        String fake = api.getDisplayName(p);
        c = c.replaceText(TextReplacementConfig.builder()
            .matchLiteral(real)
            .replacement(Component.text(fake))
            .build());
    }
    return c;
}

Note: isNameChanged(p) checks whether the player has hide on or a changed name. Also keep a real-to-fake map in data.yml so players who already went offline are replaced too.

4. Fallback if a real name still leaks (for example through team prefix/suffix): call event.deathMessage(null) and build the message yourself with
   Component.translatable(originalKey, fakeVictim, fakeKiller, itemComponent)
   then send it with Bukkit.broadcast. Log the version with real names to the console only.

5. Add a config option debug: true. When enabled, print the raw death message JSON to the console before and after scrubbing (GsonComponentSerializer.gson().serialize(msg)), so it is visible where the real name remains.

6. If any other plugin (LostSMP bounty kill, heart drop messages, etc.) announces kills, note where LostNamesAPI.getDisplayName() should be used. I will connect that to LostSMP separately.

7. TEST and report the result of each case. No real name or UUID may appear in the message or in the hover tooltip:
   - A kills B with a sword, both hidden
   - A hidden, B normal
   - A normal, B hidden
   - A kills B while using a /namechange name
   - Kill by arrow or other projectile
   - Death by mob
   - Death by lava or fall damage
   - Hover the mouse over the death message and check for real names or UUIDs

Final output: the complete fixed code, plus a short explanation of where the original bug was.
Kodari AI
KodariOct 15 at 10:52 am 1

Fixed PlayerDeathEvent handling in LostNamesPlugin: the listener already runs at HIGHEST and is registered in the main plugin. Death messages are now scrubbed recursively, removing SHOW_ENTITY hover events and replacing active real names case-insensitively—including names from persisted profiles for offline players. SHOW_ITEM hovers are preserved. Added debug: true to config.yml to log the raw JSON before and after scrubbing; the original real-name message is logged to console only.

Test status: I haven’t run these cases on a live Paper server, so they’re not runtime-verified. The recursive handling is intended to cover PvP with both players hidden, either player hidden, /namechange, projectile kills, mob deaths, lava/fall deaths, and entity hover tooltips. For kill announcements generated by LostSMP or another plugin, use LostNamesAPI.getDisplayName(player) (or the UUID overload) when composing bounty, heart-drop, or similar messages.

Gopal Kumar

k so gime me

Kodari AI
KodariOct 15 at 10:54 am 1

Here’s the paste-ready death-message fix for LostNamesPlugin.java. It uses the existing profiles data saved to data.yml, so active fake names for offline players are included too.

Java
@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(PlayerDeathEvent event) {
    Component original = event.deathMessage();
    if (original == null) {
        return;
    }

    if (getConfig().getBoolean("debug", false)) {
        getLogger().info("Death message before scrubbing: "
            + GsonComponentSerializer.gson().serialize(original));
    }

    Component scrubbed = scrubDeathMessage(original);

    event.deathMessage(null);
    broadcastToPlayers(scrubbed);

    // Keep the unsanitized version in the console only.
    getLogger().info(PlainTextComponentSerializer.plainText().serialize(original));

    if (getConfig().getBoolean("debug", false)) {
        getLogger().info("Death message after scrubbing: "
            + GsonComponentSerializer.gson().serialize(scrubbed));
    }
}

private Component scrubDeathMessage(Component component) {
    if (component.hoverEvent() != null
        && component.hoverEvent().action() == HoverEvent.Action.SHOW_ENTITY) {
        component = component.hoverEvent(null);
    }

    component = component.clickEvent(null);
    component = component.children(
        component.children().stream().map(this::scrubDeathMessage).toList()
    );

    if (component instanceof TranslatableComponent translatable) {
        List<Component> arguments = translatable.arguments().stream()
            .map(argument -> scrubDeathMessage(argument.asComponent()))
            .toList();
        component = translatable.arguments(arguments);
    }

    return replaceActiveNames(component);
}

private Component replaceActiveNames(Component component) {
    for (NameProfile profile : profiles.values()) {
        String realName = profile.originalName();
        String fakeName = profile.fakeName();

        if (!realName.isBlank() && !realName.equalsIgnoreCase(fakeName)) {
            component = component.replaceText(TextReplacementConfig.builder()
                .match(Pattern.compile(
                    Pattern.quote(realName),
                    Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
                ))
                .replacement(Component.text(fakeName))
                .build());
        }
    }
    return component;
}

Required config entry:

YAML
debug: true

The listener is registered in onEnable() with Bukkit.getPluginManager().registerEvents(this, this);. The original leak was in the vanilla translatable death component: its entity arguments could carry real names and SHOW_ENTITY hovers, including for the killer.

Gopal Kumar

k so make plugin

Kodari AI
KodariOct 15 at 10:56 am 1
  • Harden the death-message scrubber so it sanitizes item-hover text as well as component text.

  • Add the specified leak-check fallback and keep unsanitized messages out of player broadcasts.

  • Keep the existing listener registration and debug config unchanged.

Implemented the death-message fix in LostNamesPlugin.java. It removes SHOW_ENTITY hovers, recursively scrubs message arguments and text hovers, and replaces active real names in serialized output too—preserving SHOW_ITEM hovers while sanitizing their text. If a name is still detected, it rebuilds the translatable message with fake victim/killer names. The unsanitized message is not broadcast; debug: true logs before/after JSON to the console.

Testing: I haven’t run a live Paper server, so none of these cases are runtime-verified: PvP with both hidden, either player hidden, /namechange, projectile kill, mob death, lava/fall death, and checking message/hover tooltips for real names or UUIDs.

For kill announcements from LostSMP or another plugin, use LostNamesAPI.getDisplayName(player) or getDisplayName(uuid).

Gopal Kumar

k so gime me plugin man

Kodari AI
KodariOct 15 at 12:24 pm 1
  • Keep the existing HIGHEST-priority listener, registration, and debug config unchanged.

  • Log the raw message only to the console if the fallback is needed, then broadcast only the sanitized message.

  • The recursive scrub already handles entity/text hovers; serialized replacement also sanitizes names inside SHOW_ITEM hover data.

Updated the plugin project. To get the jar:

  1. Click Compile in the top bar (on phone: ⋮ → Compile Project).

  2. Click Compile in the window.

  3. When it succeeds, click Download on the build.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
7 801
src/main/java/com/kodari/lostnames/LostNamesPlugin.java
package com.kodari.lostnames;

import com.kodari.lostnames.api.LostNamesAPI;
import com.kodari.lostnames.hook.LostNamesPlaceholderExpansion;
import io.papermc.paper.event.player.AsyncChatEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.IllegalFormatException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
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.PlayerDeathEvent;
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class LostNamesPlugin extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {
    private static final String HIDDEN_TEAM = "lostnames_hidden";

    private final Map<UUID, NameProfile> profiles = new ConcurrentHashMap<>();
    private final Map<UUID, String> knownNames = new ConcurrentHashMap<>();
    private final Map<UUID, Long> lastNameChange = new ConcurrentHashMap<>();
    private File dataFile;
    private YamlConfiguration data;
    private LostNamesPlaceholderExpansion placeholderExpansion;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        dataFile = new File(getDataFolder(), "data.yml");
        loadData();
        LostNamesAPI.initialize(this);
        Bukkit.getPluginManager().registerEvents(this, this);

        for (String name : List.of("namehide", "namechange", "namedefault", "namecheck", "namereset", "namelist")) {
            getCommand(name).setExecutor(this);
            getCommand(name).setTabCompleter(this);
        }

        if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            placeholderExpansion = new LostNamesPlaceholderExpansion(this);
            placeholderExpansion.register();
        }

        for (Player player : Bukkit.getOnlinePlayers()) {
            knownNames.put(player.getUniqueId(), player.getName());
            refreshProfileRealName(player);
            applyPlayerName(player);
        }
        saveData();
    }

    @Override
    public void onDisable() {
        saveData();
        for (Player player : Bukkit.getOnlinePlayers()) {
            removeFromHiddenTeam(player.getName());
            player.setPlayerListName(player.getName());
        }
        LostNamesAPI.shutdown(this);
    }

    public String getDisplayName(UUID uuid) {
        NameProfile profile = profiles.get(uuid);
        if (profile != null) {
            return profile.fakeName();
        }
        return getRealName(uuid);
    }

    public String getRealName(UUID uuid) {
        Player online = Bukkit.getPlayer(uuid);
        if (online != null) {
            return online.getName();
        }
        String known = knownNames.get(uuid);
        if (known != null) {
            return known;
        }
        OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);
        return offline.getName() == null ? uuid.toString() : offline.getName();
    }

    private void loadData() {
        data = YamlConfiguration.loadConfiguration(dataFile);
        ConfigurationSection playerSection = data.getConfigurationSection("players");
        if (playerSection != null) {
            for (String key : playerSection.getKeys(false)) {
                try {
                    UUID uuid = UUID.fromString(key);
                    ConfigurationSection section = playerSection.getConfigurationSection(key);
                    if (section == null) {
                        continue;
                    }
                    String fakeName = section.getString("fake_name", "");
                    String originalName = section.getString("original_name", "");
                    if (!fakeName.isBlank() && !originalName.isBlank()) {
                        profiles.put(uuid, new NameProfile(section.getBoolean("hidden"), fakeName, originalName));
                    }
                } catch (IllegalArgumentException ignored) {
                    getLogger().warning("Ignoring invalid UUID in data.yml: " + key);
                }
            }
        }

        ConfigurationSection knownSection = data.getConfigurationSection("known_names");
        if (knownSection != null) {
            for (String key : knownSection.getKeys(false)) {
                try {
                    String name = knownSection.getString(key);
                    if (name != null && !name.isBlank()) {
                        knownNames.put(UUID.fromString(key), name);
                    }
                } catch (IllegalArgumentException ignored) {
                    getLogger().warning("Ignoring invalid UUID in known_names: " + key);
                }
            }
        }
    }

    private void saveData() {
        YamlConfiguration output = new YamlConfiguration();
        for (Map.Entry<UUID, NameProfile> entry : profiles.entrySet()) {
            String path = "players." + entry.getKey();
            NameProfile profile = entry.getValue();
            output.set(path + ".hidden", profile.hidden());
            output.set(path + ".fake_name", profile.fakeName());
            output.set(path + ".original_name", profile.originalName());
        }
        for (Map.Entry<UUID, String> entry : knownNames.entrySet()) {
            output.set("known_names." + entry.getKey(), entry.getValue());
        }
        try {
            output.save(dataFile);
            data = output;
        } catch (IOException exception) {
            getLogger().severe("Could not save data.yml: " + exception.getMessage());
        }
    }

    private void refreshProfileRealName(Player player) {
        NameProfile profile = profiles.get(player.getUniqueId());
        if (profile != null && !profile.originalName().equals(player.getName())) {
            profiles.put(player.getUniqueId(), new NameProfile(profile.hidden(), profile.fakeName(), player.getName()));
        }
    }

    private void applyPlayerName(Player player) {
        NameProfile profile = profiles.get(player.getUniqueId());
        if (profile == null) {
            player.setPlayerListName(player.getName());
            removeFromHiddenTeam(player.getName());
            return;
        }

        player.setPlayerListName(profile.fakeName());
        if (getConfig().getBoolean("hide_nametag", true)) {
            hiddenTeam().addEntry(player.getName());
        } else {
            removeFromHiddenTeam(player.getName());
        }
    }

    private Team hiddenTeam() {
        Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
        Team team = scoreboard.getTeam(HIDDEN_TEAM);
        if (team == null) {
            team = scoreboard.registerNewTeam(HIDDEN_TEAM);
        }
        team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
        return team;
    }