Skip to content

Commit

Permalink
feat(color): 修复ColorParser重复的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Oct 30, 2023
1 parent 9d97837 commit 906fbf0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 230 deletions.
20 changes: 13 additions & 7 deletions base/gui/src/main/java/cc/carm/lib/easyplugin/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static HashMap<UUID, GUI> getOpenedGUIs() {
}

protected GUIType type;
protected String name;
protected String title;
public HashMap<Integer, GUIItem> items;
public Inventory inv;

Expand All @@ -57,14 +57,13 @@ public static HashMap<UUID, GUI> getOpenedGUIs() {

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);
}

Expand All @@ -90,6 +89,7 @@ public GUIItem getItem(int index) {
* 更新玩家箱子的视图
*/
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)));
Expand Down Expand Up @@ -148,7 +148,7 @@ public void openGUI(Player player) {
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()));

Expand Down Expand Up @@ -181,12 +181,18 @@ public void onDrag(InventoryDragEvent event) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,17 @@ public boolean hasNextPage() {
* 前往第一页
*/
public void goFirstPage() {
if (hasPreviousPage())
this.page = 1;
else
throw new IndexOutOfBoundsException();
this.page = 1;
onPageChange(this.page);
}


/**
* 前往最后一页
*/
public void goLastPage() {
if (hasNextPage())
this.page = getLastPageNumber();
else
throw new IndexOutOfBoundsException();
this.page = getLastPageNumber();
onPageChange(this.page);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,31 @@ public List<GUIItem> getItemsContainer() {
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();
}


/**
* 前往下一页
*/
public void goNextPage() {
if (hasNextPage())
if (hasNextPage()) {
page++;
else
throw new IndexOutOfBoundsException();
this.onPageChange(this.page);
} else throw new IndexOutOfBoundsException();
}


Expand Down
208 changes: 0 additions & 208 deletions base/main/src/main/java/cc/carm/lib/easyplugin/utils/ColorParser.java

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<enabled>true</enabled>
</snapshots>
</repository>

<repository>
<id>minebench-repo</id>
<url>https://repo.minebench.de/</url>
Expand Down

0 comments on commit 906fbf0

Please sign in to comment.