[FEAT] Allow disabling nickname updates on linking and allow custom nickname formats
This commit is contained in:
@@ -131,7 +131,7 @@ public class MinecraftAccount {
|
||||
try {
|
||||
sdlinkDatabase.upsert(account);
|
||||
|
||||
String suffix = " [MC: " + this.username + "]";
|
||||
String suffix = this.username;
|
||||
int availableChars = 32 - suffix.length();
|
||||
String nickname = member.getEffectiveName();
|
||||
|
||||
@@ -139,21 +139,23 @@ public class MinecraftAccount {
|
||||
nickname = nickname.substring(0, availableChars - 3) + "...";
|
||||
}
|
||||
|
||||
nickname += suffix;
|
||||
|
||||
try {
|
||||
member.modifyNickname(nickname).queue();
|
||||
String finalnickname = SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.nicknameFormat.replace("%nick%", nickname).replace("%mcname%", suffix);
|
||||
|
||||
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) {
|
||||
try {
|
||||
if (RoleManager.getLinkedRole() != null) {
|
||||
guild.addRoleToMember(UserSnowflake.fromId(member.getId()), RoleManager.getLinkedRole()).queue();
|
||||
member.modifyNickname(finalnickname).queue();
|
||||
|
||||
try {
|
||||
if (RoleManager.getLinkedRole() != null) {
|
||||
guild.addRoleToMember(UserSnowflake.fromId(member.getId()), RoleManager.getLinkedRole()).queue();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (SDLinkConfig.INSTANCE.generalConfig.debugging) {
|
||||
e.printStackTrace();
|
||||
if (SDLinkConfig.INSTANCE.generalConfig.debugging) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,14 @@ public class LinkAndWhitelistConfigSettings {
|
||||
@Path("requireLinking")
|
||||
@SpecComment("Require users to link their Discord and Minecraft accounts before joining the server")
|
||||
public boolean requireLinking = false;
|
||||
|
||||
@Path("changeNickname")
|
||||
@SpecComment("Allow nickname changes on account linking")
|
||||
public boolean changeNickname = true;
|
||||
|
||||
@Path("nicknameFormat")
|
||||
@SpecComment("The nickname format to use for linked accounts, when changeNickname is enabled. %nick% for current nickname/name and %mcname% for the minecraft name")
|
||||
public String nicknameFormat = "%nick% [MC:%mcname%]";
|
||||
}
|
||||
|
||||
public static class Whitelisting {
|
||||
|
@@ -28,7 +28,6 @@ public class PermissionChecker {
|
||||
// Base Permissions required by the bot to operate
|
||||
private static final List<Permission> BOT_PERMS = new ArrayList<>() {{
|
||||
add(Permission.NICKNAME_CHANGE);
|
||||
add(Permission.NICKNAME_MANAGE);
|
||||
add(Permission.MANAGE_WEBHOOKS);
|
||||
add(Permission.MESSAGE_SEND);
|
||||
add(Permission.MESSAGE_EMBED_LINKS);
|
||||
@@ -50,6 +49,10 @@ public class PermissionChecker {
|
||||
* Run the permission checker to see if the bot has all the required permissions
|
||||
*/
|
||||
public static void checkBotSetup() {
|
||||
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) {
|
||||
BOT_PERMS.add(Permission.NICKNAME_MANAGE);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("\r\n").append("******************* Simple Discord Link Errors *******************").append("\r\n");
|
||||
AtomicInteger errCount = new AtomicInteger();
|
||||
|
Reference in New Issue
Block a user