Interface Message

All Superinterfaces:
Cloneable

public interface Message extends Cloneable
Easily hook into the messages system of MBedwars using this class.

By this, you're e.g. able to work with messages from the messages file or able to easily replace placeholders / chatcolors etc. Start with build(String), buildByKey(String) or buildByKey(String, String)

  • Method Details

    • getRawMessage

      String getRawMessage(@Nullable @Nullable String locale)
      This method is essential for the message processor. It returns the String that shall be processed
      Parameters:
      locale - Tries to find the message in the given locale. If it doesn't find any or if locale=null then it'll pick the default one
      Returns:
      The raw/unformatted message
    • getInputString

      String getInputString()
      Get the string that has been inserted.

      The string can later be parsed to the same message using build(String). It may does not match *exactly* when this instance has been constructed i.a. buildByKey(String). In that case, it is being surrounded with % signs, to make it parseable by build(String).

      Returns:
      The input string that has been inserted during the construction of this instance
    • getDefaultString

      @Nullable @Nullable String getDefaultString()
      Returns the default string in case no matching message has been found by the key.

      This only applies when buildByKey(String, String) has been used.

      Returns:
      The default string. null if none is being used
    • placeholder

      Message placeholder(String key, String value)
      Adds a placeholder to the message.

      It'll later reformat it from {key} to the value.

      Parameters:
      key - The name of the placeholder
      value - What the placeholder represents
      Returns:
      This instance
    • placeholder

      default Message placeholder(String key, Object value)
      Adds a placeholder to the message.

      It'll later reformat it from {key} to the value.

      Parameters:
      key - The name of the placeholder
      value - What the placeholder represents
      Returns:
      This instance
    • getPlaceholder

      @Nullable @Nullable String getPlaceholder(String key)
      Obtains the value of a placeholder that has been previously added.
      Parameters:
      key - The key of the placeholder
      Returns:
      Its value. null if it hasn't been added yet
    • clearPlaceholders

      void clearPlaceholders()
      Removes all previously added placeholders to this instance.
    • done

      String done(@Nullable @Nullable CommandSender sender, boolean freeInstance)
      Will put the message into the MessageProccessor and returns its result.

      Message instances are stored in a pool to decrease memory usage.
      By that they must be putten back when not used anymore. Or in other words: set "freeInstance" to false when you want to store this instance inside the memory

      This method also automatically replaces PAPI placeholders, in case this feature is enabled the user.

      Parameters:
      sender - Will take his language, otherwise the default language when null
      freeInstance - If it should put this instance back into the pool or not
      Returns:
      The final String
    • done

      default String done(@Nullable @Nullable CommandSender sender)
      Same as done(CommandSender, boolean) and puts this instance automatically back into the pool
      Parameters:
      sender - Will take his language, otherwise the default language when null
      Returns:
      The final String
    • done

      String done(@Nullable @Nullable RemotePlayer sender, boolean freeInstance)
      Will put the message into the MessageProccessor and returns its result.

      Message instances are stored in a pool to decrease memory usage.
      By that they must be putten back when not used anymore. Or in other words: set "freeInstance" to false when you want to store this instance inside the memory

      This method also automatically replaces PAPI placeholders, in case this feature is enabled the user.

      Parameters:
      sender - Will take his language, otherwise the default language when null
      freeInstance - If it should put this instance back into the pool or not
      Returns:
      The final String
    • done

      default String done(@Nullable @Nullable RemotePlayer sender)
      Same as done(RemotePlayer, boolean) and puts this instance automatically back into the pool
      Parameters:
      sender - Will take his language, otherwise the default language when null
      Returns:
      The final String
    • done

      String done(@Nullable @Nullable CommandSenderWrapper sender, boolean freeInstance)
      Will put the message into the MessageProccessor and returns its result.

      Message instances are stored in a pool to decrease memory usage.
      By that they must be putten back when not used anymore. Or in other words: set "freeInstance" to false when you want to store this instance inside the memory

      This method also automatically replaces PAPI placeholders, in case this feature is enabled the user.

      Parameters:
      sender - Will take his language, otherwise the default language when null
      freeInstance - If it should put this instance back into the pool or not
      Returns:
      The final String
    • done

      default String done(@Nullable @Nullable CommandSenderWrapper sender)
      Same as done(CommandSenderWrapper, boolean) and puts this instance automatically back into the pool
      Parameters:
      sender - Will take his language, otherwise the default language when null
      Returns:
      The final String
    • done

      default String done(boolean freeInstance)
      Will put the message into the MessageProccessor and returns its result.

      Message instances are stored in a pool to decrease memory usage.
      By that they must be putten back when not used anymore. Or in other words: set "freeInstance" to false when you want to store this instance inside the memory

      This method also automatically replaces PAPI placeholders, in case this feature is enabled the user.

      Parameters:
      freeInstance - If it should put this instance back into the pool or not
      Returns:
      The final String
    • done

      default String done()
      Will put the message into the MessageProccessor and returns the result.

      Does the same as done(CommandSender), but passes null as sender.
      Also puts this instance automatically back into the pool

      Returns:
      The final String
    • send

      default void send(CommandSender sender)
      Computes it and sends it to the person
      Parameters:
      sender - The target
    • send

      default void send(CommandSenderWrapper sender)
      Computes it and sends it to the person
      Parameters:
      sender - The target
    • send

      default void send(RemotePlayer sender)
      Computes it and sends it to the person
      Parameters:
      sender - The target
    • send

      void send(CommandSender sender, boolean freeInstance)
      Computes it and sends it to the person
      Parameters:
      sender - The target
      freeInstance - If it should put this instance back into the pool or not
    • send

      void send(CommandSenderWrapper sender, boolean freeInstance)
      Computes it and sends it to the person
      Parameters:
      sender - The target
      freeInstance - If it should put this instance back into the pool or not
    • send

      void send(RemotePlayer sender, boolean freeInstance)
      Computes it and sends it to the person
      Parameters:
      sender - The target
      freeInstance - If it should put this instance back into the pool or not
    • free

      boolean free()
      Messages are stored in a pool to reduce memory usage. Invoke this method when you're done using it and want to put it back manually.
      Keep in mind that the methods done() and done(CommandSender) automatically are putting this instance back into memory unless told otherwise using the parameter "freeInstance".
      Returns:
      false if it's already in the pool
    • isFreed

      boolean isFreed()
      Returns whether the Message instance has been put back to the pool or not.
      Returns:
      If it has been freed by now
    • cloneNonUpcyable

      Message cloneNonUpcyable()
      Clones the current Message and creates a non-freeable variant.

      You may use it in sensible parts where you want to make sure that the instance 100% doesn't get freed at any moment.

      Returns:
      A new instance that can't be put back into the pool
    • clone

      Message clone()
      Clones an exact replica.
      Returns:
      A cloned instance
    • build

      static Message build(String rawMessage)
      Creates an instance of a message.

      It's being taken from a pool for greater performance.
      Make sure that you won't use the instance after you ran done() or done(CommandSender). Otherwise the system will break.

      Parameters:
      rawMessage - The raw/unformatted message containing the placeholders, color codes etc.
      Returns:
      An instance of Message to pass parameters
    • build

      static Message build(String... lines)
      Creates an instance of a message that persists of multiple lines.

      It's being taken from a pool for greater performance.
      Make sure that you won't use the instance after you ran done() or done(CommandSender). Otherwise the system will break.

      Parameters:
      lines - The lines in a raw/unformatted format containing the placeholders, color codes etc.
      Returns:
      An instance of Message to pass parameters
    • build

      static Message build(List<String> lines)
      Creates an instance of a message that persists of multiple lines.

      It's being taken from a pool for greater performance.
      Make sure that you won't use the instance after you ran done() or done(CommandSender). Otherwise the system will break.

      Parameters:
      lines - The lines in a raw/unformatted format containing the placeholders, color codes etc.
      Returns:
      An instance of Message to pass parameters
    • buildByKey

      static Message buildByKey(String key, String def)
      Creates an instance of a message.

      It's being taken from a pool for greater performance. Make sure that you won't reuse the instance after you ran done() or done(CommandSender). Otherwise the system will break.

      The difference to the build(String) method is that this one will first try to get the key from the messages file. It'll use the given def String if it hasn't been found.

      Parameters:
      key - Will look for this key in the messages file
      def - Uses this if it hasn't found it in the messages file
      Returns:
      An instance of Message to pass parameters
    • buildByKey

      static Message buildByKey(String key)
      Creates an instance of a message.

      It's being taken from a pool for greater performance. Make sure that you won't reuse the instance after you ran done() or done(CommandSender). Otherwise the system will break.

      The difference to the build(String) method is that this one will first try to get the key from the messages file. It'll use the given def String if it hasn't been found
      Uses they key itself if it does not exist.

      Parameters:
      key - Will look for this key in the messages file
      Returns:
      An instance of Message to pass parameters