Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Sound: add custom sound for vault groups
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Oct 7, 2023
1 parent 748d34f commit 692e86f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/main/java/net/flectone/utils/ObjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,30 @@ public static int getCurrentTime() {
}

public static void playSound(@Nullable Player player, @NotNull String command) {
if (player == null || !config.getBoolean("sound." + command + ".enable")) return;
if (player == null) return;

String[] params = config.getString("sound." + command + ".type").split(":");
if (params.length < 3) {
Main.warning("Update the sound string sound." + command + ".type to a new format SOUND:VOLUME:PITCH");
params = new String[]{params[0], "1", "1"};
}
Main.getDataThreadPool().execute(() -> {
String vaultSound = config.getString("sound." + FPlayer.getVaultGroup(player) + "." + command);
if (!config.getBoolean("sound." + command + ".enable") && vaultSound.isEmpty()) return;

try {
player.playSound(player.getLocation(), Sound.valueOf(params[0]), Float.parseFloat(params[1]), Float.parseFloat(params[2]));
} catch (IllegalArgumentException exception) {
Main.warning("Incorrect sound " + params[0] + " for " + command + ".sound.type");
exception.printStackTrace();
}
vaultSound = vaultSound.isEmpty()
? config.getString("sound." + command + ".type")
: vaultSound;

String[] params = vaultSound.split(":");

if (params.length < 3) {
Main.warning("Update the sound string sound." + command + ".type to a new format SOUND:VOLUME:PITCH");
params = new String[]{params[0], "1", "1"};
}

try {
player.playSound(player.getLocation(), Sound.valueOf(params[0]), Float.parseFloat(params[1]), Float.parseFloat(params[2]));
} catch (IllegalArgumentException exception) {
Main.warning("Incorrect sound " + params[0] + " for " + command + ".sound.type");
exception.printStackTrace();
}
});
}

@NotNull
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,17 @@ cool-down:
# Sound type format
# SOUND_NAME:VOLUME:PITCH
sound:

# You can set different sounds for vault groups
#
# admin:
# try-cube: "BLOCK_NOTE_BLOCK_BELL:1:1"
# helper:
# try-cube: "ENTITY_LLAMA_SPIT:0.3:1"
#
# In this case you don't need to use "enable" and "type",
# the most important thing is that this string is not empty

spit:
enable: true
type: "ENTITY_LLAMA_SPIT:0.3:1"
Expand Down

0 comments on commit 692e86f

Please sign in to comment.