diff --git a/src/main/java/com/hypherionmc/sdlink/core/accounts/MinecraftAccount.java b/src/main/java/com/hypherionmc/sdlink/core/accounts/MinecraftAccount.java index c940bcb..56b5a7e 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/accounts/MinecraftAccount.java +++ b/src/main/java/com/hypherionmc/sdlink/core/accounts/MinecraftAccount.java @@ -299,6 +299,14 @@ public class MinecraftAccount { if (account == null) return false; + User discordUser = getDiscordUser(); + + if (discordUser != null) { + Member m = BotController.INSTANCE.getJDA().getGuilds().get(0).getMemberById(discordUser.getId()); + if (m != null) + return m.getRoles().stream().anyMatch(r -> RoleManager.getAutoWhitelistRoles().contains(r)); + } + return !SDLinkPlatform.minecraftHelper.isPlayerWhitelisted(MinecraftAccount.standard(account.getUsername())).isError() && account.isWhitelisted(); } diff --git a/src/main/java/com/hypherionmc/sdlink/core/config/impl/LinkAndWhitelistConfigSettings.java b/src/main/java/com/hypherionmc/sdlink/core/config/impl/LinkAndWhitelistConfigSettings.java index 3ceefd5..b255186 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/config/impl/LinkAndWhitelistConfigSettings.java +++ b/src/main/java/com/hypherionmc/sdlink/core/config/impl/LinkAndWhitelistConfigSettings.java @@ -7,6 +7,9 @@ package com.hypherionmc.sdlink.core.config.impl; import me.hypherionmc.moonconfig.core.conversion.Path; import me.hypherionmc.moonconfig.core.conversion.SpecComment; +import java.util.ArrayList; +import java.util.List; + /** * @author HypherionSA * Config Structure to control Whitelisting and Account Linking @@ -52,6 +55,10 @@ public class LinkAndWhitelistConfigSettings { @SpecComment("Automatically link Minecraft and Discord Accounts when a user is whitelisted") public boolean linkedWhitelist = false; + @Path("autoWhitelistRoles") + @SpecComment("Users with linked discord accounts, that contain any of these roles will be automatically whitelisted") + public List autoWhitelistRoles = new ArrayList<>(); + @Path("autoWhitelistRole") @SpecComment("If a role ID (or name) is defined here, it will be assigned to players when they are whitelisted") public String autoWhitelistRole = ""; diff --git a/src/main/java/com/hypherionmc/sdlink/core/managers/RoleManager.java b/src/main/java/com/hypherionmc/sdlink/core/managers/RoleManager.java index f76c78b..d91262c 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/managers/RoleManager.java +++ b/src/main/java/com/hypherionmc/sdlink/core/managers/RoleManager.java @@ -10,7 +10,9 @@ import com.hypherionmc.sdlink.core.util.SystemUtils; import net.dv8tion.jda.api.entities.Role; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; /** @@ -22,6 +24,7 @@ public class RoleManager { private static Role whitelistedRole; private static Role linkedRole; private static final HashMap commandRoles = new HashMap<>(); + private static final Set autoWhitelistRoles = new HashSet<>(); /** * Check and load the roles required by the bot @@ -37,6 +40,15 @@ public class RoleManager { linkedRole = getRole(errCount, builder, "Linked Account", SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.linkedRole); } + if (SDLinkConfig.INSTANCE.whitelistingAndLinking.whitelisting.whitelisting) { + SDLinkConfig.INSTANCE.whitelistingAndLinking.whitelisting.autoWhitelistRoles.forEach(r -> { + Role role = getRole(errCount, builder, "Auto Whitelist Role", r); + + if (role != null) + autoWhitelistRoles.add(role); + }); + } + if (SDLinkConfig.INSTANCE.linkedCommands.enabled) { commandRoles.clear(); SDLinkConfig.INSTANCE.linkedCommands.commands.forEach(cmd -> { @@ -97,4 +109,8 @@ public class RoleManager { public static HashMap getCommandRoles() { return commandRoles; } + + public static Set getAutoWhitelistRoles() { + return autoWhitelistRoles; + } }