refactor(bukkit): 优化代码
This commit is contained in:
@@ -12,6 +12,9 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* GUI 处理类
|
||||
*/
|
||||
@@ -105,7 +108,11 @@ public abstract class PageHandler implements InventoryHolder {
|
||||
|
||||
@NotNull
|
||||
public String getTitle() {
|
||||
return pageConfig.getTitle();
|
||||
String title = pageConfig.getTitle();
|
||||
for (Map.Entry<String, String> entry : getPageVariables().entrySet()) {
|
||||
title = title.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -113,4 +120,9 @@ public abstract class PageHandler implements InventoryHolder {
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HashMap<String, String> getPageVariables() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ public abstract class PageableHandler<E> extends FixedPageHandler {
|
||||
int pageSize = buttonIndexes.size(); // 一页有多少个按钮
|
||||
elementSlot = new HashMap<>();
|
||||
|
||||
HashMap<String, String> variables = getVariables();
|
||||
HashMap<String, String> variables = getPageVariables();
|
||||
|
||||
for (int i = 0; i < pageSize; i++) {
|
||||
// 元素在当前 page 中的索引位置
|
||||
@@ -186,9 +186,4 @@ public abstract class PageableHandler<E> extends FixedPageHandler {
|
||||
public void setElementButtonName(String elementButtonName) {
|
||||
this.elementButtonName = elementButtonName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HashMap<String, String> getVariables() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user