How to make custom rank system

Jul 21, 2017
How to make custom rank system
  • This tutorial teaches you how to make a custom rank system.

    1. Make an enum to represent your ranks. We'll use Mineplex's as an example.
    Code (Java):
    public enum Rank {
        NONE(""),
        ULTRA(ChatColor.LIGHT_PURPLE + "ULTRA"),
        HERO(ChatColor.AQUA + "HERO"),
        LEGEND(ChatColor.GREEN + "LEGEND");

        private final String prefix;

        Rank(String prefix) {
            this.prefix = prefix;
        }
    }
    2. Make a Map to hold Player ranks.
    Code (Java):
    Map<Player, Rank> ranks = new HashMap<>();
    3. Make methods to set, get, load and save the rank of the Player.
    It will set the display and player list name.
    Code (Java):
    public void setRank(Player player, Rank rank) {
         ranks.put(player, rank);
    }

    public Rank getRank(Player player) {
         return ranks.get(player);
    }

    public void loadRank(Player player) {
        String rankString = getConfig().get(player.getUniqueId() + ".rank");
        Rank rank = (rankString == null) ? Rank.NONE : Rank.valueOf(rankString);
        player.setDisplayName(prefix.get(rank) + player.getName());
        player.setPlayerListName(prefix.get(rank) + player.getName());
        ranks.put(player, rank);
    }

    public void saveRank(Player player) {
        getConfig().set(player.getUniqueId() + ".rank", ranks.get(rank));
        ranks.remove(player);
    }
    Loading should be called when the player joins the server. Saving should be called when a player leaves the server (we want to make sure their rank gets updated if it needs too, and we don't want a loose player object in our map!)

    You are done!

    You can now give your players perks according to their ranking system. Here's an example:
    Code (Java):
    if (getRank(player) == Rank.LEGEND) {
         player.setWalkSpeed(0.4F);
    } else {
         player.setWalkSpeed(0.2F);
    }
  • Loading...
  • Loading...