From e962f645b69a197f4fae69d982e21b3629ee07b8 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 20 Jan 2019 01:21:33 -0800 Subject: [PATCH] Skill Unlock notifications now have sounds --- .../com/gmail/nossr50/datatypes/player/McMMOPlayer.java | 4 ++-- .../java/com/gmail/nossr50/listeners/SelfListener.java | 9 +++++++-- .../gmail/nossr50/util/player/NotificationManager.java | 6 ++++++ .../java/com/gmail/nossr50/util/sounds/SoundManager.java | 8 +++++++- 4 files changed, 22 insertions(+), 5 deletions(-) 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 1da6d8581..6a5d585e3 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -149,9 +149,9 @@ public class McMMOPlayer { updateXPBar(primarySkillType, plugin); } - public void processUnlockNotifications(mcMMO plugin, PrimarySkillType primarySkillType) + public void processUnlockNotifications(mcMMO plugin, PrimarySkillType primarySkillType, int skillLevel) { - RankUtils.executeSkillUnlockNotifications(plugin, this, primarySkillType, profile.getSkillLevel(primarySkillType)); + RankUtils.executeSkillUnlockNotifications(plugin, this, primarySkillType, skillLevel); } public void updateXPBar(PrimarySkillType primarySkillType, Plugin plugin) diff --git a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java index 50de80bfd..fac28de6a 100644 --- a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java @@ -30,8 +30,13 @@ public class SelfListener implements Listener { Player player = event.getPlayer(); PrimarySkillType skill = event.getSkill(); - //Send player skill unlock notifications - UserManager.getPlayer(player).processUnlockNotifications(plugin, event.getSkill()); + //Players can gain multiple levels especially during xprate events + for(int i = 0; i < event.getLevelsGained(); i++) + { + int previousLevelGained = event.getSkillLevel() - i; + //Send player skill unlock notifications + UserManager.getPlayer(player).processUnlockNotifications(plugin, event.getSkill(), previousLevelGained); + } if(Config.getInstance().getScoreboardsEnabled()) ScoreboardManager.handleLevelUp(player, skill); diff --git a/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java b/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java index 08446e88c..d1051c776 100644 --- a/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java @@ -8,11 +8,14 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.TextComponentFactory; +import com.gmail.nossr50.util.sounds.SoundManager; +import com.gmail.nossr50.util.sounds.SoundType; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.SoundCategory; import org.bukkit.entity.Player; public class NotificationManager { @@ -122,6 +125,9 @@ public class NotificationManager { //CHAT MESSAGE mcMMOPlayer.getPlayer().spigot().sendMessage(TextComponentFactory.getSubSkillUnlockedNotificationComponents(mcMMOPlayer.getPlayer(), subSkillType)); + //Unlock Sound Effect + SoundManager.sendCategorizedSound(mcMMOPlayer.getPlayer(), mcMMOPlayer.getPlayer().getLocation(), SoundType.SKILL_UNLOCKED, SoundCategory.MASTER); + //ACTION BAR MESSAGE /*if(AdvancedConfig.getInstance().doesNotificationUseActionBar(NotificationType.SUBSKILL_UNLOCKED)) mcMMOPlayer.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(LocaleLoader.getString("JSON.SkillUnlockMessage", diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java index b0016359b..d64f5a201 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java @@ -4,6 +4,7 @@ import com.gmail.nossr50.config.SoundConfig; import com.gmail.nossr50.util.Misc; import org.bukkit.Location; import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.World; import org.bukkit.entity.Player; @@ -14,7 +15,12 @@ public class SoundManager { */ public static void sendSound(Player player, Location location, SoundType soundType) { - player.playSound(location, getSound(soundType), getVolume(soundType), getPitch(soundType)); + player.playSound(location, getSound(soundType), SoundCategory.MASTER, getVolume(soundType), getPitch(soundType)); + } + + public static void sendCategorizedSound(Player player, Location location, SoundType soundType, SoundCategory soundCategory) + { + player.playSound(location, getSound(soundType), soundCategory, getVolume(soundType), getPitch(soundType)); } public static void worldSendSound(World world, Location location, SoundType soundType)