Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new actions #82

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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("[broadcastrawsound]", "Broadcast a RAW sound to the server", "- '[broadcastrawsound]"),
BROADCAST_WORLD_SOUND("[broadcastsoundworld]", "Broadcast a sound to the player's world", "- '[broadcastsoundworld]"),
BROADCAST_WORLD_RAW_SOUND("[broadcastrawsoundworld]", "Broadcast a RAW sound to the player's world", "- '[broadcastrawsoundworld]"),
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 @@ -352,33 +352,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 @@ -416,6 +428,21 @@ public void run() {
}

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

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

case PLAY_RAW_SOUND:
player.playSound(player.getLocation(), soundName, volume, pitch);
break;
case BROADCAST_SOUND:
for (final Player broadcastTarget : Bukkit.getOnlinePlayers()) {
broadcastTarget.playSound(broadcastTarget.getLocation(), sound, volume, pitch);
Expand All @@ -438,4 +465,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;
}

}