-
Notifications
You must be signed in to change notification settings - Fork 2
Implemented notification sound for incoming messages #71
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+104
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to log and do nothing, so e.g. something like
Suggested change
|
||||||||||||||||||||||||
| } catch (Throwable ignored) { | ||||||||||||||||||||||||
| // Ensure message sending never fails because of sound errors | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+112
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This try/catch should not be needed as it would only cover the config access |
||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
-334
to
+363
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The empty line at the end of the file should not be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sorry but, I don't see any empty lines there
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,3 +152,15 @@ errors: | |
|
|
||
| # Trying to message a team, but not in one | ||
| not-in-team: "<red>(!) You are not in a team.</red>" | ||
|
|
||
|
|
||
| pm-sound: | ||
|
Comment on lines
+155
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there should also be a way to do this for team messages, and make the config like. sound:
private:
# …
team:
# …Also I think it would be best to move this above the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, sounds reasonable, my personal intention was just to notify players about pm notification only since team message can be more spammy sometimes, but still yeah config might be a better choice for server owners to pick |
||
| # 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 | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the
pro.cloudnode.smp.cloudnodemsg.PluginConfigclass for accessing the configThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sure, my bad didn't noticed it