diff --git a/easyplugin-all/pom.xml b/easyplugin-all/pom.xml
index 38421dc..66c30fa 100644
--- a/easyplugin-all/pom.xml
+++ b/easyplugin-all/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-bom/pom.xml b/easyplugin-bom/pom.xml
index 45ace36..7b9e8d6 100644
--- a/easyplugin-bom/pom.xml
+++ b/easyplugin-bom/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-command/pom.xml b/easyplugin-command/pom.xml
index 6f16bc8..8eba27f 100644
--- a/easyplugin-command/pom.xml
+++ b/easyplugin-command/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-common/pom.xml b/easyplugin-common/pom.xml
index 4187f81..efaa6fe 100644
--- a/easyplugin-common/pom.xml
+++ b/easyplugin-common/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-configuration/pom.xml b/easyplugin-configuration/pom.xml
index 66335a2..5cb3b55 100644
--- a/easyplugin-configuration/pom.xml
+++ b/easyplugin-configuration/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-database/pom.xml b/easyplugin-database/pom.xml
index 49550ce..5ea2ea6 100644
--- a/easyplugin-database/pom.xml
+++ b/easyplugin-database/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-gui/pom.xml b/easyplugin-gui/pom.xml
index 5a4c29b..a47368a 100644
--- a/easyplugin-gui/pom.xml
+++ b/easyplugin-gui/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/GUI.java b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/GUI.java
index 0090ddc..861823b 100644
--- a/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/GUI.java
+++ b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/GUI.java
@@ -25,7 +25,6 @@ public class GUI {
public static void initialize(JavaPlugin plugin) {
GUI.plugin = plugin;
-
}
public static JavaPlugin getPlugin() {
@@ -36,8 +35,8 @@ public class GUI {
return openedGUIs;
}
- GUIType type;
- String name;
+ protected GUIType type;
+ protected String name;
public HashMap items;
public Inventory inv;
diff --git a/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/AutoPagedGUI.java b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/AutoPagedGUI.java
new file mode 100644
index 0000000..8503dba
--- /dev/null
+++ b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/AutoPagedGUI.java
@@ -0,0 +1,96 @@
+package cc.carm.lib.easyplugin.gui.paged;
+
+import cc.carm.lib.easyplugin.gui.GUIItem;
+import cc.carm.lib.easyplugin.gui.GUIType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.ClickType;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.function.Function;
+
+public class AutoPagedGUI extends CommonPagedGUI {
+
+ public static Function defaultPreviousPage = null;
+ public static Function defaultNextPage = null;
+
+ ItemStack previousPageUI;
+ ItemStack nextPageUI;
+ int previousPageSlot = -1;
+ int nextPageSlot = -1;
+
+ public AutoPagedGUI(GUIType type, String name, int[] range) {
+ super(type, name, range);
+ }
+
+ public AutoPagedGUI(GUIType type, String name, int a, int b) {
+ super(type, name, a, b);
+ }
+
+ public void setPreviousPageUI(ItemStack lastPageUI) {
+ this.previousPageUI = lastPageUI;
+ }
+
+ public void setNextPageUI(ItemStack nextPageUI) {
+ this.nextPageUI = nextPageUI;
+ }
+
+ public void setPreviousPageSlot(int slot) {
+ this.previousPageSlot = slot;
+ }
+
+ public void setNextPageSlot(int slot) {
+ this.nextPageSlot = slot;
+ }
+
+ @Override
+ public void openGUI(Player user) {
+ if (previousPageSlot >= 0) {
+ if (hasPreviousPage()) {
+ setItem(previousPageSlot, new GUIItem(
+ previousPageUI == null ? getDefaultPreviousPage(user) : previousPageUI) {
+ @Override
+ public void onClick(ClickType type) {
+ if (type == ClickType.RIGHT) {
+ goFirstPage();
+ } else {
+ goPreviousPage();
+ }
+ openGUI(user);
+ }
+ });
+ } else {
+ setItem(previousPageSlot, null);
+ }
+ }
+
+ if (nextPageSlot >= 0) {
+ if (hasNextPage()) {
+ setItem(nextPageSlot, new GUIItem(
+ nextPageUI == null ? getDefaultNextPage(user) : nextPageUI) {
+ @Override
+ public void onClick(ClickType type) {
+ if (type == ClickType.RIGHT) {
+ goLastPage();
+ } else {
+ goNextPage();
+ }
+ openGUI(user);
+ }
+ });
+ } else {
+ setItem(nextPageSlot, null);
+ }
+ }
+
+
+ super.openGUI(user);
+ }
+
+ private static ItemStack getDefaultNextPage(Player player) {
+ return defaultNextPage != null ? defaultNextPage.apply(player) : null;
+ }
+
+ private static ItemStack getDefaultPreviousPage(Player player) {
+ return defaultPreviousPage != null ? defaultPreviousPage.apply(player) : null;
+ }
+}
diff --git a/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/CommonPagedGUI.java b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/CommonPagedGUI.java
new file mode 100644
index 0000000..5488207
--- /dev/null
+++ b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/CommonPagedGUI.java
@@ -0,0 +1,162 @@
+package cc.carm.lib.easyplugin.gui.paged;
+
+
+import cc.carm.lib.easyplugin.gui.GUIItem;
+import cc.carm.lib.easyplugin.gui.GUIType;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class CommonPagedGUI extends PagedGUI {
+
+ private int[] range;
+
+ private CommonPagedGUI(GUIType type, String name) {
+ super(type, name);
+ }
+
+ public CommonPagedGUI(GUIType type, String Name, int a, int b) {
+ this(type, Name, toRange(type, a, b));
+ }
+
+ public CommonPagedGUI(GUIType type, String Name, int[] range) {
+ super(type, Name);
+ Arrays.sort(range);
+ this.range = range;
+
+ }
+
+
+
+ /*
+ int[] matrix = new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53
+ }
+ */
+
+ private static int[] toRange(GUIType type, int a, int b) {
+ if (a > b) {
+ a = a ^ b;
+ b = a ^ b;
+ a = a ^ b;
+ }
+
+ int lineA = getLine(a);
+ int columnA = getColumn(a);
+ int lineB = getLine(b);
+ int columnB = getColumn(b);
+
+ if (lineB > type.getLines())
+ throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
+
+ int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
+
+ for (int i = 0, l = 0; i < type.getSize(); i++) {
+ int li = getLine(i);
+ int ci = getColumn(i);
+ if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
+ range[l] = i;
+ l++;
+ }
+ }
+
+ return range;
+ }
+
+ private static int getLine(int i) {
+ return i / 9 + 1;
+ }
+
+ private static int getColumn(int i) {
+ return i % 9 + 1;
+ }
+
+ @Override
+ public boolean hasPreviousPage() {
+ return page > 1;
+ }
+
+ @Override
+ public boolean hasNextPage() {
+ return page < getLastPageNumber();
+ }
+
+
+ /**
+ * 前往第一页
+ */
+ public void goFirstPage() {
+ if (hasPreviousPage())
+ this.page = 1;
+ else
+ throw new IndexOutOfBoundsException();
+ }
+
+
+ /**
+ * 前往最后一页
+ */
+ public void goLastPage() {
+ if (hasNextPage())
+ this.page = getLastPageNumber();
+ else
+ throw new IndexOutOfBoundsException();
+ }
+
+
+ /**
+ * 得到最后一页的页码
+ *
+ * @return 最后一页的页码
+ */
+ public int getLastPageNumber() {
+ return (this.container.size() / range.length) + 1;
+ }
+
+ /**
+ * 得到第一页的页码
+ *
+ * @return 第一页页码(默认为1)
+ */
+ public int getFirstPageNumber() {
+ return 1;
+ }
+
+
+ @Override
+ public void openGUI(Player player) {
+ if (container.isEmpty()) {
+ super.openGUI(player);
+ return;
+ }
+ List list = new ArrayList<>();
+ int start = (page - 1) * range.length;
+ for (int i = start; i < start + range.length; i++) {
+ if (i < container.size()) {
+ list.add(container.get(i));
+ } else {
+ break;
+ }
+ }
+
+ int i = 0;
+ Arrays.stream(range).forEach(index -> setItem(index, null));
+ for (int index : range) {
+ if (i < list.size()) {
+ setItem(index, list.get(i));
+ i++;
+ } else {
+ break;
+ }
+ }
+ super.openGUI(player);
+ }
+
+}
diff --git a/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/PagedGUI.java b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/PagedGUI.java
new file mode 100644
index 0000000..802c647
--- /dev/null
+++ b/easyplugin-gui/src/main/java/cc/carm/lib/easyplugin/gui/paged/PagedGUI.java
@@ -0,0 +1,79 @@
+package cc.carm.lib.easyplugin.gui.paged;
+
+
+import cc.carm.lib.easyplugin.gui.GUI;
+import cc.carm.lib.easyplugin.gui.GUIItem;
+import cc.carm.lib.easyplugin.gui.GUIType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class PagedGUI extends GUI {
+
+ List container = new ArrayList<>();
+ public int page = 1;
+
+ public PagedGUI(GUIType type, String name) {
+ super(type, name);
+ }
+
+ public int addItem(GUIItem i) {
+ container.add(i);
+ return container.size() - 1;
+ }
+
+ /**
+ * 从GUI中移除一个物品
+ *
+ * @param item 物品
+ */
+ public void removeItem(GUIItem item) {
+ container.remove(item);
+ }
+
+ /**
+ * 从GUI中移除一个物品
+ *
+ * @param slot 物品格子数
+ */
+ public void removeItem(int slot) {
+ container.remove(slot);
+ }
+
+ public List getItemsContainer() {
+ return new ArrayList<>(container);
+ }
+
+ /**
+ * 前往上一页
+ */
+ public void goPreviousPage() {
+ if (hasPreviousPage())
+ page--;
+ else
+ throw new IndexOutOfBoundsException();
+ }
+
+
+ /**
+ * 前往下一页
+ */
+ public void goNextPage() {
+ if (hasNextPage())
+ page++;
+ else
+ throw new IndexOutOfBoundsException();
+ }
+
+
+ /**
+ * @return 是否有上一页
+ */
+ public abstract boolean hasPreviousPage();
+
+ /**
+ * @return 是否有下一页
+ */
+ public abstract boolean hasNextPage();
+
+}
diff --git a/easyplugin-lp/pom.xml b/easyplugin-lp/pom.xml
index a4de066..7f26463 100644
--- a/easyplugin-lp/pom.xml
+++ b/easyplugin-lp/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-main/pom.xml b/easyplugin-main/pom.xml
index 19c53ad..c2de871 100644
--- a/easyplugin-main/pom.xml
+++ b/easyplugin-main/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-placeholderapi/pom.xml b/easyplugin-placeholderapi/pom.xml
index a6abeab..605a6ce 100644
--- a/easyplugin-placeholderapi/pom.xml
+++ b/easyplugin-placeholderapi/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/easyplugin-vault/pom.xml b/easyplugin-vault/pom.xml
index c2b6043..e1acc61 100644
--- a/easyplugin-vault/pom.xml
+++ b/easyplugin-vault/pom.xml
@@ -5,7 +5,7 @@
easyplugin-parent
cc.carm.lib
- 1.3.0
+ 1.3.1
4.0.0
diff --git a/pom.xml b/pom.xml
index d52e11a..272f55d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
cc.carm.lib
easyplugin-parent
pom
- 1.3.0
+ 1.3.1
easyplugin-bom