public abstract class Component extends Object
Layout
.
A Component is very versatile it its core its task is to define how it is
rendered and when happens when it gets clicked on.
Most methods have access to the Player, Interaction
and Cursor
so they they can implement
very advanced logic.Modifier and Type | Field and Description |
---|---|
protected Action |
clickAction |
protected boolean |
hidden |
protected String |
id |
protected Interaction |
interaction |
Modifier | Constructor and Description |
---|---|
protected |
Component(String id,
Action clickAction,
boolean hidden,
Interaction interaction)
Instantiates a new Component.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
apply(Graphics graphic,
org.bukkit.entity.Player player,
GuiPoint cursor)
Render the component on the provided graphic context.
|
abstract Component |
clone(Interaction interaction)
Clone the component with the new interaction.
|
void |
dispose()
Dispose the component.
|
Action |
getClickAction()
Gets click action.
|
String |
getId()
Gets component id.
|
Interaction |
getInteraction()
Gets the interaction this component is used in.
|
abstract String |
getState(org.bukkit.entity.Player player,
GuiPoint cursor)
Gets the current state of the component for the given parameters.
|
boolean |
isHidden()
Check whether the component is currently hidden
|
abstract boolean |
isInBounds(org.bukkit.entity.Player player,
GuiPoint cursor)
Checks whether the cursor is in bounds of the component.
|
Component |
locate(String componentId)
Locate the component with the given id.
|
<T extends Component> |
locate(String componentId,
Class<T> type)
Locate the component with the given id and type.
|
Component |
locateOn(Interaction interaction)
Locate the same component on a different interaction.
|
void |
onClick(org.bukkit.entity.Player player,
GuiPoint cursor,
boolean isPrimary)
Called when a player clicks on the component.
|
void |
setClickAction(Action clickAction)
Sets the click action.
|
void |
setHidden(boolean hidden)
Sets whether the component is currently hidden.
|
protected final String id
protected Action clickAction
protected final Interaction interaction
protected boolean hidden
protected Component(String id, Action clickAction, boolean hidden, Interaction interaction)
id
- the components id (should be unique)clickAction
- the click actionhidden
- the hiddeninteraction
- the interaction this component is used inpublic abstract void apply(Graphics graphic, org.bukkit.entity.Player player, GuiPoint cursor)
graphic
- the graphicplayer
- the playercursor
- the cursorpublic abstract boolean isInBounds(org.bukkit.entity.Player player, GuiPoint cursor)
player
- the playercursor
- the cursorpublic abstract String getState(org.bukkit.entity.Player player, GuiPoint cursor)
apply(Graphics, Player, GuiPoint)
renders different content, then the this method should
return different strings. If it renders the same the return value should be the same.
RectComponent
returns
x+"*"+y+"*"+width+"*"+height+"*"+color.getRGB()
)player
- the playercursor
- the cursorpublic Component locate(String componentId)
componentId
- the component idpublic <T extends Component> T locate(String componentId, Class<T> type)
locate(String)
method.componentId
- the component idpublic Component locateOn(Interaction interaction)
interaction.getComponentTree().locate(component.getId())
interaction
- the interactionpublic abstract Component clone(Interaction interaction)
interaction
- the interactionpublic void onClick(org.bukkit.entity.Player player, GuiPoint cursor, boolean isPrimary)
player
- the playercursor
- the cursorisPrimary
- whether the click is primary (i.e. whether there was no other component in the way)public void dispose()
public void setClickAction(Action clickAction)
clickAction
- the click actionpublic String getId()
public Action getClickAction()
public Interaction getInteraction()
public boolean isHidden()
public void setHidden(boolean hidden)
hidden
- the hiddenCopyright © 2021. All rights reserved.