perf(bukkit): 优化 gui 按钮声音播放代码

This commit is contained in:
2023-01-22 01:57:24 +08:00
parent 6eafc62f50
commit 7797a95d89
2 changed files with 17 additions and 8 deletions

View File

@@ -54,13 +54,22 @@ public abstract class PageHandler implements InventoryHolder {
}
public void onPlayButtonSound(@NotNull ClickType clickType, @NotNull InventoryAction action, int index) {
PageConfig config = getPageConfig();
Sound sound = config.getButtonSound(getButtonGroup().getButtonName(index));
sound = sound == null ? config.getButtonSound("default") : sound;
if (sound == null) {
if (!(player instanceof Player)) {
return;
}
if (!(player instanceof Player)) {
PageConfig config = getPageConfig();
String buttonName = getButtonGroup().getButtonName(index);
Sound sound = config.getButtonSound(buttonName);
if (sound == null) {
switch (buttonName) {
case "empty":
case "barrier":
break;
default:
sound = config.getButtonSound("default");
}
}
if (sound == null) {
return;
}
((Player) player).playSound(player.getLocation(), sound, 1, 1);