Util Table generator

Discussion in 'Resources' started by FisheyLP, Aug 8, 2016.

Thread Status:
Not open for further replies.
  1. As simple as it sounds to generate a table and display it to a player, there's actually much more to it.

    Minecraft's font is not monospace. That means that some characters are wider (@ for example) and some are shorter (k for example).
    But don't worry, I implemented both fonts for either client or console :)

    How to use it:

    1. Initialize a new table generator:
    TableGenerator tg = new TableGenerator(Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT);
    This will be the alignment for the columns. It also defines the amount of columns (3 in this example).

    There are 3 available alignments:
    • left
    • right
    • center

    2. Add rows to it:
    tg.addRow("example", "§3§nLongest string");
    tg.addRow("§6left", "§ecenter", "§cright");
    tg.addRow("§aanother string", ":)", "the end.");
    It also has support for empty rows:
    As you can see in the first row, I only put 2 texts inside, but that doesn't matter, the third column will be empty.
    But providing more texts than available columns will cause an IllegalArgumentException to be thrown.

    3. Generate the table:
    tg.generate(Receiver receiver, boolean ignoreColors, boolean coloredDistances)
    • The receiver CLIENT is for the chat window (supports minecraft's custom font width).
    • The receiver CONSOLE is for the console (monospace font).
    The boolean ignoreColors will not count color codes as the text's length, when set to true.
    The boolean coloredDistances will make all distance chars appear in dark gray.
    Example of "distance chars" (open)

    These chars are almost not seeable with the gray chat window behind it, if noone told you that they're there before.

    It will return a List<String> of the rows.

    3.1 Displaying it to a player:
    for (String line : tg.generate(Receiver.CLIENT, true, true)) {
    3.2 Displaying it to the console:
    for (String line : tg.generate(Receiver.CONSOLE, true, false)) {
        // Or sender.sendMessage if you are using it inside onCommand
    4. Delimiter:
    The delimiter (currently " | ") can be changed if you want so.
    Simply edit the 'String delimiter' variable at the top of the class.

    Final result:

    The column widths are equal to the longest string in the current column for every row.

    GitHub repo: https://github.com/FisheyLP/TableGenerator
    Last edited: Feb 28, 2017
  2. Offline


    Cool. Arsen approves.
  3. Offline


Thread Status:
Not open for further replies.

Share This Page