From 8c9a554864f55289dc66887588eb13447c6ec8cd Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Tue, 16 Sep 2014 01:34:28 +0200 Subject: [PATCH] Added ProTips sound. --- .../me/azenet/UHPlugin/UHGameManager.java | 14 ++-------- .../me/azenet/UHPlugin/UHPluginCommand.java | 4 +-- .../me/azenet/UHPlugin/UHProTipsSender.java | 16 ++++++++++-- src/main/java/me/azenet/UHPlugin/UHUtils.java | 26 ++++++++++++++++++- src/main/resources/config.yml | 5 ++++ 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/azenet/UHPlugin/UHGameManager.java b/src/main/java/me/azenet/UHPlugin/UHGameManager.java index b25b7c9..21c6a9b 100644 --- a/src/main/java/me/azenet/UHPlugin/UHGameManager.java +++ b/src/main/java/me/azenet/UHPlugin/UHGameManager.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; @@ -87,16 +86,7 @@ public UHGameManager(UHPlugin plugin) { // Registers the death sound - String nameDeathSound = p.getConfig().getString("death.announcements.sound"); - if(nameDeathSound != null) { - nameDeathSound = nameDeathSound.trim().toUpperCase().replace(" ", "_"); - try { - this.deathSound = Sound.valueOf(nameDeathSound); - } catch(IllegalArgumentException ignored) { - // Non-existent death sound - // The value of this.deathSound is kept to null. - } - } + this.deathSound = UHUtils.string2Sound(p.getConfig().getString("death.announcements.sound")); } /** @@ -848,7 +838,7 @@ public Sound getDeathSound() { */ public Integer getEpisodeLength() { try { - return UHUtils.string2time(p.getConfig().getString("episodes.length")); + return UHUtils.string2Time(p.getConfig().getString("episodes.length")); } catch(IllegalArgumentException e) { return 20 * 60; // default value, 20 minutes } diff --git a/src/main/java/me/azenet/UHPlugin/UHPluginCommand.java b/src/main/java/me/azenet/UHPlugin/UHPluginCommand.java index 3be7dff..96c98f3 100644 --- a/src/main/java/me/azenet/UHPlugin/UHPluginCommand.java +++ b/src/main/java/me/azenet/UHPlugin/UHPluginCommand.java @@ -1546,7 +1546,7 @@ private void doTimers(CommandSender sender, Command command, String label, Strin } else { try { - Integer duration = UHUtils.string2time(args[2]); + Integer duration = UHUtils.string2Time(args[2]); String timerName = UHUtils.getStringFromCommandArguments(args, 3); if(p.getTimerManager().getTimer(timerName) != null) { @@ -1572,7 +1572,7 @@ else if(subcommand.equalsIgnoreCase("set")) { // /uh timers set > protipsGiven = new HashMap>(); + Sound proTipsSound = null; + Float proTipsSoundVolume = 1f; + Float proTipsSoundPitch = 1f; + public static final String PROTIP_LOCK_CHAT = "teamchat.lock"; public static final String PROTIP_USE_G_COMMAND = "teamchat.useGCommand"; public static final String PROTIP_USE_T_COMMAND = "teamchat.useTCommand"; @@ -59,10 +64,15 @@ public UHProTipsSender(UHPlugin p) { this.i = p.getI18n(); // Initialization of the "protips" map - protipsGiven.put(PROTIP_LOCK_CHAT, new ArrayList()); protipsGiven.put(PROTIP_USE_G_COMMAND, new ArrayList()); protipsGiven.put(PROTIP_USE_T_COMMAND, new ArrayList()); + + // Sound + proTipsSound = UHUtils.string2Sound(p.getConfig().getString("protips.sound.name")); + proTipsSoundVolume = (float) p.getConfig().getDouble("protips.sound.volume"); + proTipsSoundPitch = (float) p.getConfig().getDouble("protips.sound.pitch"); + } @@ -92,8 +102,10 @@ public boolean sendProtip(Player player, String protip) { protipsGiven.get(protip).add(player.getUniqueId()); - player.sendMessage(i.t("protips.base") + " " + ChatColor.RESET + i.t("protips." + protip)); + player.sendMessage(i.t("protips.base") + " " + ChatColor.RESET + i.t("protips." + protip)); + player.playSound(player.getLocation(), proTipsSound, proTipsSoundVolume, proTipsSoundPitch); + return false; } diff --git a/src/main/java/me/azenet/UHPlugin/UHUtils.java b/src/main/java/me/azenet/UHPlugin/UHUtils.java index a51eed1..9b7e519 100644 --- a/src/main/java/me/azenet/UHPlugin/UHUtils.java +++ b/src/main/java/me/azenet/UHPlugin/UHUtils.java @@ -26,6 +26,7 @@ import org.bukkit.FireworkEffect.Builder; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.EntityType; @@ -64,6 +65,29 @@ public static String getStringFromCommandArguments(String[] args, int startIndex return text; } + /** + * Converts a string to a Sound. + *

+ * "AMBIENCE_THUNDER", "ambiance thunder" and "AMBIENCE THunDER" are recognized as + * Sound.AMBIENCE_THUNDER, as example. + * + * @param soundName The text to be converted. + * @return The corresponding Sound, or null if there isn't any match. + */ + public static Sound string2Sound(String soundName) { + if(soundName != null) { + soundName = soundName.trim().toUpperCase().replace(" ", "_"); + try { + return Sound.valueOf(soundName); + } catch(IllegalArgumentException e) { + // Non-existent sound + return null; + } + } + + return null; + } + /** * Converts a string to a number of seconds. *

@@ -81,7 +105,7 @@ public static String getStringFromCommandArguments(String[] args, int startIndex * @throws IllegalArgumentException if the text is not formatted as above. * @throws NumberFormatException if the text between the colons cannot be converted in integers. */ - public static int string2time(String text) { + public static int string2Time(String text) { String[] splitted = text.split(":"); if(splitted.length > 3) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 76a4334..a5509f4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -168,6 +168,11 @@ dynmap: logTeamChat: false protips: + sound: + name: NOTE_PLING # Cf. http://l.carrade.eu/bukkit-sounds ; "NONE" if you don't want a sound. + volume: 2 + pitch: 3 + teamchat: useTCommand: true # Protip: team-chat command lock: true # Protip: can lock the team-chat