StaticComponent - ParzivalExe/guiapi GitHub Wiki
Overview
FromStaticComponents are the easiest as they have no features. They are simply a component that, when clicked, doesn't do anything, meaning that it instantly cancels the interaction.
Therefore StaticComponents can be used either for decorations like creating a border around important components with different colored glass or for transferring information to the player by it's Title
and Description
.
There is however also a different use for StaticComponents you first wouldn't think of as you can add a clickAction
with usage of a ClickListener and use a StaticComponent as an easy Button without messing around with Bukkit-Events as using no Bukkit-Events is actually easier in many instances.
Implementation
When you simply need a StaticComponent without any Logic behind it, then implementing a StaticComponent is easier than implementing any other Component. Simply write:
ComponentMeta staticMeta = new ComponentMeta("StaticComponent", new ItemStack(Material.RED_STAINED_GLASS_PANE));
//manipulate staticMeta here
StaticComponent staticComponent = new StaticComponent(staticMeta);
//manipulate staticComponent here
gui.addComponent(staticComponent);
Of course, you can also set a specific place this StaticComponent should be placed at in the Gui by writing: staticComponent.setPlace(4);
That's basically all for the easy implementation of StaticComponent. Now we come to the implementation where we let StaticComponent basically function like a Button
Button-Implementation
Here we can use the exact same code as before, but at the point where we manipulate StaticComponent, we add a ClickListener by calling staticComponent.addClickListener(clickListener);
The clickListener here could either be a specific instance/class like the class we are in right now (staticComponent.addClickListener(this);
) when we implement ComponentClickAction
in this class or we could simply implement all the logic directly by writing:
staticComponent.addClickListener(new ComponentClickAction() {
@Override
public boolean onClick(Component component, Player player, Gui gui, InventoryAction action, ClickType clickType) {
//implement what should happen when StaticComponent is clicked
return true;
}
});
The complete explanation on how this works is in chapter Events.
Events
ComponentClickedEvent
= fired, when the StaticComponent (or any other Component) is clicked
StaticComponentClickedEvent
= fired, when the StaticComponent 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"
)
Resources
Component-Code: io.github.parzivalExe.guiApi.components.StaticComponent
Great, now you know how to implement a StaticComponent with a few lines. Next Component on the List is FreeSpaceComponent