Skip to content

Commit

Permalink
Added ProTips sound.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Sep 15, 2014
1 parent 023f92a commit 8c9a554
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
14 changes: 2 additions & 12 deletions src/main/java/me/azenet/UHPlugin/UHGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}

/**
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/azenet/UHPlugin/UHPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -1572,7 +1572,7 @@ else if(subcommand.equalsIgnoreCase("set")) { // /uh timers set <duration> <name
}
else {
try {
Integer duration = UHUtils.string2time(args[2]);
Integer duration = UHUtils.string2Time(args[2]);
String timerName = UHUtils.getStringFromCommandArguments(args, 3);

UHTimer timer = p.getTimerManager().getTimer(timerName);
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/me/azenet/UHPlugin/UHProTipsSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import me.azenet.UHPlugin.i18n.I18n;

import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;


Expand All @@ -50,6 +51,10 @@ public class UHProTipsSender {

Map<String,ArrayList<UUID>> protipsGiven = new HashMap<String,ArrayList<UUID>>();

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";
Expand All @@ -59,10 +64,15 @@ public UHProTipsSender(UHPlugin p) {
this.i = p.getI18n();

// Initialization of the "protips" map

protipsGiven.put(PROTIP_LOCK_CHAT, new ArrayList<UUID>());
protipsGiven.put(PROTIP_USE_G_COMMAND, new ArrayList<UUID>());
protipsGiven.put(PROTIP_USE_T_COMMAND, new ArrayList<UUID>());

// 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");

}


Expand Down Expand Up @@ -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;
}

Expand Down
26 changes: 25 additions & 1 deletion src/main/java/me/azenet/UHPlugin/UHUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,6 +65,29 @@ public static String getStringFromCommandArguments(String[] args, int startIndex
return text;
}

/**
* Converts a string to a Sound.
* <p>
* "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.
* <p>
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c9a554

Please sign in to comment.