Ensure that we're not spamming sounds

This commit is contained in:
TfT_02 2013-12-15 00:42:09 +01:00
parent 4486261413
commit da1841eb9e
2 changed files with 48 additions and 1 deletions

View File

@ -75,6 +75,9 @@ public class McMMOPlayer {
private boolean abilityUse = true;
private boolean godMode;
private Sound recentSound;
private int lastSound;
private final Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
private final Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
@ -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
*/

View File

@ -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!