diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 9bcdb3e0e..7c447cdce 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -75,6 +75,9 @@ public class McMMOPlayer { private boolean abilityUse = true; private boolean godMode; + private Sound recentSound; + private int lastSound; + private final Map abilityMode = new HashMap(); private final Map abilityInformed = new HashMap(); @@ -442,6 +445,50 @@ public class McMMOPlayer { godMode = !godMode; } + /* + * Sounds + */ + + /** + * Play a sound at the players location. + * Sound will only get played if it's different + * compared to the previously played sound or if the cooldown has expired. + * + * @param sound The Sound to play + * @param volume Volume of the sound + * @param pitch Pitch of the sound + * @param cooldown Cooldown time between sounds + */ + public void playSound(Sound sound, float volume, float pitch, int cooldown) { + if (getRecentSound() == sound && !SkillUtils.cooldownExpired(getLastSound(), 1)) { + return; + } + + setRecentSound(sound); + actualizeLastSound(); + player.playSound(player.getLocation(), sound, volume, pitch); + } + + public void playSound(Sound sound, float volume, float pitch) { + playSound(sound, volume, pitch, 1); + } + + public Sound getRecentSound() { + return recentSound; + } + + public void setRecentSound(Sound recentSound) { + this.recentSound = recentSound; + } + + public int getLastSound() { + return lastSound; + } + + public void actualizeLastSound() { + lastSound = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); + } + /* * Skill notifications */ diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java index cf207ab73..d6cf1ff82 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java @@ -148,7 +148,7 @@ public class RepairManager extends SkillManager { // BWONG BWONG BWONG if (Config.getInstance().getRepairAnvilUseSoundsEnabled()) { - player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); + mcMMOPlayer.playSound(Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); } // Repair the item!