[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 {
|
try {
|
||||||
sdlinkDatabase.upsert(account);
|
sdlinkDatabase.upsert(account);
|
||||||
|
|
||||||
String suffix = " [MC: " + this.username + "]";
|
String suffix = this.username;
|
||||||
int availableChars = 32 - suffix.length();
|
int availableChars = 32 - suffix.length();
|
||||||
String nickname = member.getEffectiveName();
|
String nickname = member.getEffectiveName();
|
||||||
|
|
||||||
@@ -139,10 +139,11 @@ public class MinecraftAccount {
|
|||||||
nickname = nickname.substring(0, availableChars - 3) + "...";
|
nickname = nickname.substring(0, availableChars - 3) + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
nickname += suffix;
|
String finalnickname = SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.nicknameFormat.replace("%nick%", nickname).replace("%mcname%", suffix);
|
||||||
|
|
||||||
|
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) {
|
||||||
try {
|
try {
|
||||||
member.modifyNickname(nickname).queue();
|
member.modifyNickname(finalnickname).queue();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (RoleManager.getLinkedRole() != null) {
|
if (RoleManager.getLinkedRole() != null) {
|
||||||
@@ -156,6 +157,7 @@ public class MinecraftAccount {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Result.success("Your Discord and MC accounts have been linked");
|
return Result.success("Your Discord and MC accounts have been linked");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@@ -33,6 +33,14 @@ public class LinkAndWhitelistConfigSettings {
|
|||||||
@Path("requireLinking")
|
@Path("requireLinking")
|
||||||
@SpecComment("Require users to link their Discord and Minecraft accounts before joining the server")
|
@SpecComment("Require users to link their Discord and Minecraft accounts before joining the server")
|
||||||
public boolean requireLinking = false;
|
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 {
|
public static class Whitelisting {
|
||||||
|
@@ -28,7 +28,6 @@ public class PermissionChecker {
|
|||||||
// Base Permissions required by the bot to operate
|
// Base Permissions required by the bot to operate
|
||||||
private static final List<Permission> BOT_PERMS = new ArrayList<>() {{
|
private static final List<Permission> BOT_PERMS = new ArrayList<>() {{
|
||||||
add(Permission.NICKNAME_CHANGE);
|
add(Permission.NICKNAME_CHANGE);
|
||||||
add(Permission.NICKNAME_MANAGE);
|
|
||||||
add(Permission.MANAGE_WEBHOOKS);
|
add(Permission.MANAGE_WEBHOOKS);
|
||||||
add(Permission.MESSAGE_SEND);
|
add(Permission.MESSAGE_SEND);
|
||||||
add(Permission.MESSAGE_EMBED_LINKS);
|
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
|
* Run the permission checker to see if the bot has all the required permissions
|
||||||
*/
|
*/
|
||||||
public static void checkBotSetup() {
|
public static void checkBotSetup() {
|
||||||
|
if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname) {
|
||||||
|
BOT_PERMS.add(Permission.NICKNAME_MANAGE);
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("\r\n").append("******************* Simple Discord Link Errors *******************").append("\r\n");
|
builder.append("\r\n").append("******************* Simple Discord Link Errors *******************").append("\r\n");
|
||||||
AtomicInteger errCount = new AtomicInteger();
|
AtomicInteger errCount = new AtomicInteger();
|
||||||
|
Reference in New Issue
Block a user