New Message Api

In the past, if I wanted to create a message, this is what I would do:

public Message derpyMessage() {
    return Messages.builder("DERPYNESS").color(TextColors.GREEN).build();

That does not work anymore. Now Sponge uses Text and TextBuilder. Could anyone show me how to create a message using these new classes?

Read the docs!

1 Like

That still shows Messages though…

Not helpful, the docs haven’t updated yet…

Ok, I see that apologies, still take a look at the github source. They seem to work similarly?

You are right, they do!

public Message createStuff() {
    return Messages.of("HI").builder().color(TextColors.GREEN).build();

public Text createNewStuff() {
    return Texts.of("HI").builder().color(TextColors.GREEN).build();

How would you use the newest version through Maven?

LATEST doesnt work, and 1.1-SNAPSHOT doesnt have it.

The new message api is still part of 1.1-SNAPSHOT. All you have to do is re download your dependencies.

I have updated most of the Text docs in my fork here. However, the Selector section is still not updated.

Hope it helps

1 Like

We’ve actually added a new way to create Text instances to make it easier when creating simple messages. This looks similar to code written for Bukkit. For example, this code on Bukkit:

player.sendMessage(ChatColor.RED + "You don't have permission for this command");

Can be written like this on Sponge:

player.sendMessage(Texts.of(TextColors.RED, "You don't have permission for this command"));

Additionally I would like to point out you should not use methods only to create static Text instances like in the examples posted above. Instead, Text instances are perfect to use as static (constant) instances, for example like this:

public static final Text NO_PERMISSION = of(TextColors.RED, "You don't have permission for this command");

// Somewhere in the code

How would I go about re-downloading the dependencies?.. I am not too familiar with Maven but I am trying to get adept to using it.

Depends what IDE you have…

Well, in a case in which you only have maven integrated in your IDE yes, if you have maven on your machine I think you can run

mvn clean install -U

that will build the project while updating dependencies
or you could run

mvn dependency:resolve

Which should only update all your dependencies without building.

Well it is eclipse, which most people use to my knowledge.

In that case right click the root project folder, go into the Maven submenu of the context menu that appears then click “Update Project” then make sure the “Update Snapshots” box is checked and press the “OK” button.

Also, yes, most people seem to use eclipse, but you really never know.

1 Like

Yes it is true. Sorry for sounding snide. I tend to use netbeans too but have voided from it this time around because it has quite the CPU issues with Mac.

Thank you for your help!

1 Like