Skip to content
Ture Bentzin edited this page Apr 16, 2023 · 9 revisions

Let's talk about Utils

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() or Core.getInstance().

I will use the natural order of the modules in the project to sort the different entries here

AdventureAPI

MessageRepresentation : non-static

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!

Clone this wiki locally