Class TextSizer

java.lang.Object
studio.magemonkey.codex.mccore.util.TextSizer

public class TextSizer extends Object
Handles measuring the size of strings and squaring them up Units for sizes are based off of the space between characters (e.g. size 4 = the size of 4 of the spaces between characters)
  • Constructor Details

    • TextSizer

      public TextSizer()
  • Method Details

    • measureString

      public static int measureString(String message)
      Gets the size of the message
      Parameters:
      message - message to measure
      Returns:
      message size
    • expand

      public static String expand(String message, int size, boolean front)
      Expands a string to meet the desired size
      Parameters:
      message - message to expand
      size - desired size
      front - whether or not to add to the front of the string
      Returns:
      the resulting message
      Throws:
      IllegalArgumentException - when the string is either too large or just one pixel too small
    • expand

      public static List<String> expand(List<String> messages, boolean front)
      Expands the messages so that they are all the same size Note: this adds a space to the end of the longest string to ensure it can square them all
      Parameters:
      messages - messages to expand
      front - whether or not to add to the front
      Returns:
      list of expanded strings
    • expandConsole

      public static String expandConsole(String message, int size, boolean front)
      Expands a string to meet the desired size for the console
      Parameters:
      message - message to expand
      size - desired size
      front - whether or not to add to the front of the string
      Returns:
      the resulting message
      Throws:
      IllegalArgumentException - when the string is too large or null
    • split

      public static List<String> split(List<String> messages, boolean vertical, TextSizer.TextAlignment... alignments)

      Splits the list of messages into a number of columns equal to the number of alignments provided. Columns from left to right will have the provided alignments in order. The returned list contains the rows resulting from the arrangement.

      The vertical parameter refers to what order the messages are added to columns. If true, then messages will appear in the following pattern assuming 3 columns and 8 elements:

      0 3 6

      1 4 7

      2 5

      If set to false, the messages will appear in this pattern instead:

      0 1 2

      3 4 5

      6 7

      Parameters:
      messages - messages to split into columns
      vertical - whether to apply messages vertically
      alignments - the alignments for each column
      Returns:
      the arranged message rows
    • split

      public static List<String> split(String message, int maxSize)
      Splits a string to fit within the given size, breaking it up by word
      Parameters:
      message - message to split
      maxSize - maximum size of each line
      Returns:
      resulting lines
    • createLine

      public static String createLine(String begin, String end, String fill)
      Creates a line that is the maximum size allowed in the chat box using the given info
      Parameters:
      begin - beginning string
      end - ending string
      fill - string to fill with
      Returns:
      maximum size string line
    • createLine

      public static String createLine(String begin, String end, String fill, org.bukkit.ChatColor fillColor)
      Creates a line that is the maximum size allowed in the chat box using the given info
      Parameters:
      begin - beginning string
      end - ending string
      fill - string to fill with
      fillColor - color to apply to the fill
      Returns:
      maximum size string line
    • createLine

      public static String createLine(String middle, String fill, org.bukkit.ChatColor fillColor)
      Creates a line that is the maximum size allowed in the chat box using the given info
      Parameters:
      middle - middle string
      fill - string to fill the line with
      Returns:
      line string