-
Notifications
You must be signed in to change notification settings - Fork 1
Messages
Plugin messages are represented by Message objects. Messages implement the ComponentLike interface of Adventure and can be used wherever you would normally use Components (Chat messages, books, scoreboard, GUI title, item names/lores, ...).
The identifier of a Message is the combination of a namespace and a key.
The namespace is the path to the Translation application separated by dots (.
).
The namespace of the global Translations instance is global
, every fork of it with name xy has the namespace global.xy
and so forth.
The key of a message is the identifier within any Translations instance. Like error.no_perm
or prefix
.
In combination, the PathFinder plugin would have a Message of namespaced key global.PathFinder:prefix
.
The Translations instance will load all messages from specified locale files (see chapter about storages) and store the translated value into the according dictionary of a Message.
When converting a Message to a Component, it will use the default locale en
and load its value from the dictionary.
See per player locale if you want to specify a locale.
A message needs a reference to any Translations instance to function. Therefore, you must either create the Message directly from a Translations, or assign them before using them.
Create them from Translations:
private Message prefix = null;
void anyContext(Translations t) {
prefix = t.message("prefix");
//or
prefix = t.messageBuilder("prefix").withDefault("<rainbow>Prefix</rainbow> ").build();
}
Assign them later:
public static final Message PREFIX = new MessageBuilder("prefix").withDefault("<rainbow>Prefix</rainbow> ").build();
void anyContext(Translations t) {
t.addMessage(PREFIX);
// or simply add all constants from a class with
t.addMessages(TranslationsFramework.messageFieldsFromClass(MyMessagesClass.class));
}