diff --git a/gradle.properties b/gradle.properties index e7ace85..f47e19d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ version_major=0 version_minor=0 -version_patch=18 +version_patch=19 shade_group=com.hypherionmc.sdlink.shaded. # Core Dependencies -jda=5.0.0-beta.12 +jda=5.0.0-beta.13 chewtils=2.0-SNAPSHOT webhooks=0.7.5 commons4=4.4 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 59080fc..7a70a45 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/accounts/MinecraftAccount.java +++ b/src/main/java/com/hypherionmc/sdlink/core/accounts/MinecraftAccount.java @@ -134,17 +134,13 @@ public class MinecraftAccount { String finalnickname = SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.nicknameFormat.replace("%nick%", nickname).replace("%mcname%", suffix); + if (finalnickname.length() > 32) { + finalnickname = finalnickname.substring(0, 28) + "..."; + } + if (SDLinkConfig.INSTANCE.whitelistingAndLinking.accountLinking.changeNickname && updateNick) { try { 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) { if (SDLinkConfig.INSTANCE.generalConfig.debugging) { e.printStackTrace(); @@ -152,6 +148,14 @@ public class MinecraftAccount { } } + try { + if (RoleManager.getLinkedRole() != null) { + guild.addRoleToMember(UserSnowflake.fromId(member.getId()), RoleManager.getLinkedRole()).queue(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return Result.success("Your Discord and MC accounts have been linked"); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/hypherionmc/sdlink/core/config/SDLinkConfig.java b/src/main/java/com/hypherionmc/sdlink/core/config/SDLinkConfig.java index 2578a30..93433c0 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/config/SDLinkConfig.java +++ b/src/main/java/com/hypherionmc/sdlink/core/config/SDLinkConfig.java @@ -24,7 +24,7 @@ public class SDLinkConfig extends ModuleConfig { // DO NOT REMOVE TRANSIENT HERE... OTHERWISE, THE STUPID CONFIG LIBRARY // WILL TRY TO WRITE THESE TO THE CONFIG public transient static SDLinkConfig INSTANCE; - public transient static int configVer = 9; + public transient static int configVer = 10; @Path("general") @SpecComment("General Mod Config") diff --git a/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChannelWebhookConfig.java b/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChannelWebhookConfig.java index 4214217..4ecf179 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChannelWebhookConfig.java +++ b/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChannelWebhookConfig.java @@ -39,7 +39,7 @@ public class ChannelWebhookConfig { public long eventsChannelID = 0; @Path("consoleChannelID") - @SpecComment("If this ID is set, console messages sent after the bot started will be relayed here, and you can execute minecraft commands here") + @SpecComment("If this ID is set, console messages sent after the bot started will be relayed here") public long consoleChannelID = 0; } @@ -53,11 +53,11 @@ public class ChannelWebhookConfig { public String chatWebhook = ""; @Path("eventsWebhook") - @SpecComment("The URL of the channel webhook to use for Server Messages Will be encrypted on first run") + @SpecComment("The URL of the channel webhook to use for Server Messages. Will be encrypted on first run") public String eventsWebhook = ""; @Path("consoleWebhook") - @SpecComment("The URL of the channel webhook to use for Console Messages Will be encrypted on first run") + @SpecComment("The URL of the channel webhook to use for Console Messages. DOES NOT WORK FOR CONSOLE RELAY! Will be encrypted on first run") public String consoleWebhook = ""; } diff --git a/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChatSettingsConfig.java b/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChatSettingsConfig.java index 3e99a2f..946c1a3 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChatSettingsConfig.java +++ b/src/main/java/com/hypherionmc/sdlink/core/config/impl/ChatSettingsConfig.java @@ -90,7 +90,7 @@ public class ChatSettingsConfig { public boolean broadcastCommands = true; @Path("ignoredCommands") - @SpecComment("Commands that should not be broadcasted to discord") + @SpecComment("Commands that should not be broadcast to discord") public List ignoredCommands = new ArrayList() {{ add("particle"); add("login"); add("execute"); }}; @Path("allowMentionsFromChat") 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 95992c5..9dcc5a7 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 @@ -56,7 +56,7 @@ public class LinkAndWhitelistConfigSettings { public boolean linkedWhitelist = false; @Path("autoWhitelist") - @SpecComment("Allow automatically whitelisting and de-whitelisting users with autoWhitelistRoles") + @SpecComment("Allow automatically whitelisting and de-whitelisting users with autoWhitelistRoles. WARNING: You cannot use the regular whitelist commands if this is enabled") public boolean autoWhitelist = false; @Path("autoWhitelistRoles") diff --git a/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/ConfirmWhitelistSlashCommand.java b/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/ConfirmWhitelistSlashCommand.java index a8780cd..7e26e80 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/ConfirmWhitelistSlashCommand.java +++ b/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/ConfirmWhitelistSlashCommand.java @@ -5,6 +5,7 @@ package com.hypherionmc.sdlink.core.discord.commands.slash.whitelist; import com.hypherionmc.sdlink.core.accounts.MinecraftAccount; +import com.hypherionmc.sdlink.core.config.SDLinkConfig; import com.hypherionmc.sdlink.core.database.SDLinkAccount; import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand; import com.hypherionmc.sdlink.core.messaging.Result; @@ -33,6 +34,11 @@ public class ConfirmWhitelistSlashCommand extends SDLinkSlashCommand { @Override protected void execute(SlashCommandEvent event) { + if (SDLinkConfig.INSTANCE.whitelistingAndLinking.whitelisting.autoWhitelist) { + event.reply("Sorry, but this server uses auto-whitelisting based on roles. This command cannot be used").setEphemeral(true).queue(); + return; + } + int mcCode = event.getOption("code") != null ? event.getOption("code").getAsInt() : 0; if (mcCode == 0) { diff --git a/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/UnWhitelistAccountSlashCommand.java b/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/UnWhitelistAccountSlashCommand.java index d84cb04..870e1e2 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/UnWhitelistAccountSlashCommand.java +++ b/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/UnWhitelistAccountSlashCommand.java @@ -5,6 +5,7 @@ package com.hypherionmc.sdlink.core.discord.commands.slash.whitelist; import com.hypherionmc.sdlink.core.accounts.MinecraftAccount; +import com.hypherionmc.sdlink.core.config.SDLinkConfig; import com.hypherionmc.sdlink.core.database.SDLinkAccount; import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand; import com.hypherionmc.sdlink.core.messaging.Result; @@ -29,6 +30,11 @@ public class UnWhitelistAccountSlashCommand extends SDLinkSlashCommand { @Override protected void execute(SlashCommandEvent event) { + if (SDLinkConfig.INSTANCE.whitelistingAndLinking.whitelisting.autoWhitelist) { + event.reply("Sorry, but this server uses auto-whitelisting based on roles. This command cannot be used").setEphemeral(true).queue(); + return; + } + sdlinkDatabase.reloadCollection("accounts"); List accounts = sdlinkDatabase.findAll(SDLinkAccount.class); diff --git a/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/WhitelistAccountCommand.java b/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/WhitelistAccountCommand.java index 13d4668..730b84b 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/WhitelistAccountCommand.java +++ b/src/main/java/com/hypherionmc/sdlink/core/discord/commands/slash/whitelist/WhitelistAccountCommand.java @@ -5,6 +5,7 @@ package com.hypherionmc.sdlink.core.discord.commands.slash.whitelist; import com.hypherionmc.sdlink.core.accounts.MinecraftAccount; +import com.hypherionmc.sdlink.core.config.SDLinkConfig; import com.hypherionmc.sdlink.core.database.SDLinkAccount; import com.hypherionmc.sdlink.core.discord.commands.slash.SDLinkSlashCommand; import com.hypherionmc.sdlink.core.services.SDLinkPlatform; @@ -37,6 +38,11 @@ public class WhitelistAccountCommand extends SDLinkSlashCommand { @Override protected void execute(SlashCommandEvent event) { + if (SDLinkConfig.INSTANCE.whitelistingAndLinking.whitelisting.autoWhitelist) { + event.reply("Sorry, but this server uses auto-whitelisting based on roles. This command cannot be used").setEphemeral(true).queue(); + return; + } + String mcName = event.getOption("mcname") != null ? event.getOption("mcname").getAsString() : ""; if (mcName.isEmpty()) { diff --git a/src/main/java/com/hypherionmc/sdlink/core/util/LogReader.java b/src/main/java/com/hypherionmc/sdlink/core/util/LogReader.java index 5af40a3..768ccb8 100644 --- a/src/main/java/com/hypherionmc/sdlink/core/util/LogReader.java +++ b/src/main/java/com/hypherionmc/sdlink/core/util/LogReader.java @@ -94,12 +94,12 @@ public class LogReader extends AbstractAppender { if (!BotController.INSTANCE.isBotReady()) return; if (System.currentTimeMillis() - time > 250) { + logs = logs.replaceAll("\\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\\b", "[REDACTED]"); + if (logs.length() > 2000) { logs = logs.substring(0, 1999); } - logs = logs.replaceAll("\\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\\b", "[REDACTED]"); - DiscordMessage discordMessage = new DiscordMessageBuilder(MessageType.CONSOLE) .message(logs) .author(DiscordAuthor.SERVER)