Solved Header

Discussion in 'Plugin Development' started by MaTaMoR_, Apr 9, 2015.

Thread Status:
Not open for further replies.
  1. Hi, made i little system to get a adjustable header :
    Code:
    Code:
    public static String header(String text) {
        if(text.contains("&l")) {
            text = text.replace("&l", "");
        }
    
        int length = ChatColor.stripColor(color(text)).length();
        if((length % 2) != 0) {
            length++;
        }
    
        int middle = (length / 2);
        int borderlength = (27 - middle) - 1;
    
        StringBuilder sb = new StringBuilder();
        for(int i = 0; borderlength > i; i++) {
            sb.append("-");
        }
        String border = "&7&m" + sb.toString() + "&r";
    
        return color(border + " " + text + " " + border);
    }
    
    I don't know what im doing wrong, i mean i tried with two texts but i think is not working right, because second text is not fully filled : Photo
     
  2. Offline

    SuperOriginal

    It's difficult to align text like that because letters have different widths
     
    Last edited: Apr 9, 2015
  3. Offline

    nverdier

    @MaTaMoR_
    (((length of space you want to fill) - (length of text)) ÷ 2) = number of "-' on each side.
     
  4. (((length of space you want to fill) - (length of text)) / 2)*
    Still the same
     
  5. Offline

    nverdier

    @MaTaMoR_ I wasn't giving Java code :p

    Oh, I see the problem now. As @SuperOriginal said. Character width. You'd have to get a new font for it to be 100% perfect.
     
  6. Offline

    mythbusterma

    @MaTaMoR_

    There's not real way to do column alignment like this in Minecraft, as the font is not monospace, which is what you call a font that abides by the assumptions you're making. Also, the support for \t (literal tab) is a little weird, although you're welcome to try that (that is the character usually used to format output from console applications).
     
Thread Status:
Not open for further replies.

Share This Page