mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-31 18:07:56 +01:00
Add silent quit & join permissions, make link(ed) other permissions admin
This commit is contained in:
parent
d22d55902d
commit
46ac4be92b
@ -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.DiscordMessageEmbed;
|
||||||
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
|
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
|
||||||
import com.discordsrv.api.event.events.message.receive.game.JoinMessageReceiveEvent;
|
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.configurate.annotation.Untranslated;
|
||||||
import com.discordsrv.common.config.main.generic.IMessageConfig;
|
import com.discordsrv.common.config.main.generic.IMessageConfig;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class JoinMessageConfig implements IMessageConfig {
|
public class JoinMessageConfig implements IMessageConfig {
|
||||||
@ -40,6 +42,10 @@ public class JoinMessageConfig implements IMessageConfig {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Comment("If the \"%1\" permission should determine if join messages are sent")
|
||||||
|
@Constants.Comment("discordsrv.silentjoin")
|
||||||
|
public boolean enableSilentPermission = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enabled() {
|
public boolean enabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
|
@ -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.DiscordMessageEmbed;
|
||||||
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
|
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.configurate.annotation.Untranslated;
|
||||||
import com.discordsrv.common.config.main.generic.IMessageConfig;
|
import com.discordsrv.common.config.main.generic.IMessageConfig;
|
||||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class LeaveMessageConfig implements IMessageConfig {
|
public class LeaveMessageConfig implements IMessageConfig {
|
||||||
@ -38,6 +40,10 @@ public class LeaveMessageConfig implements IMessageConfig {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Comment("If the \"%1\" permission should determine if leave messages are sent")
|
||||||
|
@Constants.Comment("discordsrv.silentquit")
|
||||||
|
public boolean enableSilentPermission = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enabled() {
|
public boolean enabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
|
@ -90,7 +90,7 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") // Wacky generis
|
@SuppressWarnings("unchecked") // Wacky generis
|
||||||
private <CC extends BaseChannelConfig & IChannelConfig> CompletableFuture<Void> forwardToChannel(
|
protected <CC extends BaseChannelConfig & IChannelConfig> CompletableFuture<Void> forwardToChannel(
|
||||||
@Nullable E event,
|
@Nullable E event,
|
||||||
@Nullable IPlayer player,
|
@Nullable IPlayer player,
|
||||||
@NotNull BaseChannelConfig config
|
@NotNull BaseChannelConfig config
|
||||||
|
@ -29,7 +29,13 @@ import com.discordsrv.common.DiscordSRV;
|
|||||||
import com.discordsrv.common.component.util.ComponentUtil;
|
import com.discordsrv.common.component.util.ComponentUtil;
|
||||||
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
|
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
|
||||||
import com.discordsrv.common.config.main.generic.IMessageConfig;
|
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 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> {
|
public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig, JoinMessageReceiveEvent> {
|
||||||
|
|
||||||
@ -47,6 +53,19 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
|
|||||||
event.markAsProcessed();
|
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
|
@Override
|
||||||
public IMessageConfig mapConfig(JoinMessageReceiveEvent event, BaseChannelConfig channelConfig) {
|
public IMessageConfig mapConfig(JoinMessageReceiveEvent event, BaseChannelConfig channelConfig) {
|
||||||
return channelConfig.joinMessages().getForEvent(event);
|
return channelConfig.joinMessages().getForEvent(event);
|
||||||
|
@ -29,7 +29,13 @@ import com.discordsrv.common.DiscordSRV;
|
|||||||
import com.discordsrv.common.component.util.ComponentUtil;
|
import com.discordsrv.common.component.util.ComponentUtil;
|
||||||
import com.discordsrv.common.config.main.channels.LeaveMessageConfig;
|
import com.discordsrv.common.config.main.channels.LeaveMessageConfig;
|
||||||
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
|
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 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> {
|
public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageConfig, LeaveMessageReceiveEvent> {
|
||||||
|
|
||||||
@ -47,6 +53,19 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
|
|||||||
event.markAsProcessed();
|
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
|
@Override
|
||||||
public LeaveMessageConfig mapConfig(BaseChannelConfig channelConfig) {
|
public LeaveMessageConfig mapConfig(BaseChannelConfig channelConfig) {
|
||||||
return channelConfig.leaveMessages;
|
return channelConfig.leaveMessages;
|
||||||
|
@ -9,12 +9,12 @@ public enum Permission {
|
|||||||
COMMAND_BROADCAST("command.admin.broadcast"),
|
COMMAND_BROADCAST("command.admin.broadcast"),
|
||||||
COMMAND_RESYNC("command.admin.resync"),
|
COMMAND_RESYNC("command.admin.resync"),
|
||||||
COMMAND_VERSION("command.admin.version"),
|
COMMAND_VERSION("command.admin.version"),
|
||||||
|
COMMAND_LINK_OTHER("command.admin.link.other"),
|
||||||
|
COMMAND_LINKED_OTHER("command.admin.linked.other"),
|
||||||
// Player
|
// Player
|
||||||
COMMAND_ROOT("command.player.root"),
|
COMMAND_ROOT("command.player.root"),
|
||||||
COMMAND_LINK("command.player.link.base"),
|
COMMAND_LINK("command.player.link"),
|
||||||
COMMAND_LINK_OTHER("command.player.link.other"),
|
COMMAND_LINKED("command.player.linked"),
|
||||||
COMMAND_LINKED("command.player.linked.base"),
|
|
||||||
COMMAND_LINKED_OTHER("command.player.linked.other"),
|
|
||||||
|
|
||||||
// Mentions
|
// Mentions
|
||||||
MENTION_USER("mention.user.base"),
|
MENTION_USER("mention.user.base"),
|
||||||
@ -25,6 +25,8 @@ public enum Permission {
|
|||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
UPDATE_NOTIFICATION("updatenotification"),
|
UPDATE_NOTIFICATION("updatenotification"),
|
||||||
|
SILENT_JOIN("silentjoin"),
|
||||||
|
SILENT_QUIT("silentquit"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String permission;
|
private final String permission;
|
||||||
|
Loading…
Reference in New Issue
Block a user