-
Notifications
You must be signed in to change notification settings - Fork 0
Utlis
The JuliGamesCore has a variety of util classes all over the different modules. On this page, I want to introduce you to some of these classes and their features to help you out with tasks that are already done in the Core. I will split this into two different sections:
- static utils
- non-static utils
The static utils are just classes with public static methods that can help you out with developing using the Core and the non-static ones are classes that are not accessible through
API.get()
orCore.getInstance()
.
I will use the natural order of the modules in the project to sort the different entries here
net.juligames.core.adventure.api.MessageRepresentation
This class is an implementation of the Adventure interface ComponentLike
and can be used for converting between Messages from the Core and Components from Adventure. You can use this implementation by creating an instance of it with the message you want to represent. You should be able to use this MessageRepresentation as a parameter for Component demanding methods now!
Example:
final Audience audience = Audience.empty();
final MessageRecipient messageRecipient = AudienceMessageRecipient.getByPointer(audience);
final Message helloWorld =
API.get().getMessageApi().findBestMessageForRecipient("helloworld.message", messageRecipient);//italy (just an example)
final MessageRepresentation messageRepresentation = new MessageRepresentation(helloWorld);
audience.showTitle(Title.title(messageRepresentation.asComponent(), Component.empty()));
audience.sendMessage(messageRepresentation);
audience.sendActionBar(messageRepresentation);
audience.sendPlayerListHeaderAndFooter(messageRepresentation, Component.empty());
Please note that this example just shows the syntax. You can use a different way to get hold of a Message
object then using findBestMessageForRecipient
!
As we defined above this class is not a "static util", but I suggest using the static factory methods that are provided to avoid the pain we had in the example above. So let us do what we did in the example above but using the factory methods:
Example:
final Audience audience = Audience.empty();
final MessageRepresentation messageRepresentation = MessageRepresentation.represent("helloworld.message", audience);
audience.showTitle(Title.title(messageRepresentation.asComponent(), Component.empty()));
audience.sendMessage(messageRepresentation);
audience.sendActionBar(messageRepresentation);
audience.sendPlayerListHeaderAndFooter(messageRepresentation, Component.empty());
As we see it is much easier to do so, but it is not as dynamic and versatile as the first option. If possible I would suggest using this static approach. We also need to keep in mind that this MessageRepresentation
should not be used for just sending messages.
net.juligames.core.adventure.api.prompt.BackedPrompt
net.juligames.core.adventure.api.prompt.ConfigurationPrompt
net.juligames.core.adventure.api.prompt.DictionaryBackedPrompt
net.juligames.core.adventure.api.prompt.IndexBackedPrompt
net.juligames.core.adventure.api.prompt.MapBackedPrompt
net.juligames.core.adventure.api.prompt.MiniMessagePrompt
net.juligames.core.adventure.api.prompt.NamedTextColorPrompt
net.juligames.core.adventure.api.prompt.SpacePrompt
net.juligames.core.adventure.api.prompt.VoidPrompt
net.juligames.core.adventure.api.LegacyMessageDealer
The LegacyMessageDealer is a utility implementation of CustomMessageDealer
. This implementation allows you to convert legacy messages to miniMessages using Adventure. You might need to give a CustomMessageDealer
as a parameter in different methods. This can be used for example to introduce legacy messages into the message system. We know that only valid MiniMessages with or without replacements are allowed in the message system database, so we need to convert the legacy message to an accepted format.
Example:
API.get().getMessageApi().registerThirdPartyMessage(
"legacyplugin.message1",
"&1 This is a legacy message",
new LegacyMessageDealer(LegacyMessageType.AMPERSAND));
Here we also use the LegacyMessageType (net.juligames.core.api.message.LegacyMessageType)!
If you need assistance with your setup, development, or configuration, feel free to reach out to me via email ©Ture Bentzin 2023