From 3e0487ba1fe6a276093051844c2bd9ff30264cb9 Mon Sep 17 00:00:00 2001 From: Draycia Date: Sun, 25 Jan 2026 23:47:46 -0800 Subject: [PATCH] Add ping permissions, play sounds on velocity --- .../carbon/common/command/commands/WhisperCommand.java | 8 ++++---- .../draycia/carbon/common/listeners/PartyPingHandler.java | 7 ++++++- .../net/draycia/carbon/common/listeners/PingHandler.java | 5 +++-- common/src/main/resources/carbon-permissions.yml | 5 ++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java index ed84296f..3e0a704c 100644 --- a/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java @@ -242,8 +242,8 @@ public final class WhisperCommand extends CarbonCommand { recipientUsername, recipientDisplayName, privateChatEvent.message()); final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound(); - if (localRecipient && messageSound != null) { - recipient.playSound(messageSound); + if (localRecipient && messageSound != null && recipient.hasPermission("carbon.whisper.ping_sounds")) { + recipient.playSound(messageSound, Sound.Emitter.self()); } sender.lastWhisperTarget(recipient.uuid()); @@ -289,8 +289,8 @@ public final class WhisperCommand extends CarbonCommand { WhisperCommand.broadcastWhisperSpy(this.server, this.messages, senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound(); - if (messageSound != null) { - recipient.playSound(messageSound); + if (messageSound != null && recipient.hasPermission("carbon.whisper.ping_sounds")) { + recipient.playSound(messageSound, Sound.Emitter.self()); } }).exceptionally(ex -> { this.logger.warn("Failed to handle whisper packet {}", packet, ex); diff --git a/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java b/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java index 0e2d7331..8faeff65 100644 --- a/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java +++ b/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java @@ -22,6 +22,7 @@ package net.draycia.carbon.common.listeners; import com.google.inject.Inject; import net.draycia.carbon.api.event.CarbonEventHandler; import net.draycia.carbon.api.event.events.CarbonChatEvent; +import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.common.channels.PartyChatChannel; import net.draycia.carbon.common.config.ConfigManager; import net.kyori.adventure.audience.Audience; @@ -50,7 +51,11 @@ public class PartyPingHandler implements Listener { continue; } - recipient.playSound(sound); + if (recipient instanceof CarbonPlayer player && !player.hasPermission("carbon.parties.ping_sound")) { + continue; + } + + recipient.playSound(sound, Sound.Emitter.self()); } } }); diff --git a/common/src/main/java/net/draycia/carbon/common/listeners/PingHandler.java b/common/src/main/java/net/draycia/carbon/common/listeners/PingHandler.java index 45b2481e..fb3e453f 100644 --- a/common/src/main/java/net/draycia/carbon/common/listeners/PingHandler.java +++ b/common/src/main/java/net/draycia/carbon/common/listeners/PingHandler.java @@ -28,6 +28,7 @@ import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.util.KeyedRenderer; import net.draycia.carbon.common.config.ConfigManager; import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -75,8 +76,8 @@ public class PingHandler implements Listener { Pattern.quote(plainDisplayName)), Pattern.CASE_INSENSITIVE)) .replacement(matchedText -> { - if (this.configManager.primaryConfig().pings().playSound()) { - recipient.playSound(this.configManager.primaryConfig().pings().sound()); + if (this.configManager.primaryConfig().pings().playSound() && recipient.hasPermission("carbon.ping_sounds")) { + recipient.playSound(this.configManager.primaryConfig().pings().sound(), Sound.Emitter.self()); } return Component.text(matchedText.content()).color(this.configManager.primaryConfig().pings().highlightTextColor()); diff --git a/common/src/main/resources/carbon-permissions.yml b/common/src/main/resources/carbon-permissions.yml index 7a54f81b..a5938b4d 100644 --- a/common/src/main/resources/carbon-permissions.yml +++ b/common/src/main/resources/carbon-permissions.yml @@ -13,6 +13,8 @@ carbon.ignore.unignore: "Removes the player from the sender's ignore list." carbon.itemlink: "Shows the player's held or equipped item in chat." carbon.crossserver: "Allows cross server messages to be received by the player." carbon.parties: "Allows the creation and use of chat parties." +carbon.parties.ping_sound: "Allows the ping sound to play when receiving party messages." +carbon.ping_sounds: "Allows the ping sound to play when receiving pings." carbon.mute: "Mutes the player, preventing them from sending messages or whispers." carbon.mute.exempt: "Prevents the player from being muted." carbon.mute.info: "Shows if the player is muted or now." @@ -27,6 +29,7 @@ carbon.whisper: "Sends private messages to other players." carbon.whisper.continue: "Sends a message to the last player you whispered." carbon.whisper.reply: "Sends a message to the last player who messaged you." carbon.whisper.vanished: "Allows the player to send messages to vanished players." +carbon.whisper.ping_sounds: "Allows the ping sound to play when receiving whispers." # Nickname tag permissions carbon.nickname.tags.color: "Allows the use of colors in nicknames." @@ -92,4 +95,4 @@ carbon.messagetags.reset: "Allows the use of the reset tag in messages." carbon.messagetags.newline: "Allows the use of the newline tag in messages." carbon.messagetags.pride: "Allows the use of the pride tag in messages." carbon.messagetags.shadow_color: "Allows the use of the shadow tag in messages." -carbon.messagetags.transition: "Allows the use of the transition tag in messages." \ No newline at end of file +carbon.messagetags.transition: "Allows the use of the transition tag in messages."