ry08737

make a plugin where i can do /setrank (playername) and then the rank and then it displays it infront of theyre name but if somebody has no rank there is just nothing and i can set the color of theyre rank

Kodari AI
KodariOct 27 at 6:47 pm 1

The generation was stopped before any content could be produced.

ry08737

make a plugin where i can do /setrank (playername) and then the rank and then it displays it infront of theyre name but if somebody has no rank there is just nothing and i can set the color of they displayed rank with /rankcolor (playername) and then colors

Kodari AI
KodariOct 27 at 6:49 pm 1
RankDisplayPlugin
A Minecraft plugin that allows admins to assign ranks to players via /setrank (playername) (rankname). The assigned rank is displayed in front of the player's name in chat and tab list. Players without a rank display nothing. Admins can customize the color of each player's displayed rank using /rankcolor (playername) (color), supporting standard Minecraft color codes. Ranks and colors persist across server restarts through a configuration file. The plugin provides simple, intuitive commands with permission checks, ensuring only authorized staff can modify ranks and colors. It enhances server organization and player identity by visually distinguishing ranked players.
  • Add /setrank <player> <rank> with none to clear a rank.

  • Add /rankcolor <player> <color> using named Minecraft colors or color codes.

  • Persist ranks and colors, and show the prefix before names in the tab list/nameplates.

Created the RankPrefix plugin. Use:

  • /setrank <player> <rank> to set a rank; /setrank <player> none to clear it.

  • /rankcolor <player> <color> to change the rank color, using a color name (such as red or light_purple) or code (such as &c).

Ranks and colors persist across restarts. Commands require OP by default, and players must have joined the server before.

ry08737

also in chat and make the rank in brackets

Kodari AI
KodariOct 27 at 6:54 pm 1
  • Show the colored rank as [rank] in the tab/nameplate prefix.

  • Add the same prefix to player chat, leaving chat unchanged for players without a rank.

Ranks now appear as colored [rank] prefixes in chat, as well as in the tab list and above players’ names. Players without a rank keep the normal chat format.

ry08737

ok fix the bug were when you make somebody a diffrent rank then the rest, you get the same rank as them

Kodari AI
KodariNov 5 at 3:08 pm 1

I’ll give each player a persistent, collision-safe scoreboard team so changing one player’s rank can’t change another’s prefix.

Fixed rank isolation: scoreboard teams now have persistent, UUID-specific names, so assigning one player a different rank won’t overwrite another player’s prefix. Clearing a rank also won’t unregister a team that still has entries.

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

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;

import java.util.Locale;
import java.util.UUID;

public final class RankPrefixPlugin extends JavaPlugin implements Listener {
    private Scoreboard scoreboard;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("setrank").setExecutor(this::setRankCommand);
        getCommand("rankcolor").setExecutor(this::rankColorCommand);

