Interface Message


public interface Message
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
    • 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
    • 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
    • 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
    • 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