diff --git a/src/main/java/pro/cloudnode/smp/cloudnodemsg/Message.java b/src/main/java/pro/cloudnode/smp/cloudnodemsg/Message.java index b206444..aa460d2 100644 --- a/src/main/java/pro/cloudnode/smp/cloudnodemsg/Message.java +++ b/src/main/java/pro/cloudnode/smp/cloudnodemsg/Message.java @@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataType; +import org.bukkit.Sound; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import pro.cloudnode.smp.cloudnodemsg.error.ChannelOfflineError; @@ -85,6 +86,34 @@ public void send(final @NotNull Context context) throws InvalidPlayerError { sendMessage(recipient, CloudnodeMSG.getInstance().config() .incoming(senderUsername, recipientUsername, message)); + // Play PM notification sound for the recipient (if online and enabled in config) + recipientPlayer.ifPresent(recPlayer -> { + try { + // Don't play sound if recipient is the same as sender (e.g., self-message) + if (sender.getUniqueId().equals(recipient.getUniqueId())) return; + + if (!CloudnodeMSG.getInstance().getConfig().getBoolean("pm-sound.enabled", true)) return; + + final String soundName = CloudnodeMSG.getInstance().getConfig().getString("pm-sound.sound", "BLOCK_NOTE_BLOCK_PLING"); + final float volume = (float) CloudnodeMSG.getInstance().getConfig().getDouble("pm-sound.volume", 1.0); + final float pitch = (float) CloudnodeMSG.getInstance().getConfig().getDouble("pm-sound.pitch", 1.0); + + try { + final Sound sound = Sound.valueOf(soundName); + recPlayer.playSound(recPlayer.getLocation(), sound, volume, pitch); + } catch (IllegalArgumentException | NoSuchFieldError | NullPointerException e) { + // fallback to a safe default if configured sound isn't available on this server version + try { + recPlayer.playSound(recPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, volume, pitch); + } catch (Throwable ignored) { + // silently ignore if no sound is available + } + } + } catch (Throwable ignored) { + // Ensure message sending never fails because of sound errors + } + }); + if (sender.getUniqueId().equals(console.getUniqueId()) || (senderPlayer.isPresent() && !Message.hasChannel(senderPlayer.get(), recipient))) setReplyTo(sender, recipient); if (recipient.getUniqueId().equals(console.getUniqueId()) || (recipientPlayer.isPresent() && !Message.hasChannel(recipientPlayer.get(), sender))) @@ -331,4 +360,4 @@ public static enum Context { */ REPLY; } -} +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6012eb5..44f4729 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -152,3 +152,15 @@ errors: # Trying to message a team, but not in one not-in-team: "(!) You are not in a team." + + +pm-sound: + # Enable or disable playing a sound when a private message is received + enabled: true + # Sound to play on private message (Minecraft sound identifier) + # Examples: ENTITY_ALLAY_AMBIENT_WITH_ITEM, ENTITY_PLAYER_LEVELUP, etc. + sound: BLOCK_NOTE_BLOCK_PLINGt + # Volume of the sound (float). 1.0 is normal volume, increase to be louder. + volume: 1.0 + # Pitch of the sound (float). 1.0 is normal pitch, lower for deeper, higher for sharper. + pitch: 1.0