MessageComponent - ParzivalExe/guiapi GitHub Wiki
Overview
FromThe MessageComponent simply shows the message
it holds to the player who clicked it inside his Ingame-Chat. After it was clicked it will also close the Gui since many players would otherwise probably miss the message send to them through the Ingame-Chat.
Implementation
The MessageComponent should already be quite familiar to you as you have probably already used it if you followed the Tutorial in the chapter First Component. As always the basic construct on how to create the component is basically the same:
ComponentMeta messageMeta = new ComponentMeta("HELLO WORLD", new ItemStack(Material.BARRIER);
//manipulate messageMeta here
MessageComponent messageComponent = new MessageComponent(messageMeta, "Hello World! ;)");
//manipulate messageComponent here
gui.addComponent(messageComponent);
The fields you can change for this components are for one, of course, the message itself with messageComponent.setMessage("Hello World");
, but in the example above, we did this already with a special constructor that also took the message as it's second argument. The second field we can manipulate is the colorCodeChar
which is normally set to colorCodeChar = '&'
. What the colorCodeChar
does is actually pretty simple. All messages send by the MessageComponent can contain ChatColorCodes and the ColorCodeChar defines now, which prefix these ColorCodes should use to be recognized as such. For example, when you setColorCodeChar('!')
you have to write messageComponent.setMessage("!4Red");
to get a red message to appear.
Events
ComponentClickedEvent
= fired, when the MessageComponent (or any other Component) is clicked
MessageComponentClickedEvent
= fired, when the MessageComponent is clicked
XML-Attributes
title="{Component-Title}"
= sets the Title of this Component (example: title="Hello World"
)
look="{AMOUNT}xID:{DATA}{[DURABILITY]}"
= sets the Look of this Component (example: look="3x322:1"
or look="3xGOLDEN_APPLE"
)
description="[{line1}, {line2}...]"
= sets the description of this Component (example: description="[This is a Description, with a \,]"
)
place="{PLACE}"
= sets the place this Component should be placed at in the Gui (example: place="4"
)
message="{message}"
= sets the message this MessageComponent should send when clicked (example: message="Hello World"
)
colorCodeChar="{ColorPrefix}"
= sets the colorCodePrefix this message should use when coloring it's message. Important is, that this can only be one character since it will be converted into a char in the final program (example: colorCodeChar="&"
)
Resources
Component-Code: io.github.parzivalExe.guiApi.components.MessageComponent
Great, now you know how to implement a MessageComponent with a few lines. Next Component on the List is the TeleportComponent.