Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public enum ActionType {
CLOSE("[close]", "Close the viewers open menu", "- '[close]"),
REFRESH("[refresh]", "Refresh items in the current menu view", "- '[refresh]"),
BROADCAST_SOUND("[broadcastsound]", "Broadcast a sound to the server", "- '[broadcastsound]"),
BROADCAST_RAW_SOUND("[rawsound]", "Broadcast a RAW sound to the server", "- '[rawsound]"),
BROADCAST_WORLD_SOUND("[broadcastsoundworld]", "Broadcast a sound to the player's world", "- '[broadcastsoundworld]"),
BROADCAST_WORLD_RAW_SOUND("[rawsoundworld]", "Broadcast a RAW sound to the player's world", "- '[rawsoundworld]"),
PLAY_SOUND("[sound]", "Play a sound for a the specific player", "- '[sound]"),
PLAY_RAW_SOUND("[rawsound]", "Play a RAW sound for a the specific player", "- '[rawsound]"),
TAKE_MONEY("[takemoney]", "Take money from a player (requires Vault)", "- '[takemoney] <amount>"),
GIVE_MONEY("[givemoney]", "Give money to a player (requires Vault)", "- '[givemoney] <amount>"),
TAKE_EXP("[takeexp]", "Take exp points/levels from a player", "- '[takeexp] <amount>L'"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,33 +338,45 @@ public void run() {
break;

case BROADCAST_SOUND:
case BROADCAST_RAW_SOUND:
case BROADCAST_WORLD_SOUND:
case BROADCAST_WORLD_RAW_SOUND:
case PLAY_RAW_SOUND:
case PLAY_SOUND:
final Sound sound;
boolean isRaw = isRaw(actionType);

Sound sound = null;
String soundName = executable;
float volume = 1;
float pitch = 1;

if (!executable.contains(" ")) {
try {
sound = Sound.valueOf(executable.toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
"Sound name given for sound action: " + executable + ", is not a valid sound!",
exception
);
break;
if (!isRaw) {
try {
sound = Sound.valueOf(executable.toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
"Sound name given for sound action: " + executable + ", is not a valid sound!",
exception
);
break;
}
}
} else {
String[] parts = executable.split(" ", 3);

try {
sound = Sound.valueOf(parts[0].toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
"Sound name given for sound action: " + parts[0] + ", is not a valid sound!",
exception
);
break;
if (!isRaw) {
try {
sound = Sound.valueOf(parts[0].toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
"Sound name given for sound action: " + parts[0] + ", is not a valid sound!",
exception
);
break;
}
} else {
soundName = parts[0];
}

if (parts.length == 3) {
Expand Down Expand Up @@ -401,6 +413,27 @@ public void run() {
}
}

if (isRaw) {
switch (actionType) {
case BROADCAST_WORLD_RAW_SOUND:
for (final Player target : player.getWorld().getPlayers()) {
target.playSound(target.getLocation(), soundName, volume, pitch);
}
break;

case BROADCAST_RAW_SOUND:
for (final Player target : Bukkit.getOnlinePlayers()) {
target.playSound(target.getLocation(), soundName, volume, pitch);
}
break;

case PLAY_RAW_SOUND:
player.playSound(player.getLocation(), soundName, volume, pitch);
break;
}
break;
}

switch (actionType) {
case BROADCAST_SOUND:
for (final Player target : Bukkit.getOnlinePlayers()) {
Expand All @@ -424,4 +457,9 @@ public void run() {
break;
}
}

private boolean isRaw(ActionType actionType) {
return actionType == ActionType.PLAY_RAW_SOUND || actionType == ActionType.BROADCAST_RAW_SOUND || actionType == ActionType.BROADCAST_WORLD_RAW_SOUND;
}

}