From 56257c442dfb16287ab5f82869653637ae2f97a6 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sun, 20 Dec 2020 00:55:31 +0100 Subject: [PATCH] Added a sounds.yml file where you can configure a few of the sounds played in MMOCore. Contains configurations for class select, attribute points, waypoint sounds and more. --- pom.xml | 2 +- .../java/net/Indyuce/mmocore/MMOCore.java | 3 + .../net/Indyuce/mmocore/api/SoundObject.java | 53 ++++++++++++++ .../api/experience/PlayerProfessions.java | 4 +- .../Indyuce/mmocore/api/loot/LootChest.java | 3 +- .../mmocore/api/player/PlayerData.java | 10 +-- .../api/player/social/FriendRequest.java | 3 +- .../Indyuce/mmocore/gui/AttributeView.java | 13 ++-- .../mmocore/gui/ClassConfirmation.java | 3 +- .../net/Indyuce/mmocore/gui/ClassSelect.java | 5 +- .../net/Indyuce/mmocore/gui/QuestViewer.java | 5 +- .../mmocore/gui/SubclassConfirmation.java | 3 +- .../Indyuce/mmocore/gui/SubclassSelect.java | 3 +- .../Indyuce/mmocore/listener/SpellCast.java | 7 +- .../mmocore/listener/WaypointsListener.java | 4 +- .../mmocore/manager/ConfigManager.java | 1 + .../Indyuce/mmocore/manager/SoundManager.java | 72 +++++++++++++++++++ src/main/resources/default/sounds.yml | 28 ++++++++ 18 files changed, 193 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/api/SoundObject.java create mode 100644 src/main/java/net/Indyuce/mmocore/manager/SoundManager.java create mode 100644 src/main/resources/default/sounds.yml diff --git a/pom.xml b/pom.xml index cd91247f..b8eeab49 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.Indyuce MMOCore - 1.6 + 1.6.1 MMOCore Offer your players a brand new RPG experience. diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index c0e04929..c4e34745 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -70,6 +70,7 @@ import net.Indyuce.mmocore.manager.MMOLoadManager; import net.Indyuce.mmocore.manager.QuestManager; import net.Indyuce.mmocore.manager.RestrictionManager; import net.Indyuce.mmocore.manager.SkillManager; +import net.Indyuce.mmocore.manager.SoundManager; import net.Indyuce.mmocore.manager.WaypointManager; import net.Indyuce.mmocore.manager.data.DataProvider; import net.Indyuce.mmocore.manager.data.mysql.MySQLDataProvider; @@ -102,6 +103,7 @@ public class MMOCore extends JavaPlugin { public ConfigManager configManager; public WaypointManager waypointManager; public RestrictionManager restrictionManager; + public SoundManager soundManager; public RequestManager requestManager; public ConfigItemManager configItems; public VaultEconomy economy; @@ -419,6 +421,7 @@ public class MMOCore extends JavaPlugin { waypointManager = new WaypointManager(new ConfigFile("waypoints").getConfig()); restrictionManager = new RestrictionManager(new ConfigFile("restrictions").getConfig()); requestManager = new RequestManager(); + soundManager = new SoundManager(new ConfigFile("sounds").getConfig()); configItems = new ConfigItemManager(new ConfigFile("items").getConfig()); if (getConfig().isConfigurationSection("action-bar")) diff --git a/src/main/java/net/Indyuce/mmocore/api/SoundObject.java b/src/main/java/net/Indyuce/mmocore/api/SoundObject.java new file mode 100644 index 00000000..324f5d5e --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/SoundObject.java @@ -0,0 +1,53 @@ +package net.Indyuce.mmocore.api; + +import org.bukkit.Sound; + +public class SoundObject { + private final Sound sound; + private final String key; + private final float volume; + private final float pitch; + + public SoundObject(String input) { + String[] split = input.split(","); + if(split.length > 2) { + input = split[0]; + volume = Float.parseFloat(split[1]); + pitch = Float.parseFloat(split[1]); + } else { + volume = 1; + pitch = 1; + } + + Sound sound = null; + String key = ""; + try { + sound = Sound.valueOf(input.toUpperCase().replace("-", "_")); + } catch(Exception ignored) { + key = input; + } + + this.sound = sound; + this.key = key; + } + + public boolean hasSound() { + return key.isEmpty(); + } + + public Sound getSound() { + return sound; + } + + public String getKey() { + return key; + } + + public float getVolume() { + return volume; + } + + public float getPitch() { + return pitch; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java index cba32727..6d889e8f 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java @@ -4,12 +4,12 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import net.Indyuce.mmocore.manager.SoundManager; import net.mmogroup.mmolib.MMOLib; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Particle; -import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import com.google.gson.Gson; @@ -175,7 +175,7 @@ public class PlayerProfessions { new SmallParticleEffect(playerData.getPlayer(), Particle.SPELL_INSTANT); new ConfigMessage("profession-level-up").addPlaceholders("level", "" + level, "profession", profession.getName()) .send(playerData.getPlayer()); - playerData.getPlayer().playSound(playerData.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); + MMOCore.plugin.soundManager.play(playerData.getPlayer(), SoundManager.SoundEvent.LEVEL_UP); playerData.getStats().updateStats(); } diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java b/src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java index 77458d99..cfed3383 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java +++ b/src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.loot; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; @@ -60,7 +61,7 @@ public class LootChest { * if a player is responsible of closing the chest, close it with sound */ if (player) { - block.loc.getWorld().playSound(block.loc, Sound.ITEM_ARMOR_EQUIP_LEATHER, 1, 1); + MMOCore.plugin.soundManager.play(block.loc.getBlock(), SoundManager.SoundEvent.CLOSE_LOOT_CHEST); block.loc.getWorld().spawnParticle(Particle.CRIT, block.loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5); MMOCore.plugin.lootChests.unregister(this); } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 4c9702e2..4fb107b5 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -10,12 +10,12 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Level; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.Particle; -import org.bukkit.Sound; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -416,7 +416,7 @@ public class PlayerData extends OfflinePlayerData { if(!isOnline()) return; if (getPlayer().getLocation().getBlockX() != x || getPlayer().getLocation().getBlockY() != y || getPlayer().getLocation().getBlockZ() != z) { - getPlayer().playSound(getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, .5f); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.WARP_CANCELLED); MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(getPlayer()); giveStellium(waypoint.getStelliumCost()); cancel(); @@ -427,12 +427,12 @@ public class PlayerData extends OfflinePlayerData { if (t++ >= 100) { getPlayer().teleport(waypoint.getLocation()); getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false)); - getPlayer().playSound(getPlayer().getLocation(), VersionSound.ENTITY_ENDERMAN_TELEPORT.toSound(), 1, .5f); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.WARP_TELEPORT); cancel(); return; } - getPlayer().playSound(getPlayer().getLocation(), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound(), 1, (float) (t / Math.PI * .015 + .5)); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.WARP_CHARGE, 1, (float) (t / Math.PI * .015 + .5)); double r = Math.sin((double) t / 100 * Math.PI); for (double j = 0; j < Math.PI * 2; j += Math.PI / 4) getPlayer().getLocation().getWorld().spawnParticle(Particle.REDSTONE, @@ -488,7 +488,7 @@ public class PlayerData extends OfflinePlayerData { Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(this, null, oldLevel, level)); if(isOnline()) { new ConfigMessage("level-up").addPlaceholders("level", "" + level).send(getPlayer()); - getPlayer().playSound(getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.LEVEL_UP); new SmallParticleEffect(getPlayer(), Particle.SPELL_INSTANT); } getStats().updateStats(); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/social/FriendRequest.java b/src/main/java/net/Indyuce/mmocore/api/player/social/FriendRequest.java index 895c3d3f..1a947872 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/social/FriendRequest.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/social/FriendRequest.java @@ -1,9 +1,8 @@ package net.Indyuce.mmocore.api.player.social; -import org.bukkit.Sound; - import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; +import org.bukkit.Sound; public class FriendRequest extends Request { private final PlayerData target; diff --git a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java index d0d2dc7a..a42e4e97 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.gui; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.inventory.InventoryClickEvent; @@ -89,13 +90,13 @@ public class AttributeView extends EditableInventory { int spent = playerData.getAttributes().countSkillPoints(); if (spent < 1) { MMOCore.plugin.configManager.getSimpleMessage("no-attribute-points-spent").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.NOT_ENOUGH_POINTS); return; } if (playerData.getAttributeReallocationPoints() < 1) { MMOCore.plugin.configManager.getSimpleMessage("not-attribute-reallocation-point").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.NOT_ENOUGH_POINTS); return; } @@ -103,7 +104,7 @@ public class AttributeView extends EditableInventory { playerData.giveAttributePoints(spent); playerData.giveAttributeReallocationPoints(-1); MMOCore.plugin.configManager.getSimpleMessage("attribute-points-reallocated", "points", "" + playerData.getAttributePoints()).send(player); - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.RESET_ATTRIBUTES); open(); } @@ -112,21 +113,21 @@ public class AttributeView extends EditableInventory { if (playerData.getAttributePoints() < 1) { MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.NOT_ENOUGH_POINTS); return; } AttributeInstance ins = playerData.getAttributes().getInstance(attribute); if (attribute.hasMax() && ins.getBase() >= attribute.getMax()) { MMOCore.plugin.configManager.getSimpleMessage("attribute-max-points-hit").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.NOT_ENOUGH_POINTS); return; } ins.addBase(1); playerData.giveAttributePoints(-1); MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", "" + ins.getBase()).send(player); - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.LEVEL_ATTRIBUTE); open(); } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java b/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java index c27dbfb4..b4ec60d5 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java +++ b/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.gui; +import net.Indyuce.mmocore.manager.SoundManager; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -136,7 +137,7 @@ public class ClassConfirmation extends EditableInventory { while (playerData.hasSkillBound(0)) playerData.unbindSkill(0); MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player); - player.playSound(player.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SELECT_CLASS); player.closeInventory(); } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java b/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java index 65d9ee9a..76b1f6bd 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java +++ b/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java @@ -5,6 +5,7 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; @@ -117,14 +118,14 @@ public class ClassSelect extends EditableInventory { return; if (playerData.getClassPoints() < 1) { - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.CANT_SELECT_CLASS); new ConfigMessage("cant-choose-new-class").send(player); return; } PlayerClass profess = MMOCore.plugin.classManager.get(tag); if (profess.equals(playerData.getProfess())) { - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.CANT_SELECT_CLASS); MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player); return; } diff --git a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java index e2b25f62..e3eb6d51 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java @@ -11,6 +11,7 @@ import net.Indyuce.mmocore.gui.api.item.InventoryItem; import net.Indyuce.mmocore.gui.api.item.InventoryPlaceholderItem; import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem; import net.Indyuce.mmocore.gui.api.item.Placeholders; +import net.Indyuce.mmocore.manager.SoundManager; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.item.NBTItem; import org.apache.commons.lang.Validate; @@ -237,7 +238,7 @@ public class QuestViewer extends EditableInventory { if (playerData.getQuestData().hasCurrent(quest)) { if (event.getAction() == InventoryAction.PICKUP_HALF) { playerData.getQuestData().start(null); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.CANCEL_QUEST); MMOCore.plugin.configManager.getSimpleMessage("cancel-quest").send(player); open(); } @@ -295,7 +296,7 @@ public class QuestViewer extends EditableInventory { * eventually start a new quest. */ MMOCore.plugin.configManager.getSimpleMessage("start-quest", "quest", quest.getName()).send(player); - player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.START_QUEST); playerData.getQuestData().start(quest); open(); } diff --git a/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java b/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java index f2a2371c..03664da7 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.gui; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; @@ -68,7 +69,7 @@ public class SubclassConfirmation extends EditableInventory { playerData.setClass(profess); MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player); - player.playSound(player.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SELECT_CLASS); player.closeInventory(); } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java b/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java index a43db96c..cf42737d 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.inventory.InventoryClickEvent; @@ -120,7 +121,7 @@ public class SubclassSelect extends EditableInventory { if (playerData.getClassPoints() < 1) { player.closeInventory(); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.CANT_SELECT_CLASS); new ConfigMessage("cant-choose-new-class").send(player); return; } diff --git a/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java b/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java index 3e9fdbe0..6ae4229a 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java +++ b/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.listener; import net.Indyuce.mmocore.manager.ConfigManager; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -34,7 +35,7 @@ public class SpellCast implements Listener { * skill casting mode */ if (action == ConfigManager.SwapAction.HOTBAR_SWAP) { - player.playSound(player.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1, 1); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.HOTBAR_SWAP); for (int j = 0; j < 9; j++) { ItemStack replaced = player.getInventory().getItem(j + 9 * 3); player.getInventory().setItem(j + 9 * 3, player.getInventory().getItem(j)); @@ -46,7 +47,7 @@ public class SpellCast implements Listener { if (!((!MMOCore.plugin.configManager.canCreativeCast && player.getGameMode() == GameMode.CREATIVE) || player.getGameMode() == GameMode.SPECTATOR) && !playerData.isCasting() && playerData.getBoundSkills().size() > 0) { playerData.skillCasting = new SkillCasting(playerData); - player.playSound(player.getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1, 2); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_BEGIN); } } @@ -102,7 +103,7 @@ public class SpellCast implements Listener { : MMOCore.plugin.configManager.normalSwapAction; if(action != ConfigManager.SwapAction.SPELL_CAST || !playerData.isOnline()) return; if (event.getPlayer().equals(playerData.getPlayer()) && !player.isSneaking()) { - player.playSound(player.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1, 2); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SPELL_CAST_END); MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(playerData.getPlayer()); close(); } diff --git a/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java b/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java index a8525d88..b4f21b78 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java @@ -1,7 +1,7 @@ package net.Indyuce.mmocore.listener; +import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Particle; -import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -29,7 +29,7 @@ public class WaypointsListener implements Listener { data.unlockWaypoint(waypoint); new SmallParticleEffect(player, Particle.SPELL_WITCH); MMOCore.plugin.configManager.getSimpleMessage("new-waypoint", "waypoint", waypoint.getName()).send(player); - player.playSound(player.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1.2f); + MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.WARP_UNLOCK); return; } diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index c5f7a4ba..da063a28 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -84,6 +84,7 @@ public class ConfigManager { loadDefaultFile("stats.yml"); loadDefaultFile("waypoints.yml"); loadDefaultFile("restrictions.yml"); + loadDefaultFile("sounds.yml"); loadDefaultFile("loot-chests.yml"); loadDefaultFile("commands.yml"); loadDefaultFile("guilds.yml"); diff --git a/src/main/java/net/Indyuce/mmocore/manager/SoundManager.java b/src/main/java/net/Indyuce/mmocore/manager/SoundManager.java new file mode 100644 index 00000000..0f70949d --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/manager/SoundManager.java @@ -0,0 +1,72 @@ +package net.Indyuce.mmocore.manager; + +import net.Indyuce.mmocore.api.SoundObject; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class SoundManager { + private final Map sounds = new HashMap<>(); + + public SoundManager(FileConfiguration config) { + for(SoundEvent sound : SoundEvent.values()) + sounds.put(sound, new SoundObject(config.getString(sound.name().replace("_", "-").toLowerCase()))); + } + + + public void play(Block block, SoundEvent event) { + play(block, block.getLocation(), event); + } + + public void play(Block block, Location loc, SoundEvent event) { + SoundObject sound = sounds.get(event); + if(sound.hasSound()) + block.getWorld().playSound(loc, sound.getSound(), sound.getVolume(), sound.getPitch()); + else block.getWorld().playSound(loc, sound.getKey(), sound.getVolume(), sound.getPitch()); + } + + public void play(Player player, SoundEvent event) { + play(player, player.getLocation(), event); + } + + public void play(Player player, Location loc, SoundEvent event) { + SoundObject sound = sounds.get(event); + if(sound.hasSound()) + player.playSound(loc, sound.getSound(), sound.getVolume(), sound.getPitch()); + else player.playSound(loc, sound.getKey(), sound.getVolume(), sound.getPitch()); + } + + public void play(Player player, SoundEvent event, float volume, float pitch) { + play(player, player.getLocation(), event, volume, pitch); + } + + public void play(Player player, Location loc, SoundEvent event, float volume, float pitch) { + SoundObject sound = sounds.get(event); + if(sound.hasSound()) + player.playSound(loc, sound.getSound(), volume, pitch); + else player.playSound(loc, sound.getKey(), volume, pitch); + } + + public enum SoundEvent { + LEVEL_UP, + WARP_TELEPORT, + WARP_CANCELLED, + WARP_CHARGE, + WARP_UNLOCK, + HOTBAR_SWAP, + SPELL_CAST_BEGIN, + SPELL_CAST_END, + CANT_SELECT_CLASS, + SELECT_CLASS, + LEVEL_ATTRIBUTE, + RESET_ATTRIBUTES, + NOT_ENOUGH_POINTS, + CANCEL_QUEST, + START_QUEST, + CLOSE_LOOT_CHEST + } +} diff --git a/src/main/resources/default/sounds.yml b/src/main/resources/default/sounds.yml new file mode 100644 index 00000000..d7497c58 --- /dev/null +++ b/src/main/resources/default/sounds.yml @@ -0,0 +1,28 @@ +# Format = SOUND,VOLUME,PITCH +# If only the sound name is specified, the +# volume and pitch will be set to 1. + +level-up: ENTITY_PLAYER_LEVELUP,1,2 + +warp-cancelled: ENTITY_VILLAGER_NO,1,0.5 +warp-teleport: ENTITY_ENDERMAN_TELEPORT,1,0.5 +warp-charge: BLOCK_NOTE_BLOCK_BELL #Uses a special pitch method, so pitch and volume is not changeable +warp-unlock: UI_TOAST_CHALLENGE_COMPLETE,1,1.2 + +hotbar-swap: ITEM_ARMOR_EQUIP_LEATHER + +spell-cast-begin: BLOCK_END_PORTAL_FRAME_FILL,1,2 +spell-cast-end: BLOCK_FIRE_EXTINGUISH,1,2 + +cant-select-class: ENTITY_VILLAGER_NO +select-class: UI_TOAST_CHALLENGE_COMPLETE + +level-attribute: ENTITY_PLAYER_LEVELUP +reset-attributes: ENTITY_PLAYER_LEVELUP + +not-enough-points: ENTITY_VILLAGER_NO + +cancel-quest: ENTITY_VILLAGER_NO +start-quest: ENTITY_EXPERIENCE_ORB_PICKUP + +close-loot-chest: ITEM_ARMOR_EQUIP_LEATHER \ No newline at end of file