Add silent quit & join permissions, make link(ed) other permissions admin

This commit is contained in:
Vankka 2024-03-02 17:46:30 +02:00
parent d22d55902d
commit 46ac4be92b
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
6 changed files with 57 additions and 5 deletions

View File

@ -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;

View File

@ -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;

View File

@ -90,7 +90,7 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
}
@SuppressWarnings("unchecked") // Wacky generis
private <CC extends BaseChannelConfig & IChannelConfig> CompletableFuture<Void> forwardToChannel(
protected <CC extends BaseChannelConfig & IChannelConfig> CompletableFuture<Void> forwardToChannel(
@Nullable E event,
@Nullable IPlayer player,
@NotNull BaseChannelConfig config

View File

@ -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<IMessageConfig, JoinMessageReceiveEvent> {
@ -47,6 +53,19 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
event.markAsProcessed();
}
@Override
protected CompletableFuture<Void> 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);

View File

@ -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<LeaveMessageConfig, LeaveMessageReceiveEvent> {
@ -47,6 +53,19 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
event.markAsProcessed();
}
@Override
protected CompletableFuture<Void> 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;

View File

@ -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;