From 7ce74de993eaec1a0b5eb35b1877f7af9360fcd5 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 24 Jun 2023 15:58:08 +0200 Subject: [PATCH] Deprecates CompatibleSound in favor of XSound from the XSeries library --- .../core/compatibility/CompatibleSound.java | 4 ++++ Core/pom.xml | 1 + Core/src/main/java/com/craftaro/core/gui/Gui.java | 13 +++++++------ .../main/java/com/craftaro/core/gui/GuiManager.java | 8 ++++---- .../java/com/craftaro/core/world/SItemStack.java | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleSound.java b/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleSound.java index 1dd58008..f33072fd 100644 --- a/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleSound.java +++ b/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleSound.java @@ -1,5 +1,6 @@ package com.craftaro.core.compatibility; +import com.cryptomorin.xseries.XSound; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.World; @@ -14,7 +15,10 @@ import org.bukkit.entity.Player; * sounds were renamed. New sounds have been added by different versions, as * well. The intent of this class is to provide either the correct sound or a * near equivalent for the current server. + * + * @deprecated Use {@link XSound} instead. */ +@Deprecated public enum CompatibleSound { // some of these values are missing an API value... // would using the raw strings be better? diff --git a/Core/pom.xml b/Core/pom.xml index b2a6c50c..eba9a913 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -120,6 +120,7 @@ com/cryptomorin/xseries/XMaterial* com/cryptomorin/xseries/XBlock* + com/cryptomorin/xseries/XSound* diff --git a/Core/src/main/java/com/craftaro/core/gui/Gui.java b/Core/src/main/java/com/craftaro/core/gui/Gui.java index e41df269..fbb6a017 100644 --- a/Core/src/main/java/com/craftaro/core/gui/Gui.java +++ b/Core/src/main/java/com/craftaro/core/gui/Gui.java @@ -1,5 +1,6 @@ package com.craftaro.core.gui; +import com.craftaro.core.compatibility.ServerVersion; import com.craftaro.core.gui.events.GuiClickEvent; import com.craftaro.core.gui.events.GuiCloseEvent; import com.craftaro.core.gui.events.GuiDropItemEvent; @@ -11,9 +12,8 @@ import com.craftaro.core.gui.methods.Droppable; import com.craftaro.core.gui.methods.Openable; import com.craftaro.core.gui.methods.Pagable; import com.craftaro.core.utils.ItemUtils; -import com.craftaro.core.compatibility.CompatibleSound; -import com.craftaro.core.compatibility.ServerVersion; import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XSound; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -50,7 +50,7 @@ public class Gui { protected ItemStack nextPageItem, prevPageItem; protected ItemStack nextPage, prevPage; protected Gui parent = null; - protected static ItemStack AIR = new ItemStack(Material.AIR); + protected static final ItemStack AIR = new ItemStack(Material.AIR); protected GuiManager guiManager; protected boolean open = false; @@ -60,7 +60,7 @@ public class Gui { protected Closable closer = null; protected Droppable dropper = null; protected Pagable pager = null; - protected CompatibleSound defaultSound = CompatibleSound.UI_BUTTON_CLICK; + protected XSound defaultSound = XSound.UI_BUTTON_CLICK; public Gui() { this.rows = 3; @@ -69,6 +69,7 @@ public class Gui { public Gui(@NotNull GuiType type) { this.inventoryType = type; + switch (type) { case HOPPER: case DISPENSER: @@ -959,11 +960,11 @@ public class Gui { } } - public CompatibleSound getDefaultSound() { + public XSound getDefaultSound() { return defaultSound; } - public void setDefaultSound(CompatibleSound sound) { + public void setDefaultSound(XSound sound) { defaultSound = sound; } } diff --git a/Core/src/main/java/com/craftaro/core/gui/GuiManager.java b/Core/src/main/java/com/craftaro/core/gui/GuiManager.java index 1b45b02c..581cb294 100644 --- a/Core/src/main/java/com/craftaro/core/gui/GuiManager.java +++ b/Core/src/main/java/com/craftaro/core/gui/GuiManager.java @@ -237,13 +237,13 @@ public class GuiManager { event.setCancelled(gui.unlockedCells.entrySet().stream().noneMatch(e -> event.getSlot() == e.getKey() && e.getValue())); // process button press - if (gui.onClick(manager, player, openInv, event)) { - player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F); + if (gui.onClick(this.manager, player, openInv, event)) { + gui.getDefaultSound().play(player); } } else { // Player clicked in the bottom inventory while GUI is open - if (gui.onClickPlayerInventory(manager, player, openInv, event)) { - player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F); + if (gui.onClickPlayerInventory(this.manager, player, openInv, event)) { + gui.getDefaultSound().play(player); } else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { event.setCancelled(true); diff --git a/Core/src/main/java/com/craftaro/core/world/SItemStack.java b/Core/src/main/java/com/craftaro/core/world/SItemStack.java index b2415d46..ad2f5ea2 100644 --- a/Core/src/main/java/com/craftaro/core/world/SItemStack.java +++ b/Core/src/main/java/com/craftaro/core/world/SItemStack.java @@ -1,9 +1,9 @@ package com.craftaro.core.world; import com.craftaro.core.compatibility.CompatibleHand; -import com.craftaro.core.compatibility.CompatibleSound; import com.craftaro.core.compatibility.ServerVersion; import com.craftaro.core.nms.Nms; +import com.cryptomorin.xseries.XSound; import org.bukkit.Bukkit; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -93,7 +93,7 @@ public class SItemStack { Bukkit.getServer().getPluginManager().callEvent(breakEvent); this.sItem.breakItem(player, amount); - CompatibleSound.ENTITY_ITEM_BREAK.play(player); + XSound.ENTITY_ITEM_BREAK.play(player); } public ItemStack getItem() {