I’m currently looking at @sk89q’s example plugin for the command syntax and by looking at it it seems I need a new class for each command. Would I be right in assuming this or can I have multiple commands in the one class?
Also, the sendMessage syntax confuses me a fair bit and I was wondering how I’d send a coloured message to a player. I’ve currently got the below though there’s something telling me it’s wrong.
player.sendMessage(TextColors.DARK_AQUA + 'This is a string');
If the above syntax is wrong, could someone please correct me. Thanks.
As for the player message you are missing a chat type you can find theme in the sponge API chat types located here.
As far as I can tell you do need class per command though I could be wrong on this.
player.sendMessage(
Message.builder("This is ").color(TextColors.DARK_AQUA).append(
Message.builder("a string").color(TextColors.GOLD).build()
.build()
);
Appending more messages after that is easier:
Message.builder("This is ").color(TextColors.DARK_AQUA).append(
Message.builder("a string").color(TextColors.GOLD).build())
).append(
Message.builder("and another string").color(TextColors.GREEN).build())
.build()
Yes, that definitely looks nicer. Also, what @Pink__Slime said is logical, actually makes a lot of sense. Many builders for different Objects do it that way (ex: The artemis entity builder / Entity.edit()). They return a builder Object after you add something so you can chain the methods.
Usage Example
MessageBuilder builder = new MessageBuilder();
Message message = builder.color(TextColors.GOLD)
.text("This is a string...")
.append(yourExistingMessage)
.color(TextColors.GREEN)
.text("Green text.")
.link("http://www.google.com")
.color(TextColors.AQUA)
.text("This is link text added to the link mesage builder.")
.close()
.text("TNT!!!!")
.build()
The link method returns a new specific MessageBuilder for the links label. By calling close, you end the link and make it return the parent MessageBuilder.