Interface Message
- All Superinterfaces:
Cloneable
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 Summary
Modifier and TypeMethodDescriptionstatic Message
Creates an instance of a message.static Message
Creates an instance of a message that persists of multiple lines.static Message
Creates an instance of a message that persists of multiple lines.static Message
buildByKey
(String key) Creates an instance of a message.static Message
buildByKey
(String key, String def) Creates an instance of a message.void
Removes all previously added placeholders to this instance.clone()
Clones an exact replica.Clones the current Message and creates a non-freeable variant.default String
done()
Will put the message into the MessageProccessor and returns the result.default String
done
(boolean freeInstance) Will put the message into the MessageProccessor and returns its result.default String
done
(@Nullable RemotePlayer sender) Same asdone(RemotePlayer, boolean)
and puts this instance automatically back into the pooldone
(@Nullable RemotePlayer sender, boolean freeInstance) Will put the message into the MessageProccessor and returns its result.default String
done
(@Nullable CommandSenderWrapper sender) Same asdone(CommandSenderWrapper, boolean)
and puts this instance automatically back into the pooldone
(@Nullable CommandSenderWrapper sender, boolean freeInstance) Will put the message into the MessageProccessor and returns its result.default String
Same asdone(String, boolean)
and puts this instance automatically back into the poolSame asdone(CommandSender, boolean)
.default String
done
(@Nullable CommandSender sender) Same asdone(CommandSender, boolean)
and puts this instance automatically back into the pooldone
(@Nullable CommandSender sender, boolean freeInstance) Will put the message into the MessageProccessor and returns its result.boolean
free()
Messages are stored in a pool to reduce memory usage.@Nullable String
Returns the default string in case no matching message has been found by the key.Get the string that has been inserted.@Nullable String
getPlaceholder
(String key) Obtains the value of a placeholder that has been previously added.getRawMessage
(@Nullable String locale) This method is essential for the message processor.boolean
isFreed()
Returns whether the Message instance has been put back to the pool or not.default Message
placeholder
(String key, Object value) Adds a placeholder to the message.placeholder
(String key, String value) Adds a placeholder to the message.default void
send
(RemotePlayer sender) Computes it and sends it to the personvoid
send
(RemotePlayer sender, boolean freeInstance) Computes it and sends it to the persondefault void
send
(CommandSenderWrapper sender) Computes it and sends it to the personvoid
send
(CommandSenderWrapper sender, boolean freeInstance) Computes it and sends it to the persondefault void
send
(CommandSender sender) Computes it and sends it to the personvoid
send
(CommandSender sender, boolean freeInstance) Computes it and sends it to the person
-
Method Details
-
getRawMessage
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 bybuild(String)
.- Returns:
- The input string that has been inserted during the construction of this instance
-
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
Adds a placeholder to the message.It'll later reformat it from {key} to the value.
- Parameters:
key
- The name of the placeholdervalue
- What the placeholder represents- Returns:
- This instance
-
placeholder
Adds a placeholder to the message.It'll later reformat it from {key} to the value.
- Parameters:
key
- The name of the placeholdervalue
- What the placeholder represents- Returns:
- This instance
-
getPlaceholder
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
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 memoryThis 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 nullfreeInstance
- If it should put this instance back into the pool or not- Returns:
- The final String
-
done
Same asdone(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
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 memoryThis 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 nullfreeInstance
- If it should put this instance back into the pool or not- Returns:
- The final String
-
done
Same asdone(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
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 memoryThis 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 nullfreeInstance
- If it should put this instance back into the pool or not- Returns:
- The final String
-
done
Same asdone(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
Same asdone(CommandSender, boolean)
.We will fallback to the default language if the locale is not found. See
MessageAPI.getStoredLocales()
to see a list of all available locales.- Parameters:
locale
- The name of the locale that shall be usedfreeInstance
- If it should put this instance back into the pool or not- Returns:
- The final String
-
done
Same asdone(String, boolean)
and puts this instance automatically back into the pool- Parameters:
locale
- The name of the locale that shall be used- Returns:
- The final String
-
done
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 memoryThis 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
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
Computes it and sends it to the person- Parameters:
sender
- The target
-
send
Computes it and sends it to the person- Parameters:
sender
- The target
-
send
Computes it and sends it to the person- Parameters:
sender
- The target
-
send
Computes it and sends it to the person- Parameters:
sender
- The targetfreeInstance
- If it should put this instance back into the pool or not
-
send
Computes it and sends it to the person- Parameters:
sender
- The targetfreeInstance
- If it should put this instance back into the pool or not
-
send
Computes it and sends it to the person- Parameters:
sender
- The targetfreeInstance
- 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 methodsdone()
anddone(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
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 randone()
ordone(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
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 randone()
ordone(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
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 randone()
ordone(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
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()
ordone(CommandSender)
. Otherwise the system will break.
The difference to thebuild(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 filedef
- Uses this if it hasn't found it in the messages file- Returns:
- An instance of Message to pass parameters
-
buildByKey
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()
ordone(CommandSender)
. Otherwise the system will break.
The difference to thebuild(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
-