-
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()
.
Note: I will add "prompts" to this list. This are classes that can be used together with ConversationLIB, but I will not include normal Interpreters here!
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)!
net.juligames.core.api.err.dev.TODOException
The TODOException can be used in methods that are still in development but the current version should be compiled. I always recommend using this Exception together with the @TODO
Annotation. The Exception will display the following text: "not implemented yet"!
Example:
/**
* @return if the core is connected and ready for operation
*/
@TODO(doNotcall = true)
public boolean isAlive() {
throw new TODOException();
}
This code is part of the Core since the Michael versions because i still haven't figured out a 100% save way to identify if the connection of the Core is alive or not...
net.juligames.core.api.err.APIException
This exception can be used if an implementation to a service or core is missing. Currently, it is only used internally.
net.juligames.core.api.external.AdventureWebuiEditorAPI
This class is a bit more exciting than what we had above. This class allows you to interact with an AdventureWebUI. You can use this class to start and retrieve sessions and so display and change miniMessages. If you want further information on the adventure-webui API then check out their wiki: Editor-API Wiki.
Example:
final AdventureWebuiEditorAPI adventureWebuiEditorAPI
= new AdventureWebuiEditorAPI(); //default juligames production webui
//generate a link for a new empty session
String link = adventureWebuiEditorAPI.startSessionAndGenerateLink("/yourCommand {token}");
//give the link to the user now
//this would be executed in your "command execution" - to retrieve the session back
String[] args = new String[1]; // the "args"
CompletableFuture<String> stringCompletableFuture = adventureWebuiEditorAPI.retrieveSession(args[0]);
try {
String miniMessage = stringCompletableFuture.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
This Example shows a way to use this API
If you need assistance with your setup, development, or configuration, feel free to reach out to me via email ©Ture Bentzin 2023