diff --git a/common/src/main/java/com/discordsrv/common/config/main/channels/JoinMessageConfig.java b/common/src/main/java/com/discordsrv/common/config/main/channels/JoinMessageConfig.java index b208294e..4b43fa31 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/channels/JoinMessageConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/channels/JoinMessageConfig.java @@ -21,10 +21,12 @@ package com.discordsrv.common.config.main.channels; import com.discordsrv.api.discord.entity.message.DiscordMessageEmbed; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; import com.discordsrv.api.event.events.message.receive.game.JoinMessageReceiveEvent; +import com.discordsrv.common.config.configurate.annotation.Constants; import com.discordsrv.common.config.configurate.annotation.Untranslated; import com.discordsrv.common.config.main.generic.IMessageConfig; import org.jetbrains.annotations.Nullable; import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Comment; @ConfigSerializable public class JoinMessageConfig implements IMessageConfig { @@ -40,6 +42,10 @@ public class JoinMessageConfig implements IMessageConfig { .build() ); + @Comment("If the \"%1\" permission should determine if join messages are sent") + @Constants.Comment("discordsrv.silentjoin") + public boolean enableSilentPermission = true; + @Override public boolean enabled() { return enabled; diff --git a/common/src/main/java/com/discordsrv/common/config/main/channels/LeaveMessageConfig.java b/common/src/main/java/com/discordsrv/common/config/main/channels/LeaveMessageConfig.java index d023d388..21d44fe7 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/channels/LeaveMessageConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/channels/LeaveMessageConfig.java @@ -20,9 +20,11 @@ package com.discordsrv.common.config.main.channels; import com.discordsrv.api.discord.entity.message.DiscordMessageEmbed; import com.discordsrv.api.discord.entity.message.SendableDiscordMessage; +import com.discordsrv.common.config.configurate.annotation.Constants; import com.discordsrv.common.config.configurate.annotation.Untranslated; import com.discordsrv.common.config.main.generic.IMessageConfig; import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Comment; @ConfigSerializable public class LeaveMessageConfig implements IMessageConfig { @@ -38,6 +40,10 @@ public class LeaveMessageConfig implements IMessageConfig { .build() ); + @Comment("If the \"%1\" permission should determine if leave messages are sent") + @Constants.Comment("discordsrv.silentquit") + public boolean enableSilentPermission = true; + @Override public boolean enabled() { return enabled; diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java index 2be90a5e..6d71d2de 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java @@ -90,7 +90,7 @@ public abstract class AbstractGameMessageModule CompletableFuture forwardToChannel( + protected CompletableFuture forwardToChannel( @Nullable E event, @Nullable IPlayer player, @NotNull BaseChannelConfig config diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/JoinMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/JoinMessageModule.java index e7d4c3b5..63769758 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/JoinMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/JoinMessageModule.java @@ -29,7 +29,13 @@ import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.config.main.generic.IMessageConfig; +import com.discordsrv.common.permission.Permission; +import com.discordsrv.common.player.IPlayer; import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.CompletableFuture; public class JoinMessageModule extends AbstractGameMessageModule { @@ -47,6 +53,19 @@ public class JoinMessageModule extends AbstractGameMessageModule forwardToChannel( + @Nullable JoinMessageReceiveEvent event, + @Nullable IPlayer player, + @NotNull BaseChannelConfig config + ) { + if (config.joinMessages().enableSilentPermission && player != null && player.hasPermission(Permission.SILENT_JOIN)) { + logger().info(player.username() + " is joining silently, join message will not be sent"); + return CompletableFuture.completedFuture(null); + } + return super.forwardToChannel(event, player, config); + } + @Override public IMessageConfig mapConfig(JoinMessageReceiveEvent event, BaseChannelConfig channelConfig) { return channelConfig.joinMessages().getForEvent(event); diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/LeaveMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/LeaveMessageModule.java index 8df1a3c3..091bda6a 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/LeaveMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/LeaveMessageModule.java @@ -29,7 +29,13 @@ import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.config.main.channels.LeaveMessageConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; +import com.discordsrv.common.permission.Permission; +import com.discordsrv.common.player.IPlayer; import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.CompletableFuture; public class LeaveMessageModule extends AbstractGameMessageModule { @@ -47,6 +53,19 @@ public class LeaveMessageModule extends AbstractGameMessageModule forwardToChannel( + @Nullable LeaveMessageReceiveEvent event, + @Nullable IPlayer player, + @NotNull BaseChannelConfig config + ) { + if (config.leaveMessages.enableSilentPermission && player != null && player.hasPermission(Permission.SILENT_QUIT)) { + logger().info(player.username() + " is leaving silently, leave message will not be sent"); + return CompletableFuture.completedFuture(null); + } + return super.forwardToChannel(event, player, config); + } + @Override public LeaveMessageConfig mapConfig(BaseChannelConfig channelConfig) { return channelConfig.leaveMessages; diff --git a/common/src/main/java/com/discordsrv/common/permission/Permission.java b/common/src/main/java/com/discordsrv/common/permission/Permission.java index 6c4724d1..6652b6a6 100644 --- a/common/src/main/java/com/discordsrv/common/permission/Permission.java +++ b/common/src/main/java/com/discordsrv/common/permission/Permission.java @@ -9,12 +9,12 @@ public enum Permission { COMMAND_BROADCAST("command.admin.broadcast"), COMMAND_RESYNC("command.admin.resync"), COMMAND_VERSION("command.admin.version"), + COMMAND_LINK_OTHER("command.admin.link.other"), + COMMAND_LINKED_OTHER("command.admin.linked.other"), // Player COMMAND_ROOT("command.player.root"), - COMMAND_LINK("command.player.link.base"), - COMMAND_LINK_OTHER("command.player.link.other"), - COMMAND_LINKED("command.player.linked.base"), - COMMAND_LINKED_OTHER("command.player.linked.other"), + COMMAND_LINK("command.player.link"), + COMMAND_LINKED("command.player.linked"), // Mentions MENTION_USER("mention.user.base"), @@ -25,6 +25,8 @@ public enum Permission { // Misc UPDATE_NOTIFICATION("updatenotification"), + SILENT_JOIN("silentjoin"), + SILENT_QUIT("silentquit"), ; private final String permission;