mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2024-09-19 19:25:45 +00:00
feat(gui): 为GUI提供更多方法 (#10)
* feat(gui): 为GUI提供更多方法 * feat(gui): 修复翻页按钮消失的bug
This commit is contained in:
parent
1b7f60fe43
commit
17b7c23c54
@ -81,6 +81,19 @@ public class GUI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置GUI上方(箱子部分)
|
||||
* @param row 行数,1为第1行
|
||||
* @param column 列数,1为第1列
|
||||
* @param item GUIItem
|
||||
*/
|
||||
public void setItem(int row, int column, @NotNull GUIItem item){
|
||||
if(row <= 0 || column <= 0) throw new IllegalArgumentException("行数和列数都不能小于等于零");
|
||||
if(row > type.getLines()) throw new IllegalArgumentException("行数("+row+")大于GUI大小限制("+type.getLines()+")");
|
||||
if(column > 9) throw new IllegalArgumentException("列数("+column+")不能大于9");
|
||||
setItem(9*(row-1)+column-1, item);
|
||||
}
|
||||
|
||||
public GUIItem getItem(int index) {
|
||||
return this.items.get(index);
|
||||
}
|
||||
|
@ -77,7 +77,14 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
||||
public void openGUI(Player user) {
|
||||
if (previousPageSlot >= 0) {
|
||||
if (hasPreviousPage()) {
|
||||
setItem(previousPageSlot, new GUIItem(Optional.ofNullable(defaultPreviousPage).map(d -> d.apply(user)).orElse(previousPageUI)) {
|
||||
ItemStack finalPreviousPageUI;
|
||||
if(previousPageUI != null)
|
||||
finalPreviousPageUI = previousPageUI;
|
||||
else if (defaultPreviousPage != null)
|
||||
finalPreviousPageUI = defaultPreviousPage.apply(user);
|
||||
else
|
||||
finalPreviousPageUI = null;
|
||||
setItem(previousPageSlot, new GUIItem(finalPreviousPageUI) {
|
||||
@Override
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
if (type == ClickType.RIGHT) {
|
||||
@ -95,7 +102,14 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
||||
|
||||
if (nextPageSlot >= 0) {
|
||||
if (hasNextPage()) {
|
||||
setItem(nextPageSlot, new GUIItem(Optional.ofNullable(defaultNextPage).map(d -> d.apply(user)).orElse(nextPageUI)) {
|
||||
ItemStack finalNextPageUI;
|
||||
if(previousPageUI != null)
|
||||
finalNextPageUI = nextPageUI;
|
||||
else if (defaultNextPage != null)
|
||||
finalNextPageUI = defaultNextPage.apply(user);
|
||||
else
|
||||
finalNextPageUI = null;
|
||||
setItem(nextPageSlot, new GUIItem(finalNextPageUI) {
|
||||
@Override
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
if (type == ClickType.RIGHT) {
|
||||
|
@ -101,6 +101,8 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
super.openGUI(player);
|
||||
return;
|
||||
}
|
||||
if(page > getLastPageNumber())
|
||||
page = getLastPageNumber();
|
||||
List<GUIItem> list = new ArrayList<>();
|
||||
int start = (page - 1) * range.length;
|
||||
for (int i = start; i < start + range.length; i++) {
|
||||
|
@ -20,7 +20,7 @@ public abstract class PagedGUI extends GUI {
|
||||
}
|
||||
|
||||
public int setCurrentPage(int page) {
|
||||
this.page = Math.max(1, Math.min(page, getLastPageNumber()));
|
||||
this.page = Math.max(1, page);
|
||||
return this.page;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user