[FEAT] Auto whitelisting based on account linking and roles
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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<String> 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 = "";
|
||||
|
@@ -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<String, Role> commandRoles = new HashMap<>();
|
||||
private static final Set<Role> 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<String, Role> getCommandRoles() {
|
||||
return commandRoles;
|
||||
}
|
||||
|
||||
public static Set<Role> getAutoWhitelistRoles() {
|
||||
return autoWhitelistRoles;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user