mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 00:58:17 +08:00
feat(color): 修复ColorParser重复的问题
This commit is contained in:
@@ -34,7 +34,7 @@ public class GUI {
|
||||
}
|
||||
|
||||
protected GUIType type;
|
||||
protected String name;
|
||||
protected String title;
|
||||
public HashMap<Integer, GUIItem> items;
|
||||
public Inventory inv;
|
||||
|
||||
@@ -57,14 +57,13 @@ public class GUI {
|
||||
|
||||
protected GUIListener listener;
|
||||
|
||||
public GUI(GUIType type, String name) {
|
||||
public GUI(GUIType type, String title) {
|
||||
this.type = type;
|
||||
this.name = ColorParser.parse(name);
|
||||
this.title = ColorParser.parse(title);
|
||||
this.items = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
public HashMap<@NotNull Integer, @NotNull GUIItem> getItems() {
|
||||
public Map<@NotNull Integer, @NotNull GUIItem> getItems() {
|
||||
return new HashMap<>(items);
|
||||
}
|
||||
|
||||
@@ -90,6 +89,7 @@ public class GUI {
|
||||
* 更新玩家箱子的视图
|
||||
*/
|
||||
public void updateView() {
|
||||
this.onUpdate();
|
||||
if (this.inv != null) {
|
||||
List<HumanEntity> viewers = this.inv.getViewers();
|
||||
IntStream.range(0, this.inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||
@@ -148,7 +148,7 @@ public class GUI {
|
||||
throw new IllegalStateException("被取消或不存在的GUI");
|
||||
}
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.title);
|
||||
IntStream.range(0, inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
||||
|
||||
@@ -181,12 +181,18 @@ public class GUI {
|
||||
public void onClose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 当GUI更新时执行的代码
|
||||
*/
|
||||
public void onUpdate() {
|
||||
}
|
||||
|
||||
public GUIType getGUIType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getGUIName() {
|
||||
return name;
|
||||
return title;
|
||||
}
|
||||
|
||||
public static void setOpenedGUI(Player player, GUI gui) {
|
||||
|
||||
@@ -93,10 +93,8 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
* 前往第一页
|
||||
*/
|
||||
public void goFirstPage() {
|
||||
if (hasPreviousPage())
|
||||
this.page = 1;
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
this.page = 1;
|
||||
onPageChange(this.page);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,10 +102,8 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
* 前往最后一页
|
||||
*/
|
||||
public void goLastPage() {
|
||||
if (hasNextPage())
|
||||
this.page = getLastPageNumber();
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
this.page = getLastPageNumber();
|
||||
onPageChange(this.page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,14 +44,20 @@ public abstract class PagedGUI extends GUI {
|
||||
return new ArrayList<>(container);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当GUI改变页码时执行的代码
|
||||
*/
|
||||
public void onPageChange(int pageNum) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 前往上一页
|
||||
*/
|
||||
public void goPreviousPage() {
|
||||
if (hasPreviousPage())
|
||||
if (hasPreviousPage()) {
|
||||
page--;
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
this.onPageChange(this.page);
|
||||
} else throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +65,10 @@ public abstract class PagedGUI extends GUI {
|
||||
* 前往下一页
|
||||
*/
|
||||
public void goNextPage() {
|
||||
if (hasNextPage())
|
||||
if (hasNextPage()) {
|
||||
page++;
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
this.onPageChange(this.page);
|
||||
} else throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user