fix(bukkit): 点击页面空位置时仍然有按钮音效
This commit is contained in:
@@ -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.ButtonGroup;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.page.PageConfig;
|
import cn.hamster3.mc.plugin.core.bukkit.page.PageConfig;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
@@ -78,6 +80,36 @@ public abstract class PageableHandler<E> 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
|
@Override
|
||||||
public void initPage() {
|
public void initPage() {
|
||||||
super.initPage();
|
super.initPage();
|
||||||
|
Reference in New Issue
Block a user