refactor(bukkit): 标准化方法名称

This commit is contained in:
2023-01-18 17:56:16 +08:00
parent 309d7c2f15
commit be7e06d9ce
4 changed files with 24 additions and 24 deletions

View File

@@ -21,7 +21,7 @@ public class PageConfig implements InventoryHolder {
@NotNull @NotNull
private final Plugin plugin; private final Plugin plugin;
@NotNull @NotNull
private final ConfigurationSection config; private final ConfigurationSection rawConfig;
@NotNull @NotNull
private final String title; private final String title;
@@ -38,12 +38,12 @@ public class PageConfig implements InventoryHolder {
@NotNull @NotNull
private final Inventory inventory; private final Inventory inventory;
public PageConfig(@NotNull Plugin plugin, @NotNull ConfigurationSection config) { public PageConfig(@NotNull Plugin plugin, @NotNull ConfigurationSection rawConfig) {
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.rawConfig = rawConfig;
title = config.getString("title", "").replace("&", "§"); title = rawConfig.getString("title", "").replace("&", "§");
List<String> graphicString = config.getStringList("graphic"); List<String> graphicString = rawConfig.getStringList("graphic");
if (graphicString.size() > 6) { if (graphicString.size() > 6) {
graphicString = graphicString.subList(0, 6); graphicString = graphicString.subList(0, 6);
} }
@@ -59,7 +59,7 @@ public class PageConfig implements InventoryHolder {
inventory = Bukkit.createInventory(this, graphicString.size() * 9, title); inventory = Bukkit.createInventory(this, graphicString.size() * 9, title);
buttons = new HashMap<>(); buttons = new HashMap<>();
ConfigurationSection buttonsConfig = config.getConfigurationSection("buttons"); ConfigurationSection buttonsConfig = rawConfig.getConfigurationSection("buttons");
if (buttonsConfig != null) { if (buttonsConfig != null) {
for (String key : buttonsConfig.getKeys(false)) { for (String key : buttonsConfig.getKeys(false)) {
buttons.put(key, buttonsConfig.getItemStack(key)); buttons.put(key, buttonsConfig.getItemStack(key));
@@ -67,7 +67,7 @@ public class PageConfig implements InventoryHolder {
} }
buttonGroups = new ArrayList<>(); buttonGroups = new ArrayList<>();
ConfigurationSection buttonGroupsConfig = config.getConfigurationSection("groups"); ConfigurationSection buttonGroupsConfig = rawConfig.getConfigurationSection("groups");
if (buttonGroupsConfig != null) { if (buttonGroupsConfig != null) {
for (String key : buttonGroupsConfig.getKeys(false)) { for (String key : buttonGroupsConfig.getKeys(false)) {
//noinspection ConstantConditions //noinspection ConstantConditions
@@ -87,7 +87,7 @@ public class PageConfig implements InventoryHolder {
} }
buttonSounds = new HashMap<>(); buttonSounds = new HashMap<>();
ConfigurationSection buttonSoundConfig = config.getConfigurationSection("sounds"); ConfigurationSection buttonSoundConfig = rawConfig.getConfigurationSection("sounds");
if (buttonSoundConfig != null) { if (buttonSoundConfig != null) {
for (String key : buttonSoundConfig.getKeys(false)) { for (String key : buttonSoundConfig.getKeys(false)) {
try { try {
@@ -164,8 +164,8 @@ public class PageConfig implements InventoryHolder {
} }
@NotNull @NotNull
public ConfigurationSection getConfig() { public ConfigurationSection getRawConfig() {
return config; return rawConfig;
} }
@NotNull @NotNull

View File

@@ -24,11 +24,11 @@ public class FixedPageHandler extends PageHandler {
@Override @Override
public void initPage() { public void initPage() {
if (inventory == null) { if (inventory == null) {
inventory = Bukkit.createInventory(this, getConfig().getInventory().getSize(), getTitle()); inventory = Bukkit.createInventory(this, getPageConfig().getInventory().getSize(), getTitle());
} }
HumanEntity player = getPlayer(); HumanEntity player = getPlayer();
PageConfig config = getConfig(); PageConfig config = getPageConfig();
ButtonGroup group = getButtonGroup(); ButtonGroup group = getButtonGroup();
List<String> graphic = config.getGraphic(); List<String> graphic = config.getGraphic();

View File

@@ -17,17 +17,17 @@ import org.jetbrains.annotations.NotNull;
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public abstract class PageHandler implements InventoryHolder { public abstract class PageHandler implements InventoryHolder {
private final PageConfig config; private final PageConfig pageConfig;
private final HumanEntity player; private final HumanEntity player;
protected Inventory inventory; protected Inventory inventory;
public PageHandler(@NotNull HumanEntity player) { public PageHandler(@NotNull HumanEntity player) {
config = PageManager.getPageConfig(getClass()); pageConfig = PageManager.getPageConfig(getClass());
this.player = player; this.player = player;
} }
public PageHandler(@NotNull PageConfig config, @NotNull HumanEntity player) { public PageHandler(@NotNull PageConfig pageConfig, @NotNull HumanEntity player) {
this.config = config; this.pageConfig = pageConfig;
this.player = player; this.player = player;
} }
@@ -51,7 +51,7 @@ 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) {
PageConfig config = getConfig(); PageConfig config = getPageConfig();
Sound sound = config.getButtonSound(getButtonGroup().getButtonName(index)); Sound sound = config.getButtonSound(getButtonGroup().getButtonName(index));
sound = sound == null ? config.getButtonSound("default") : sound; sound = sound == null ? config.getButtonSound("default") : sound;
if (sound == null) { if (sound == null) {
@@ -81,16 +81,16 @@ public abstract class PageHandler implements InventoryHolder {
if (init) { if (init) {
initPage(); initPage();
} }
Bukkit.getScheduler().runTask(config.getPlugin(), () -> player.openInventory(getInventory())); Bukkit.getScheduler().runTask(pageConfig.getPlugin(), () -> player.openInventory(getInventory()));
} }
public void close() { public void close() {
Bukkit.getScheduler().runTask(config.getPlugin(), player::closeInventory); Bukkit.getScheduler().runTask(pageConfig.getPlugin(), player::closeInventory);
} }
@NotNull @NotNull
public PageConfig getConfig() { public PageConfig getPageConfig() {
return config; return pageConfig;
} }
@NotNull @NotNull
@@ -100,12 +100,12 @@ public abstract class PageHandler implements InventoryHolder {
@NotNull @NotNull
public ButtonGroup getButtonGroup() { public ButtonGroup getButtonGroup() {
return getConfig().getButtonGroup("default"); return getPageConfig().getButtonGroup("default");
} }
@NotNull @NotNull
public String getTitle() { public String getTitle() {
return config.getTitle(); return pageConfig.getTitle();
} }
@NotNull @NotNull

View File

@@ -68,7 +68,7 @@ public abstract class PageableHandler<E> extends FixedPageHandler {
onClickElement(event.getClick(), event.getAction(), e); onClickElement(event.getClick(), event.getAction(), e);
return; return;
} }
String name = getConfig().getButtonName(event.getCurrentItem()); String name = getPageConfig().getButtonName(event.getCurrentItem());
if (name.equalsIgnoreCase(nextButtonName)) { if (name.equalsIgnoreCase(nextButtonName)) {
showNextPage(); showNextPage();
return; return;