diff --git a/pom.xml b/pom.xml
index ad37d97..d0c60fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.rezzedup
discordsrv-staff-chat
- 1.4.6
+ 1.4.5
DiscordSRV-Staff-Chat
2017
diff --git a/src/main/java/com/rezzedup/discordsrv/staffchat/Data.java b/src/main/java/com/rezzedup/discordsrv/staffchat/Data.java
index 7e553b1..7f8d5ff 100644
--- a/src/main/java/com/rezzedup/discordsrv/staffchat/Data.java
+++ b/src/main/java/com/rezzedup/discordsrv/staffchat/Data.java
@@ -138,12 +138,15 @@ static class Profile implements StaffChatProfile
static final YamlValue LEFT_TOGGLE_DATE = YamlValue.ofInstant("toggles.left").maybe();
+ static final YamlValue MUTED_SOUNDS_TOGGLE = YamlValue.ofBoolean("toggles.muted-sounds").maybe();
+
private final StaffChatPlugin plugin;
private final YamlDataFile yaml;
private final UUID uuid;
private @NullOr Instant auto;
private @NullOr Instant left;
+ private boolean mutedSounds = false;
Profile(StaffChatPlugin plugin, YamlDataFile yaml, UUID uuid)
{
@@ -153,9 +156,11 @@ static class Profile implements StaffChatProfile
if (plugin.config().getOrDefault(StaffChatConfig.PERSIST_TOGGLES))
{
- Sections.get(yaml.data(), path()).ifPresent(section -> {
+ Sections.get(yaml.data(), path()).ifPresent(section ->
+ {
auto = AUTO_TOGGLE_DATE.get(section).orElse(null);
left = LEFT_TOGGLE_DATE.get(section).orElse(null);
+ mutedSounds = MUTED_SOUNDS_TOGGLE.get(section).orElse(false);
});
}
}
@@ -211,9 +216,21 @@ public void receivesStaffChatMessages(boolean enabled)
updateStoredProfileData();
}
+ @Override
+ public boolean receivesStaffChatSounds()
+ {
+ return !mutedSounds;
+ }
+
+ @Override
+ public void receivesStaffChatSounds(boolean enabled)
+ {
+ mutedSounds = !enabled;
+ }
+
boolean hasDefaultSettings()
{
- return auto == null && left == null;
+ return auto == null && left == null && !mutedSounds;
}
void clearStoredProfileData()
@@ -238,6 +255,7 @@ void updateStoredProfileData()
AUTO_TOGGLE_DATE.set(section, auto);
LEFT_TOGGLE_DATE.set(section, left);
+ MUTED_SOUNDS_TOGGLE.set(section, mutedSounds);
yaml.updated(true);
}
diff --git a/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatPlugin.java b/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatPlugin.java
index a7aa7f7..33aeb11 100644
--- a/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatPlugin.java
+++ b/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatPlugin.java
@@ -26,6 +26,7 @@
import com.rezzedup.discordsrv.staffchat.commands.ManageStaffChatCommand;
import com.rezzedup.discordsrv.staffchat.commands.StaffChatCommand;
import com.rezzedup.discordsrv.staffchat.commands.ToggleStaffChatCommand;
+import com.rezzedup.discordsrv.staffchat.commands.ToggleStaffChatSoundsCommand;
import com.rezzedup.discordsrv.staffchat.config.MessagesConfig;
import com.rezzedup.discordsrv.staffchat.config.StaffChatConfig;
import com.rezzedup.discordsrv.staffchat.listeners.DiscordSrvLoadedLaterListener;
@@ -102,10 +103,12 @@ public void onEnable()
events().register(new PlayerPrefixedMessageListener(this));
events().register(new PlayerStaffChatToggleListener(this));
- ToggleStaffChatCommand toggle = new ToggleStaffChatCommand(this);
command("staffchat", new StaffChatCommand(this));
command("managestaffchat", new ManageStaffChatCommand(this));
+ command("togglestaffchatsounds", new ToggleStaffChatSoundsCommand(this));
+
+ ToggleStaffChatCommand toggle = new ToggleStaffChatCommand(this);
command("leavestaffchat", toggle);
command("joinstaffchat", toggle);
diff --git a/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatProfile.java b/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatProfile.java
index be2a4d0..126d6a8 100644
--- a/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatProfile.java
+++ b/src/main/java/com/rezzedup/discordsrv/staffchat/StaffChatProfile.java
@@ -45,6 +45,10 @@ public interface StaffChatProfile
void receivesStaffChatMessages(boolean enabled);
+ boolean receivesStaffChatSounds();
+
+ void receivesStaffChatSounds(boolean enabled);
+
default void toggleAutomaticStaffChat()
{
automaticStaffChat(!automaticStaffChat());
diff --git a/src/main/java/com/rezzedup/discordsrv/staffchat/commands/ToggleStaffChatSoundsCommand.java b/src/main/java/com/rezzedup/discordsrv/staffchat/commands/ToggleStaffChatSoundsCommand.java
new file mode 100644
index 0000000..50f67fe
--- /dev/null
+++ b/src/main/java/com/rezzedup/discordsrv/staffchat/commands/ToggleStaffChatSoundsCommand.java
@@ -0,0 +1,67 @@
+/*
+ * The MIT License
+ * Copyright © 2017-2024 RezzedUp and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.rezzedup.discordsrv.staffchat.commands;
+
+import com.rezzedup.discordsrv.staffchat.StaffChatPlugin;
+import com.rezzedup.discordsrv.staffchat.StaffChatProfile;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public class ToggleStaffChatSoundsCommand implements CommandExecutor
+{
+ private final StaffChatPlugin plugin;
+
+ public ToggleStaffChatSoundsCommand(StaffChatPlugin plugin)
+ {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
+ {
+ if (sender instanceof Player)
+ {
+ Player player = (Player) sender;
+ StaffChatProfile profile = plugin.data().getOrCreateProfile(player);
+ boolean toggle = !profile.receivesStaffChatSounds();
+ profile.receivesStaffChatSounds(toggle);
+
+ plugin.debug(getClass()).log(() -> String.format(
+ "Player: %s (%s) has %s receiving staff chat sounds",
+ player.getName(), profile.uuid(), ((toggle) ? "enabled (unmuted)" : "disabled (muted)")
+ ));
+
+ if (toggle) { plugin.messages().notifySoundsUnmuted(player); }
+ else { plugin.messages().notifySoundsMuted(player); }
+ }
+ else
+ {
+ sender.sendMessage("Only players may run this command.");
+ }
+
+ return true;
+ }
+}
diff --git a/src/main/java/com/rezzedup/discordsrv/staffchat/config/MessagesConfig.java b/src/main/java/com/rezzedup/discordsrv/staffchat/config/MessagesConfig.java
index b2eecd8..b3a5ddf 100644
--- a/src/main/java/com/rezzedup/discordsrv/staffchat/config/MessagesConfig.java
+++ b/src/main/java/com/rezzedup/discordsrv/staffchat/config/MessagesConfig.java
@@ -116,6 +116,18 @@ public class MessagesConfig extends YamlDataFile
YamlValue.ofString("notifications.join.others")
.defaults("%prefix% &2→&a %player% &njoined&a the staff chat");
+ public static final DefaultYamlValue MUTE_SOUNDS_NOTIFICATION =
+ YamlValue.ofString("notifications.sounds.muted")
+ .defaults(
+ "%prefix% &4→&c You have &nmuted&c staff chat sounds"
+ );
+
+ public static final DefaultYamlValue UNMUTE_SOUNDS_NOTIFICATION =
+ YamlValue.ofString("notifications.sounds.unmuted")
+ .defaults(
+ "%prefix% &2→&a You have &nunmuted&a staff chat sounds"
+ );
+
@AggregatedResult
public static final List> VALUES =
Aggregates.fromThisClass().constantsOfType(YamlValue.type()).toList();
@@ -247,6 +259,16 @@ public void notifyJoinChat(Player joiner, boolean notifyOthers)
sendNotification(joiner, JOIN_CHAT_NOTIFICATION_SELF, others);
}
+ public void notifySoundsMuted(Player player)
+ {
+ sendNotification(player, MUTE_SOUNDS_NOTIFICATION, null);
+ }
+
+ public void notifySoundsUnmuted(Player player)
+ {
+ sendNotification(player, UNMUTE_SOUNDS_NOTIFICATION, null);
+ }
+
//
// Unconfigurable notifications
//
diff --git a/src/main/java/com/rezzedup/discordsrv/staffchat/config/StaffChatConfig.java b/src/main/java/com/rezzedup/discordsrv/staffchat/config/StaffChatConfig.java
index b295ce5..6f32039 100644
--- a/src/main/java/com/rezzedup/discordsrv/staffchat/config/StaffChatConfig.java
+++ b/src/main/java/com/rezzedup/discordsrv/staffchat/config/StaffChatConfig.java
@@ -24,6 +24,7 @@
import com.github.zafarkhaja.semver.Version;
import com.rezzedup.discordsrv.staffchat.StaffChatPlugin;
+import com.rezzedup.discordsrv.staffchat.StaffChatProfile;
import com.rezzedup.util.constants.Aggregates;
import com.rezzedup.util.constants.annotations.AggregatedResult;
import community.leaf.configvalues.bukkit.DefaultYamlValue;
@@ -105,9 +106,12 @@ public class StaffChatConfig extends YamlDataFile
public static final List> VALUES =
Aggregates.fromThisClass().constantsOfType(YamlValue.type()).toList();
+ private final StaffChatPlugin plugin;
+
public StaffChatConfig(StaffChatPlugin plugin)
{
super(plugin.directory(), "staff-chat.config.yml", Load.LATER);
+ this.plugin = plugin;
reloadsWith(() ->
{
@@ -119,7 +123,7 @@ public StaffChatConfig(StaffChatPlugin plugin)
}
Version existing = get(VERSION).orElse(Configs.NO_VERSION);
- boolean isOutdated = existing.lessThan(plugin.version());
+ boolean isOutdated = existing.isLowerThan(plugin.version());
if (isOutdated)
{
@@ -148,12 +152,19 @@ private void playSound(
{
if (!getOrDefault(enabled)) { return; }
- player.playSound(
- player.getLocation().add(0, 0.5, 0),
- getOrDefault(sound),
- getOrDefault(volume),
- getOrDefault(pitch)
- );
+ boolean sounds = plugin.data().getProfile(player)
+ .map(StaffChatProfile::receivesStaffChatSounds)
+ .orElse(true);
+
+ if (sounds)
+ {
+ player.playSound(
+ player.getLocation().add(0, 0.5, 0),
+ getOrDefault(sound),
+ getOrDefault(volume),
+ getOrDefault(pitch)
+ );
+ }
}
public void playMessageSound(Player player)
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 3259041..895d7aa 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,9 @@
name: ${project.name}
version: ${project.version}
+
author: RezzedUp
+description: Staff chat plugin that hooks into DiscordSRV.
+website: https://modrinth.com/plugin/discordsrv-staff-chat
main: com.rezzedup.discordsrv.staffchat.StaffChatPlugin
api-version: 1.13
@@ -15,6 +18,11 @@ commands:
usage: |-
/ - toggle automatic staff chat
/ - send a message to the staff chat
+ managestaffchat:
+ aliases: [ discordsrv-staff-chat, discordsrvstaffchat, discordstaffchat, discordadminchat, manageadminchat ]
+ description: Manage and get information about DiscordSRV-Staff-Chat
+ permission: staffchat.manage
+ usage: /
leavestaffchat:
aliases: [leaveadminchat]
description: Leave the staff chat (stop receiving messages).
@@ -25,10 +33,10 @@ commands:
description: Rejoin the staff chat (receive messages again).
permission: staffchat.access
usage: /
- managestaffchat:
- aliases: [discordsrv-staff-chat, discordsrvstaffchat, discordstaffchat, discordadminchat, manageadminchat]
- description: Manage and get information about DiscordSRV-Staff-Chat
- permission: staffchat.manage
+ togglestaffchatsounds:
+ aliases: [toggleadminchatsounds]
+ description: Mute or unmute staff chat sounds for yourself.
+ permission: staffchat.access
usage: /
permissions:
diff --git a/src/main/resources/staff-chat.config.header.txt b/src/main/resources/staff-chat.config.header.txt
index c90a50c..0682fc2 100644
--- a/src/main/resources/staff-chat.config.header.txt
+++ b/src/main/resources/staff-chat.config.header.txt
@@ -11,7 +11,7 @@
Installation (Discord Setup):
- 1) Install this plugin and DiscordSRV
- Get DiscordSRV here: https://www.spigotmc.org/resources/discordsrv.18494/
+ Get DiscordSRV here: https://modrinth.com/plugin/discordsrv
- 2) Add a "staff-chat" channel to DiscordSRV's config
(in: /plugins/DiscordSRV/config.yml)
@@ -35,8 +35,8 @@
---
- This config can be reloaded in-game with: '/managestaffchat reload'
- (Be sure to give yourself permission to manage the staff chat with: 'staffchat.manage')
+ This config can be reloaded in-game with: `/managestaffchat reload`
+ (Be sure to give yourself permission to manage the staff chat with: `staffchat.manage`)
---