src/main/java/me/firewolf8385/flameperms/utils/ChatUtils.java
/**
     * Send a centered chat message to a player.
     * @param player Player
     * @param message nessage
     */
Send a centered chat message to a player.
@param player Player
@param message nessage
Send a centered chat message to a player . @param player Player @param message nessage
public static void centeredChat(Player player, String message)
    {
        message = translate(message);
        if(message == null || message.equals("")) player.sendMessage("");
        message = ChatColor.translateAlternateColorCodes('&', message);
        int messagePxSize = 0;
        boolean previousCode = false;
        boolean isBold = false;
        for(char c : message.toCharArray())
        {
            if(c == '§')
            {
                previousCode = true;
                continue;
            }
            else if(previousCode == true)
            {
                previousCode = false;
                if(c == 'l' || c == 'L')
                {
                    isBold = true;
                    continue;
                }
                else isBold = false;
            }
            else
            {
                DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
                messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
                messagePxSize++;
            }
        }
        int halvedMessageSize = messagePxSize / 2;
        int toCompensate = CENTER_PX - halvedMessageSize;
        int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
        int compensated = 0;
        StringBuilder sb = new StringBuilder();
        while(compensated < toCompensate)
        {
            sb.append(" ");
            compensated += spaceLength;
        }
        player.sendMessage(sb.toString() + message);
    }
public static void centeredChat ( Player player , String message ) { message = translate ( message ) ; if ( message == null || message . equals ( "" ) ) player . sendMessage ( "" ) ; message = ChatColor . translateAlternateColorCodes ( '&' , message ) ; int messagePxSize = 0 ; boolean previousCode = false ; boolean isBold = false ; for ( char c : message . toCharArray ( ) ) { if ( c == '§') { previousCode = true ; continue ; } else if ( previousCode == true ) { previousCode = false ; if ( c == 'l' || c == 'L' ) { isBold = true ; continue ; } else isBold = false ; } else { DefaultFontInfo dFI = DefaultFontInfo . getDefaultFontInfo ( c ) ; messagePxSize += isBold ? dFI . getBoldLength ( ) : dFI . getLength ( ) ; messagePxSize ++ ; } } int halvedMessageSize = messagePxSize / 2 ; int toCompensate = CENTER_PX - halvedMessageSize ; int spaceLength = DefaultFontInfo . SPACE . getLength ( ) + 1 ; int compensated = 0 ; StringBuilder sb = new StringBuilder ( ) ; while ( compensated < toCompensate ) { sb . append ( " " ) ; compensated += spaceLength ; } player . sendMessage ( sb . toString ( ) + message ) ; }
Send a centered chat message to a player.
Send a centered chat message to a player .