java.lang.Object
me.wiefferink.interactivemessenger.processing.Message

public class Message extends Object
  • Field Details

  • Method Details

    • init

      public static void init(MessageProvider provider, Logger logger)
      Initialize the Message class
      Parameters:
      provider - The provider to use for getting messages based on keys
      logger - The logger to use for logging warning and error messages
    • empty

      public static Message empty()
      Empty message object
      Returns:
      this
    • fromKey

      public static Message fromKey(String key)
      Construct a message from a language key Requires a MessageProvider to be set
      Parameters:
      key - The key of the message to use
      Returns:
      this
    • fromString

      public static Message fromString(String message)
      Construct a message from a string
      Parameters:
      message - The message to use
      Returns:
      this
    • fromList

      public static Message fromList(List<String> message)
      Construct a message from a string list
      Parameters:
      message - The message to use
      Returns:
      this
    • useFancyMessages

      public static void useFancyMessages(boolean enabled)
      Enable or disable the use of fancy messages
      Parameters:
      enabled - true to enable, false to disable
    • useColorsInConsole

      public static void useColorsInConsole(boolean enabled)
      Enable or disable the use of colors when sending a message to a target that is not a Player (console, log, etcetera)
      Parameters:
      enabled - true to enable, false to disable
    • get

      public List<String> get()
      Get the message with all replacements done
      Returns:
      Message as a list
    • getSingle

      public String getSingle()
      Get the message with all replacements done
      Returns:
      Message as a string
    • getSingle

      public String getSingle(Limit limit) throws ReplacementLimitReachedException
      Get the message with all replacements done
      Parameters:
      limit - Limit to use while processing
      Returns:
      Message as a string
      Throws:
      ReplacementLimitReachedException - when the limit is reached
    • getRaw

      public List<String> getRaw()
      Get the raw message without replacing anything
      Returns:
      The message
    • getSingleRaw

      public String getSingleRaw()
      Get raw message as string
      Returns:
      The raw message
    • getPlain

      public String getPlain()
      Get a plain string for the message (for example for using in the console)
      Returns:
      The message as simple string
    • isEmpty

      public boolean isEmpty()
      Check if the message is empty
      Returns:
      true if the message is empty, otherwise false
    • prefix

      public Message prefix(boolean doIt)
      Add the default prefix to the message (if the message is not empty)
      Parameters:
      doIt - true if the prefix should be added, otherwise false
      Returns:
      this
    • prefix

      public Message prefix()
      Add the default prefix to the message
      Returns:
      this
    • replacements

      public Message replacements(Object... replacements)
      Set the replacements to apply to the message
      Parameters:
      replacements - The replacements to apply - GeneralRegion: All region replacements are applied - Message: Message is inserted - other: index tag is replaced, like %0%
      Returns:
      this
    • append

      public Message append(List<String> lines)
      Append lines to the message
      Parameters:
      lines - The lines to append
      Returns:
      this
    • append

      public Message append(Message message)
      Append a message to this message
      Parameters:
      message - The message to append
      Returns:
      this
    • append

      public Message append(String line)
      Append lines to the message
      Parameters:
      line - The line to append
      Returns:
      this
    • prepend

      public Message prepend(List<String> lines)
      Prepend lines to the message
      Parameters:
      lines - The lines to prepend
      Returns:
      this
    • prepend

      public Message prepend(Message message)
      Prepend a message to this message
      Parameters:
      message - The message to prepend
      Returns:
      this
    • prepend

      public Message prepend(String line)
      Prepend lines to the message
      Parameters:
      line - The line to prepend
      Returns:
      this
    • noLanguageReplacements

      public Message noLanguageReplacements()
      Turn off language replacements for this message
      Returns:
      this
    • inline

      public Message inline()
      Mark this message as inline, used for insertion into other messages
      Returns:
      this
    • send

      public Message send(Object target)
      Send the message to a target
      Parameters:
      target - The target to send the message to (Player, CommandSender, Logger)
      Returns:
      this
    • getKey

      public String getKey()
      Get the key that has been used to initialize this message (if any)
      Returns:
      Key used to create this message, or null if none
    • doReplacements

      public Message doReplacements()
      Apply all replacements to the message
      Returns:
      this
    • doReplacements

      public Message doReplacements(Limit limit) throws ReplacementLimitReachedException
      Apply replacements to the message using a certain Limit (intended for internal and testing use)
      Parameters:
      limit - Limit to apply
      Returns:
      this
      Throws:
      ReplacementLimitReachedException - When the limit has been hit before replacement is finished
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getMessageStart

      public static String getMessageStart(Message message, int maximumLength)
      Get a start of the message with a maximum length
      Parameters:
      message - The message
      maximumLength - The maximum length to return
      Returns:
      The start of the message with at most maximumLength characters