Class MessageBuilder
This class should be instantiated in a plugin's onEnable method, and the build method compose is called
with a CommandSender as recipient and an enum constant whose name is used to reference the message key defined
in the language file. Macro replacements can then be assigned with a chained method call to
the setMacro method, which can be repeated as necessary to set all the macros to be replaced
in the message string. Finally, the send method is called as a final chained method call
to effectuate the actual sending of the message.
If the message is configured in the language file with a repeat-delay, an entry will be added to the message cooldown map for the player / message, and a task started to remove the entry from the cooldown map after the configured repeat-delay time has elapsed.
example:
MessageBuilder messageBuilder = MessageBuilder.create(plugin)
messageBuilder.compose(recipient, MessageId.MESSAGE_KEY)
.setMacro(Macro.PLACEHOLDER1, object)
.setMacro(Macro.PLACEHOLDER2, replacementString)
.send();
Note that any object may be passed as the replacement string, which will be converted using
that object's toString method. Some placeholders, such as RECIPIENT, PLUGIN and SERVER are
automatically populated along with any subfields in all messages and are therefore always
available as message placeholders,
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncompose(org.bukkit.command.CommandSender recipient, E messageId) Initiate the message building sequence.config()Provides external access to the config repositoryProvides external access to the constant repositorystatic MessageBuildercreate(org.bukkit.plugin.Plugin plugin) A static factory method for instantiating this class.items()Provides external access to the item repositorybooleanreload()Reload resourcessounds()Provides external access to the sound repositoryworlds()Provides external access to the enabled worlds provider
-
Field Details
-
TICKS
-
-
Method Details
-
create
A static factory method for instantiating this class. Due to the necessity of performing file I/O operations to instantiate this class, this static method has been provided to perform the potentially blocking operations before instantiation.The I/O dependencies are then injected into the constructor of the class, which is declared package-private to prevent instantiation from outside this class except by use of this static factory method. Finally, if successfully instantiated, an instance of the class will be returned. If file operations fail, the object will not be left in a partially instantiated state.- Returns:
- an instance of this class
-
compose
Initiate the message building sequence. Parameters of this method are passed into this library domain from the plugin, so robust validation is employed and type-safety is enforced by converting to domain specific types and validating on creation. If a nullCommandSenderis passed as the recipient parameter, an empty, no-op message is returned, as it is plausible a null or invalid value could be passed. The enum constant messageId parameter, conversely, cannot be null under normal conditions, and therefore throws a validation exception if a null is encountered.- Parameters:
recipient- the command sender to whom the message will be sentmessageId- the message identifier enum constant- Returns:
Messagean initialized message object
-
reload
public boolean reload()Reload resources -
config
Provides external access to the config repository -
constants
Provides external access to the constant repository -
items
Provides external access to the item repository -
sounds
Provides external access to the sound repository -
worlds
Provides external access to the enabled worlds provider
-