        for (Player player : Bukkit.getOnlinePlayers()) {
            applyRank(player);
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        applyRank(event.getPlayer());
    }

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        String prefix = rankPrefix(event.getPlayer());
        if (!prefix.isEmpty()) {
            event.setFormat(prefix.replace("%", "%%") + event.getFormat());
        }
    }

    private boolean setRankCommand(org.bukkit.command.CommandSender sender,
                                   org.bukkit.command.Command command,
                                   String label, String[] args) {
        if (args.length < 2) {
            sender.sendMessage(color("&cUsage: /setrank <player> <rank|none>"));
            return true;
        }

        OfflinePlayer target = findPlayer(args[0]);
        if (target == null) {
            sender.sendMessage(color("&cThat player has not joined this server."));
            return true;
        }

        String rank = String.join(" ", java.util.Arrays.copyOfRange(args, 1, args.length)).trim();
        String path = playerPath(target.getUniqueId());
        if (rank.equalsIgnoreCase("none") || rank.equalsIgnoreCase("clear")) {
            getConfig().set(path + ".rank", null);
            sender.sendMessage(color("&aCleared the rank for &f" + target.getName() + "&a."));
        } else {
            if (rank.length() > 48) {
                sender.sendMessage(color("&cRank text cannot be longer than 48 characters."));
                return true;
            }
            getConfig().set(path + ".rank", rank);
            sender.sendMessage(color("&aSet &f" + target.getName() + "&a's rank to &f" + rank + "&a."));
        }

        saveConfig();
        if (target.isOnline()) {
            applyRank(target.getPlayer());
        }
        return true;
    }

    private boolean rankColorCommand(org.bukkit.command.CommandSender sender,
                                     org.bukkit.command.Command command,
                                     String label, String[] args) {
        if (args.length != 2) {
            sender.sendMessage(color("&cUsage: /rankcolor <player> <color>"));
            sender.sendMessage(color("&7Colors: red, gold, yellow, green, aqua, blue, light_purple, white, gray, black..."));
            return true;
        }

        OfflinePlayer target = findPlayer(args[0]);
        if (target == null) {
            sender.sendMessage(color("&cThat player has not joined this server."));
            return true;
        }

        ChatColor rankColor = parseColor(args[1]);
        if (rankColor == null) {
            sender.sendMessage(color("&cUnknown color. Use a color name such as red or a code such as &c."));
            return true;
        }

        getConfig().set(playerPath(target.getUniqueId()) + ".color", rankColor.name());
        saveConfig();
        if (target.isOnline()) {
            applyRank(target.getPlayer());
        }
        sender.sendMessage(color("&aSet &f" + target.getName() + "&a's rank color to "
                + rankColor + rankColor.name().toLowerCase(Locale.ROOT) + "&a."));
        return true;
    }

    private OfflinePlayer findPlayer(String name) {
        Player online = Bukkit.getPlayerExact(name);
        if (online != null) {
            return online;
        }

        for (OfflinePlayer offline : Bukkit.getOfflinePlayers()) {
            if (name.equalsIgnoreCase(offline.getName())) {
                return offline;
            }
        }
        return null;
    }

    private void applyRank(Player player) {
        if (player == null) {
            return;
        }

        String path = playerPath(player.getUniqueId());
        String rank = getConfig().getString(path + ".rank");
        String teamName = teamName(player.getUniqueId(), player.getName());
        Team team = scoreboard.getTeam(teamName);

        if (rank == null || rank.isBlank()) {
            if (team != null) {
                team.removeEntry(player.getName());
                if (team.getEntries().isEmpty()) {
                    team.unregister();
                }
            }
            return;
        }

        if (team == null) {
            team = scoreboard.registerNewTeam(teamName);
        }

        team.setPrefix(rankPrefix(player));

        Team currentTeam = scoreboard.getEntryTeam(player.getName());
        if (currentTeam != null && currentTeam != team) {
            currentTeam.removeEntry(player.getName());
        }
        team.addEntry(player.getName());
    }

    private String rankPrefix(Player player) {
        String path = playerPath(player.getUniqueId());
        String rank = getConfig().getString(path + ".rank");
        if (rank == null || rank.isBlank()) {
            return "";
        }

        ChatColor rankColor = parseColor(getConfig().getString(path + ".color", "WHITE"));
        if (rankColor == null) {
            rankColor = ChatColor.WHITE;
        }
        return rankColor + "[" + rank + "]" + ChatColor.RESET + " ";
    }

    private ChatColor parseColor(String input) {
        if (input == null || input.isBlank()) {
            return null;
        }

        String value = input.trim();
        if (value.length() == 2 && (value.charAt(0) == '&' || value.charAt(0) == '§')) {
            ChatColor code = ChatColor.getByChar(value.charAt(1));
            return code != null && code.isColor() ? code : null;
        }
        if (value.length() == 1) {
            ChatColor code = ChatColor.getByChar(value.charAt(0));
            return code != null && code.isColor() ? code : null;
        }

        try {
            ChatColor named = ChatColor.valueOf(value.toUpperCase(Locale.ROOT));
            return named.isColor() ? named : null;
        } catch (IllegalArgumentException exception) {
            return null;
        }
    }

    private String playerPath(UUID uuid) {
        return "players." + uuid;
    }