77import org .bukkit .command .CommandSender ;
88import org .bukkit .entity .Player ;
99import org .bukkit .persistence .PersistentDataType ;
10+ import org .bukkit .Sound ;
1011import org .jetbrains .annotations .NotNull ;
1112import org .jetbrains .annotations .Nullable ;
1213import pro .cloudnode .smp .cloudnodemsg .error .ChannelOfflineError ;
@@ -85,6 +86,34 @@ public void send(final @NotNull Context context) throws InvalidPlayerError {
8586 sendMessage (recipient , CloudnodeMSG .getInstance ().config ()
8687 .incoming (senderUsername , recipientUsername , message ));
8788
89+ // Play PM notification sound for the recipient (if online and enabled in config)
90+ recipientPlayer .ifPresent (recPlayer -> {
91+ try {
92+ // Don't play sound if recipient is the same as sender (e.g., self-message)
93+ if (sender .getUniqueId ().equals (recipient .getUniqueId ())) return ;
94+
95+ if (!CloudnodeMSG .getInstance ().getConfig ().getBoolean ("pm-sound.enabled" , true )) return ;
96+
97+ final String soundName = CloudnodeMSG .getInstance ().getConfig ().getString ("pm-sound.sound" , "BLOCK_NOTE_BLOCK_PLING" );
98+ final float volume = (float ) CloudnodeMSG .getInstance ().getConfig ().getDouble ("pm-sound.volume" , 1.0 );
99+ final float pitch = (float ) CloudnodeMSG .getInstance ().getConfig ().getDouble ("pm-sound.pitch" , 1.0 );
100+
101+ try {
102+ final Sound sound = Sound .valueOf (soundName );
103+ recPlayer .playSound (recPlayer .getLocation (), sound , volume , pitch );
104+ } catch (IllegalArgumentException | NoSuchFieldError | NullPointerException e ) {
105+ // fallback to a safe default if configured sound isn't available on this server version
106+ try {
107+ recPlayer .playSound (recPlayer .getLocation (), Sound .BLOCK_NOTE_BLOCK_PLING , volume , pitch );
108+ } catch (Throwable ignored ) {
109+ // silently ignore if no sound is available
110+ }
111+ }
112+ } catch (Throwable ignored ) {
113+ // Ensure message sending never fails because of sound errors
114+ }
115+ });
116+
88117 if (sender .getUniqueId ().equals (console .getUniqueId ()) || (senderPlayer .isPresent () && !Message .hasChannel (senderPlayer .get (), recipient )))
89118 setReplyTo (sender , recipient );
90119 if (recipient .getUniqueId ().equals (console .getUniqueId ()) || (recipientPlayer .isPresent () && !Message .hasChannel (recipientPlayer .get (), sender )))
@@ -331,4 +360,4 @@ public static enum Context {
331360 */
332361 REPLY ;
333362 }
334- }
363+ }
0 commit comments