Skip to content

Commit b4fed00

Browse files
committed
Allow setting a global block sound instead of per-rule
1 parent 275a29c commit b4fed00

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/main/java/net/jadedmc/commandblockerpro/listeners/PlayerCommandPreprocessListener.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import net.jadedmc.commandblockerpro.events.CommandBlockEvent;
2929
import net.jadedmc.commandblockerpro.rules.Rule;
3030
import net.jadedmc.commandblockerpro.utils.ChatUtils;
31+
import org.bukkit.Sound;
3132
import org.bukkit.entity.Player;
3233
import org.bukkit.event.EventHandler;
3334
import org.bukkit.event.Listener;
@@ -54,14 +55,14 @@ public PlayerCommandPreprocessListener(final CommandBlockerProPlugin plugin) {
5455
*/
5556
@EventHandler
5657
public void onCommandSend(PlayerCommandPreprocessEvent event) {
57-
Player player = event.getPlayer();
58-
String command = event.getMessage().split(" ")[0];
58+
final Player player = event.getPlayer();
59+
final String command = event.getMessage().split(" ")[0];
5960

6061
// Loop through each rule configured, blocking the command if the rule catches it.
61-
for(Rule rule : plugin.ruleManager().rules()) {
62+
for(final Rule rule : plugin.ruleManager().getRules()) {
6263
if(rule.shouldBlock(player, command)) {
6364
// Calls the CommandBlockEvent.
64-
CommandBlockEvent commandBlockEvent = new CommandBlockEvent(player, command, rule);
65+
final CommandBlockEvent commandBlockEvent = new CommandBlockEvent(player, command, rule);
6566
plugin.getServer().getPluginManager().callEvent(commandBlockEvent);
6667

6768
// If the CommandBlockEvent is cancelled, allow the command to be processed.
@@ -82,6 +83,24 @@ public void onCommandSend(PlayerCommandPreprocessEvent event) {
8283
if(rule.hasBlockSound()) {
8384
player.playSound(player.getLocation(), rule.getBlockSound(), rule.getBlockSoundVolume(), rule.getBlockSoundPitch());
8485
}
86+
else if(plugin.settingsManager().getConfig().isSet("blockSound.sound")) {
87+
final Sound blockSound = Sound.valueOf(plugin.settingsManager().getConfig().getString("blockSound.sound"));
88+
float blockSoundPitch = 1.0f;
89+
float blockSoundVolume = 1.0f;
90+
91+
// Check for sound pitch.
92+
if (plugin.settingsManager().getConfig().isSet("blockSound.pitch")) {
93+
blockSoundPitch = (float) plugin.settingsManager().getConfig().getDouble("blockSound.pitch");
94+
}
95+
96+
// Check for Sound volume.
97+
if (plugin.settingsManager().getConfig().isSet("blockSound.volume")) {
98+
blockSoundVolume = (float) plugin.settingsManager().getConfig().getDouble("blockSound.volume");
99+
}
100+
101+
// Play the sound.
102+
player.playSound(player.getLocation(), blockSound, blockSoundVolume, blockSoundPitch);
103+
}
85104
}
86105
}
87106
}

0 commit comments

Comments
 (0)