From a43b84b45e8e6376c41d50140d356a8ef45da169 Mon Sep 17 00:00:00 2001 From: alexteens24 Date: Wed, 24 Jun 2026 09:04:42 +0700 Subject: [PATCH] fix(gui): play open_sound when skip_main_gui opens storage directly When skip_main_gui is enabled, the configured open_sound from main_gui.yml was never played because storage opened outside SpawnerMenuUI. Co-authored-by: Cursor --- .../list/gui/management/SpawnerManagementHandler.java | 2 +- .../gui/layout/GuiButtonInteractionService.java | 10 ++++++++++ .../smartspawner/spawner/gui/main/SpawnerMenuUI.java | 9 +-------- .../interactions/click/SpawnerClickManager.java | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/github/nighter/smartspawner/commands/list/gui/management/SpawnerManagementHandler.java b/core/src/main/java/github/nighter/smartspawner/commands/list/gui/management/SpawnerManagementHandler.java index 6cbc315d..d0a3aed5 100644 --- a/core/src/main/java/github/nighter/smartspawner/commands/list/gui/management/SpawnerManagementHandler.java +++ b/core/src/main/java/github/nighter/smartspawner/commands/list/gui/management/SpawnerManagementHandler.java @@ -90,8 +90,8 @@ private void handleOpenSpawnerGUI(Player player, SpawnerData spawner) { // Open storage GUI directly Inventory storageInventory = plugin.getSpawnerStorageUI() .createStorageInventory(player, spawner, 1, -1); - player.playSound(player.getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f); player.openInventory(storageInventory); + plugin.getGuiButtonInteractionService().playOpenSound(player); return; } diff --git a/core/src/main/java/github/nighter/smartspawner/spawner/gui/layout/GuiButtonInteractionService.java b/core/src/main/java/github/nighter/smartspawner/spawner/gui/layout/GuiButtonInteractionService.java index 9425d5cd..5a1b9c47 100644 --- a/core/src/main/java/github/nighter/smartspawner/spawner/gui/layout/GuiButtonInteractionService.java +++ b/core/src/main/java/github/nighter/smartspawner/spawner/gui/layout/GuiButtonInteractionService.java @@ -114,6 +114,16 @@ public void clear() { invalidSoundWarnings.clear(); } + /** + * Plays the configured open_sound from main_gui.yml, if set. + */ + public void playOpenSound(Player player) { + String openSound = plugin.getGuiLayoutConfig().getOpenSound(); + if (openSound != null) { + playSound(player, new GuiButtonSoundData(openSound, 1.0f, 1.0f)); + } + } + private String formatRemainingTime(long remainingNanos) { long tenths = Math.max(1L, (remainingNanos + 99_999_999L) / 100_000_000L); if (tenths % 10L == 0L) { diff --git a/core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuUI.java b/core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuUI.java index 70cc4450..e824342c 100644 --- a/core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuUI.java +++ b/core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuUI.java @@ -174,14 +174,7 @@ public void openSpawnerMenu(Player player, SpawnerData spawner, boolean refresh) player.openInventory(menu); if (!refresh) { - String openSound = plugin.getGuiLayoutConfig().getOpenSound(); - if (openSound != null) { - try { - player.playSound(player.getLocation(), openSound, 1.0f, 1.0f); - } catch (Exception e) { - plugin.getLogger().warning("Invalid open_sound in main_gui.yml: " + openSound); - } - } + plugin.getGuiButtonInteractionService().playOpenSound(player); } // Force timer update inactive for GUI if applicable diff --git a/core/src/main/java/github/nighter/smartspawner/spawner/interactions/click/SpawnerClickManager.java b/core/src/main/java/github/nighter/smartspawner/spawner/interactions/click/SpawnerClickManager.java index 396354c0..9a0ded75 100644 --- a/core/src/main/java/github/nighter/smartspawner/spawner/interactions/click/SpawnerClickManager.java +++ b/core/src/main/java/github/nighter/smartspawner/spawner/interactions/click/SpawnerClickManager.java @@ -213,6 +213,7 @@ private void openStorageGui(Player player, SpawnerData spawner) { Inventory storageInventory = plugin.getSpawnerStorageUI() .createStorageInventory(player, spawner, 1, -1); player.openInventory(storageInventory); + plugin.getGuiButtonInteractionService().playOpenSound(player); } private boolean isSpawnEgg(Material material) {