perf: 优化 Page 相关 API
优化 Page 相关 API
This commit is contained in:
@@ -34,7 +34,7 @@ public class FixedPageHandler extends PageHandler {
|
|||||||
HumanEntity player = getPlayer();
|
HumanEntity player = getPlayer();
|
||||||
|
|
||||||
Inventory inventory = getInventory();
|
Inventory inventory = getInventory();
|
||||||
PageConfig config = getPageConfig();
|
PageConfig config = getConfig();
|
||||||
ButtonGroup group = getButtonGroup();
|
ButtonGroup group = getButtonGroup();
|
||||||
|
|
||||||
List<String> graphic = config.getGraphic();
|
List<String> graphic = config.getGraphic();
|
||||||
|
@@ -18,38 +18,24 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public abstract class PageHandler implements InventoryHolder {
|
public abstract class PageHandler implements InventoryHolder {
|
||||||
private final PageConfig pageConfig;
|
private final PageConfig config;
|
||||||
private final HumanEntity player;
|
private final HumanEntity player;
|
||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
|
|
||||||
public PageHandler(@NotNull HumanEntity player) {
|
public PageHandler(@NotNull HumanEntity player) {
|
||||||
try {
|
try {
|
||||||
pageConfig = PageManager.getPageConfig(getClass());
|
config = PageManager.getPageConfig(getClass());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("加载界面配置时遇到了一个异常!", e);
|
throw new IllegalArgumentException("加载界面配置时遇到了一个异常!", e);
|
||||||
}
|
}
|
||||||
this.player = player;
|
this.player = player;
|
||||||
inventory = Bukkit.createInventory(this, pageConfig.getInventory().getSize(), pageConfig.getTitle());
|
inventory = Bukkit.createInventory(this, config.getInventory().getSize(), getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageHandler(@NotNull HumanEntity player, @NotNull String title) {
|
public PageHandler(@NotNull PageConfig config, @NotNull HumanEntity player) {
|
||||||
try {
|
this.config = config;
|
||||||
pageConfig = PageManager.getPageConfig(getClass());
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("加载界面配置时遇到了一个异常!", e);
|
|
||||||
}
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
inventory = Bukkit.createInventory(this, pageConfig.getInventory().getSize(), title);
|
inventory = Bukkit.createInventory(this, config.getInventory().getSize(), getTitle());
|
||||||
}
|
|
||||||
|
|
||||||
public PageHandler(@NotNull PageConfig pageConfig, @NotNull HumanEntity player) {
|
|
||||||
this(pageConfig, pageConfig.getTitle(), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PageHandler(@NotNull PageConfig pageConfig, @NotNull String title, @NotNull HumanEntity player) {
|
|
||||||
this.pageConfig = pageConfig;
|
|
||||||
this.player = player;
|
|
||||||
inventory = Bukkit.createInventory(this, pageConfig.getInventory().getSize(), title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void initPage();
|
public abstract void initPage();
|
||||||
@@ -72,7 +58,9 @@ public abstract class PageHandler implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onPlayButtonSound(@NotNull ClickType clickType, @NotNull InventoryAction action, int index) {
|
public void onPlayButtonSound(@NotNull ClickType clickType, @NotNull InventoryAction action, int index) {
|
||||||
Sound sound = getPageConfig().getButtonSound(getButtonGroup().getButtonName(index));
|
PageConfig config = getConfig();
|
||||||
|
Sound sound = config.getButtonSound(getButtonGroup().getButtonName(index));
|
||||||
|
sound = sound == null ? config.getButtonSound("default") : sound;
|
||||||
if (sound == null) {
|
if (sound == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -108,8 +96,8 @@ public abstract class PageHandler implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PageConfig getPageConfig() {
|
public PageConfig getConfig() {
|
||||||
return pageConfig;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -119,7 +107,12 @@ public abstract class PageHandler implements InventoryHolder {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ButtonGroup getButtonGroup() {
|
public ButtonGroup getButtonGroup() {
|
||||||
return getPageConfig().getButtonGroup("default");
|
return getConfig().getButtonGroup("default");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getTitle() {
|
||||||
|
return config.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@@ -130,7 +130,7 @@ public abstract class PageableHandler<E extends PageElement> extends FixedPageHa
|
|||||||
onClickElement(event.getClick(), event.getAction(), e);
|
onClickElement(event.getClick(), event.getAction(), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String name = getPageConfig().getButtonName(event.getCurrentItem());
|
String name = getConfig().getButtonName(event.getCurrentItem());
|
||||||
if (name.equalsIgnoreCase(nextButtonName)) {
|
if (name.equalsIgnoreCase(nextButtonName)) {
|
||||||
showNextPage();
|
showNextPage();
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user