Skip to content

Commit

Permalink
Add silent quit & join permissions, make link(ed) other permissions a…
Browse files Browse the repository at this point in the history
…dmin
  • Loading branch information
Vankka committed Mar 2, 2024
1 parent d22d559 commit 46ac4be
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final CompletableFuture<?> process(
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
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> {

Expand All @@ -47,6 +53,19 @@ public void onJoinMessageReceive(JoinMessageReceiveEvent event) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
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> {

Expand All @@ -47,6 +53,19 @@ public void onLeaveMessageReceive(LeaveMessageReceiveEvent event) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -25,6 +25,8 @@ public enum Permission {

// Misc
UPDATE_NOTIFICATION("updatenotification"),
SILENT_JOIN("silentjoin"),
SILENT_QUIT("silentquit"),
;

private final String permission;
Expand Down

0 comments on commit 46ac4be

Please sign in to comment.