Custom textures as prefixes

Discussion in 'Spigot Plugin Help' started by ICoding, Jun 10, 2021.

  1. Hello,

    I'm wondering how you could make prefixes like for example, OriginRealms did (picture below)

    [​IMG]

    I don't have any idea on how this could be made and do not currently have any code for it so if anyone could provide a code example of this, it would be appreciated.

    Thanks! :)
     
  2. You have to use custom resource pack. I think it's done with some kind of retextured character.
     
  3. This is based around the Origin Realms pack:

    Create a file in a resource pack named assets/minecraft/font/default.json:
    Code (Text):
    {
      "providers":
      [
        {
          "ascent": <Same as height>,
          "char": "<The character to replace>",
          "file": "ranks/<The rank name>.png",
          "height": <Height of rank character>
         }
      ]
    }
    Use a character unlikely to be used by your players such as "⅟ "(unless it's a server all about fractions, which is unlikely) or "א". See https://unicode-table.com/en/.

    Create a file in assets/minecraft/textures/ranks/<The rank name>.png containing the prefix image.

    Test the resource pack, by loading into your game, and typing the characters for each prefix into chat.

    If this works, upload it onto a website (could be hosted on the same machine as the Minecraft server, or on a file sharing site).

    The code could look something like this (it will need to be adapted for your plugin):

    Code (Java):

    public class Events implements Listener {

        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
             Rank rank = Rank.getForPlayer(event.getPlayer()));
             event.getPlayer().setDisplayName(rank.getCharacter() + " " + event.getPlayer().getDisplayName());
             event.getPlayer().setResourePack("/* Put the URL for the resource pack here */");
        }

        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event) {
            for (Rank rank : Rank.values()) {
                if (event.getMessage().contains(rank.getCharacter()) {
                    event.getPlayer().sendMessage(ChatColor.RED + "You may not use the " + rank.getCharacter() + " character in your messages, as it is reservered for player ranks.");
                    event.setCancelled(true);
                }
            }
        }

    }

    public enum Rank {
        /*
         * Put all ranks here in this format:
         * NAME_OF_RANK("Name of rank with spaces", 'character');
         */


        private char character;

        private Rank(char character) {
            this.character = character;
        }

        public char getCharacter() {
            return character;
        }

        public static Rank getForPlayer(Player player) {
            /* Code to determine player's rank */
        }

    }

     
     
    #3 mcblueparrot, Jun 10, 2021
    Last edited: Jun 10, 2021
  4. Thanks! :D