Alternative to \t

Discussion in 'Plugin Development' started by xXHediusXx, Dec 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    xXHediusXx

    Hi Community,
    I have the problem that I need to format my String in the style of a table. I've already found out by googling that Minecraft isn't supporting \t. I've tried copying functions from other people as well as writing my own to do the seperation with spaces, but I didn't manage to do it. So far i have this:
    [​IMG]
    So my question is if any of you ever ran into that problem or if anyone knows a solution to fix this.
    Thanks in advance!
     
  2. Offline

    pookeythekid

    If you have the names in a Set or List, or maybe a HashMap if you keep their scores like that, you could find a way to get the longest-named player. After looping through the Set/List/key set, loop through it again and compare each name to that longest name. Get the difference between each shorter name and the longest name, and keep track of how many more spaces you need to add to that shorter name; you could do this with a HashMap. Finally, with one more loop, you can print out the names with their added spaces, along with the "| <number>" after them.

    This is just the English version if it. It'll take a little bit of creativity to do it in Java.
     
  3. Offline

    xXHediusXx

    I can add spaces dynamically to how long the names are, I've set the maximum of namelength to 16, if the name is longer than that it gets cut to 16 characters. The problem is, that I isn't as broad as the L for instance and therefore it doesnt work.
     
  4. Offline

    mythbusterma

    xXHediusXx

    "L for instance?" What seems to be the issue here, just add spaces until the length is desirable?
     
  5. Offline

    Darkpicasa

    I think he means that the size of the "I" character is smaller than the "L" character.
    Because of that, his allignment is off.
     
  6. Offline

    mythbusterma

    Darkpicasa

    Ah. I wouldn't know how to fix that, other than calculating width in px.
     
  7. Offline

    Darkpicasa

    That's a possible approach, but there should be an easier way for something like this...
    But I can't think of one :(
     
  8. Offline

    teej107

  9. Offline

    Hoolean

    Unfortunately, there is no way to improve on that without calculating the width of each character with the default font. Even after doing this, you may find that a client uses their own texture pack, which may use an alternative font with different character widths.

    My advice would be to have the names not spaced evenly but with each column a different (albeit legible) colour; although the results will not be in line, it will still be very easy to read down a column and distinguish them. :)
     
    mythbusterma likes this.
  10. Offline

    mythbusterma

    xXHediusXx

    Alternatively, you could use the Scoreboard, which is kinda meant for stuff like this.
     
    es359 likes this.
  11. Offline

    xXHediusXx

    Yeah, I think I'm gonna go with scoreboards. For anyone interested, all the letters (upper case) are 6px wide, except the I, it's 4px. The numbers are 6px wide but for some reason they screw over the formatting as well (default texture pack).
     
Thread Status:
Not open for further replies.

Share This Page