From ffbe234852367d06977e1c8e7bed8798eacc3d53 Mon Sep 17 00:00:00 2001 From: MiniDay <372403923@qq.com> Date: Mon, 23 Jan 2023 03:19:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(bukkit):=20=E7=82=B9=E5=87=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=A9=BA=E4=BD=8D=E7=BD=AE=E6=97=B6=E4=BB=8D=E7=84=B6?= =?UTF-8?q?=E6=9C=89=E6=8C=89=E9=92=AE=E9=9F=B3=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/page/handler/PageableHandler.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/page/handler/PageableHandler.java b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/page/handler/PageableHandler.java index 8422d8d..3b943a1 100644 --- a/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/page/handler/PageableHandler.java +++ b/hamster-core-bukkit/src/main/java/cn/hamster3/mc/plugin/core/bukkit/page/handler/PageableHandler.java @@ -3,7 +3,9 @@ package cn.hamster3.mc.plugin.core.bukkit.page.handler; import cn.hamster3.mc.plugin.core.bukkit.page.ButtonGroup; import cn.hamster3.mc.plugin.core.bukkit.page.PageConfig; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; @@ -78,6 +80,36 @@ public abstract class PageableHandler extends FixedPageHandler { } } + @Override + public void onPlayButtonSound(@NotNull ClickType clickType, @NotNull InventoryAction action, int index) { + HumanEntity player = getPlayer(); + if (!(player instanceof Player)) { + return; + } + 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"); + break; + } + } + } + if (buttonName.equals("element") && elementSlot.get(index) == null) { + sound = null; + } + if (sound == null) { + return; + } + ((Player) player).playSound(player.getLocation(), sound, 1, 1); + } + @Override public void initPage() { super.initPage();