EventComponent - ParzivalExe/guiapi GitHub Wiki
Overview
FromAn EventComponent is basically the equivalent to a Button in any normal Gui you would find for normal programs. When clicked, it will call the EventComponentClickedEvent
and close the gui (except if you specified it should not close the Gui when clicked through a field in which case it will act like a StaticComponent and simply stay at it's given place)
Implementation
EventComponents belong to the easier components to implement as well, since there isn't much except the looks you can change about them. Most of the customization of EventComponents is done through the called event EventComponentClickedEvent
, as you might already have guessed. So, here it the code for general implementation:
ComponentMeta eventComponentMeta = new ComponentMeta("EventButton", new ItemStack(Material.COMMAND_BLOCK));
//manipulate eventComponentMeta here
EventComponent eventComponent = new EventComponent(eventComponentMeta);
//manipulate eventComponent here
gui.addComponent(eventComponent);
As you can guess, there is again some manipulation of this object we can do. With the function setCloseGui(boolean);
you can choose weather the Gui should be closed when the Component is clicked and therefore when the Event is fired or if the Gui should remain open which would allow multiple presses and therefore multiple calls of this event. Because EventComponent was mainly envisioned as some sort of Button this is normally set to closeGui = true
.
And that's it. Everything else is handled through the EventComponentClickedEvent
. If you want to know how Events work, you can do so in the chapter Events.
Events
ComponentClickedEvent
= fired, when the EventComponent (or any other Component) is clicked
EventComponentClickedEvent
= fired, when the EventComponent 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"
)
closeGui="true|false"
= sets weather the Gui should be closed after the Component is clicked and the appropriate Event is fired (example: closeGui="true"
)
Resources
Component-Code: io.github.parzivalExe.guiApi.components.EventComponent
Great, now you know how to implement an EventComponent with a few lines. Next Component on the List is the MessageComponent.