1.17.x Getting prefix color of rank in code (using Vault)

Discussion in 'Spigot Plugin Development' started by parpar8090, Jul 19, 2021.

  1. For the last 2 hours, I've been trying to get the prefix color of a rank in my project. I know there's a placeholder called %vault_prefix_color% but that's not what I need because it only works for the viewers. I need to come up with something similar but also works not only for the viewer.

    Getting last color:
    Code (Java):
    private String getLastColor(String s) {
            if (s == null || s.isEmpty()) return "";
            int c = s.lastIndexOf(ChatColor.COLOR_CHAR);
            if (c == -1) {
                c = s.lastIndexOf("&");
                if (c == -1) return "";
            String clr = s.substring(c);
            if (c - 2 >= 0)
                if (s.charAt(c - 2) == ChatColor.COLOR_CHAR || s.charAt(c - 2) == '&') clr = s.substring(c - 2);
            return clr;
    Get group prefix:
    Code (Java):
    private String getGroupPrefix(OfflinePlayer p) {
            if (Main.getPermissions().getPrimaryGroup(getWorldName(), p) == null) return "";
            String prefix = Main.getChat().getGroupPrefix(getMainWorld(), getMainGroup(p));
            if (prefix != null) return prefix;
            return "";
    The thing is that LUCKPERMS complains it's not async:
    me.lucko.luckperms.bukkit.vault.ServerThreadLookupException: A Vault API request has been made on the main server thread that LuckPerms cannot safely respond to.
    This is NOT a bug - please do not report it to LuckPerms.
    Instead, please carefully read the information given below.

    LuckPerms cannot respond to the request because to do so:
    - it needs to lookup a UUID for 'Sub_parpar8090' (an offline player)

    Performing this lookup on the main server thread would cause your server to lag.
    There are two solutions to this problem:
    a) Ask the author of the plugin making the request to perform Vault calls for
    offline players "asynchronously" (using the scheduler). Additionally, prefer
    using the methods that accept 'Player' or 'OfflinePlayer' instead of usernames.
    You should be able to identify the plugin making the request in the trace below.
    b) As a server admin, you can disable this exception by setting 'vault-unsafe-lookups'
    to true in the LuckPerms configuration file. However, please use this only as
    a last resort.

    I don't want to enable vault-unsafe-lookups, I guess there's no option?