T
- the type of the items it containspublic class ListComponent<T> extends Component
clickAction, hidden, id, interaction
Constructor and Description |
---|
ListComponent(String id,
Action clickAction,
boolean hidden,
Interaction interaction,
Function<Interaction,List<T>> itemListGenerator,
ListItemBuilder<T> itemComponentBuilder,
int pageSize,
int stepSize)
Instantiates a new ListComponent.
|
ListComponent(String id,
Action clickAction,
boolean hidden,
Interaction interaction,
List<T> globalItemList,
ListItemBuilder<T> itemComponentBuilder,
int pageSize,
int stepSize)
Instantiates a new ListComponent.
|
Modifier and Type | Method and Description |
---|---|
void |
apply(Graphics graphic,
org.bukkit.entity.Player player,
GuiPoint cursor)
Render the component on the provided graphic context.
|
ListComponent<T> |
clone(Interaction interaction)
Clone the component with the new interaction.
|
int |
getMaxPage()
Gets the largest page number for an interaction.
|
int |
getPage()
Get which page is shown for the interaction.
|
String |
getState(org.bukkit.entity.Player player,
GuiPoint cursor)
Gets the current state of the component for the given parameters.
|
boolean |
isInBounds(org.bukkit.entity.Player player,
GuiPoint cursor)
Checks whether the cursor is in bounds of the component.
|
ListComponent<T> |
locateOn(Interaction interaction)
Locate the same component on a different interaction.
|
void |
nextPage()
Next page.
|
void |
onClick(org.bukkit.entity.Player player,
GuiPoint cursor,
boolean isPrimary)
Called when a player clicks on the component.
|
void |
previousPage()
Previous page.
|
void |
refreshItems()
Reload items from the itemListGenerator or from the globalList and render the new components.
|
void |
setPage(int page)
Set the page of an interaction.
|
dispose, getClickAction, getId, getInteraction, isHidden, locate, locate, setClickAction, setHidden
public ListComponent(String id, Action clickAction, boolean hidden, Interaction interaction, Function<Interaction,List<T>> itemListGenerator, ListItemBuilder<T> itemComponentBuilder, int pageSize, int stepSize)
id
- the idclickAction
- the click actionhidden
- the hiddeninteraction
- the interactionitemListGenerator
- the item list generator: It should return a list of items for the given interaction.
if all interactions should have the same list then use the other constructor.itemComponentBuilder
- the item component builder: Given an interaction, item and the index it should
return an component for this list item. The index is relative to the pagination.
So it is between 0 and pageSize - 1.pageSize
- the page size (i.e. how many components to show at once)stepSize
- the step size (i.e. how many items to skip when going to the next page
| usual values are 1 or pageSize)public ListComponent(String id, Action clickAction, boolean hidden, Interaction interaction, List<T> globalItemList, ListItemBuilder<T> itemComponentBuilder, int pageSize, int stepSize)
id
- the idclickAction
- the click actionhidden
- the hiddeninteraction
- the interactionglobalItemList
- the global item listitemComponentBuilder
- the item component builder: Given an item and the index it should return an
component for this list item. The index is relative to the pagination.pageSize
- the page size (i.e. how many components to show at once)stepSize
- the step size (i.e. how many items to skip when going to the next page
| usual values are 1 or pageSize)public void refreshItems()
public void nextPage()
public void previousPage()
public int getPage()
public int getMaxPage()
public void setPage(int page)
page
- the pagepublic void apply(Graphics graphic, org.bukkit.entity.Player player, GuiPoint cursor)
Component
public boolean isInBounds(org.bukkit.entity.Player player, GuiPoint cursor)
Component
isInBounds
in class Component
player
- the playercursor
- the cursorpublic String getState(org.bukkit.entity.Player player, GuiPoint cursor)
Component
Component.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()
)public ListComponent<T> clone(Interaction interaction)
Component
public ListComponent<T> locateOn(Interaction interaction)
Component
interaction.getComponentTree().locate(component.getId())
Copyright © 2021. All rights reserved.