-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Discord Integration #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c5a6d1e
6307b0e
9e4a998
1109f11
67ac9a2
e98e263
8751030
031d466
fc95d79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.database.DatabaseManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.delivery.DeliveryManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.delivery.repository.DeliveryRepositoryOrmLite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.discord.DiscordClientManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.discord.command.DiscordLinkCommand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.discord.command.DiscordUnlinkCommand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.discord.repository.DiscordLinkRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.discord.repository.DiscordLinkRepositoryOrmLite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.gui.GuiManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.gui.implementation.locker.LockerGui; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.eternalcode.parcellockers.gui.implementation.remote.MainGui; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -72,6 +77,7 @@ public final class ParcelLockers extends JavaPlugin { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| private SkullAPI skullAPI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private DatabaseManager databaseManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private Economy economy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private DiscordClientManager discordClientManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void onEnable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -176,19 +182,51 @@ public void onEnable() { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| this.skullAPI | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.liteCommands = LiteBukkitFactory.builder(this.getName(), this) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var liteCommandsBuilder = LiteBukkitFactory.builder(this.getName(), this) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .extension(new LiteAdventureExtension<>()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .message(LiteBukkitMessages.PLAYER_ONLY, messageConfig.playerOnlyCommand) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .message(LiteBukkitMessages.PLAYER_NOT_FOUND, messageConfig.playerNotFound) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .commands(LiteCommandsAnnotations.of( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| new ParcelCommand(mainGUI), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| new ParcelLockersCommand(configService, config, noticeService), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| new DebugCommand(parcelService, lockerManager, itemStorageManager, parcelContentManager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| new DebugCommand( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| parcelService, lockerManager, itemStorageManager, parcelContentManager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| noticeService, deliveryManager) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .invalidUsage(new InvalidUsageHandlerImpl(noticeService)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .missingPermission(new MissingPermissionsHandlerImpl(noticeService)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .missingPermission(new MissingPermissionsHandlerImpl(noticeService)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| DiscordLinkRepository discordLinkRepository = new DiscordLinkRepositoryOrmLite(databaseManager, scheduler); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.discord.enabled) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.discord.botToken.isBlank() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| config.discord.serverId.isBlank() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| config.discord.channelId.isBlank() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| config.discord.botAdminRoleId.isBlank() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+202
to
+205
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.discord.botToken.isBlank() || | |
| config.discord.serverId.isBlank() || | |
| config.discord.channelId.isBlank() || | |
| config.discord.botAdminRoleId.isBlank() | |
| if (config.discord.botToken == null || config.discord.botToken.isBlank() || | |
| config.discord.serverId == null || config.discord.serverId.isBlank() || | |
| config.discord.channelId == null || config.discord.channelId.isBlank() || | |
| config.discord.botAdminRoleId == null || config.discord.botAdminRoleId.isBlank() |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Discord client is passed to DiscordLinkCommand via getClient() immediately after initialization, which may return null due to the asynchronous login in initialize(). This will cause a NullPointerException when the command is executed and tries to use the client.
| liteCommandsBuilder.commands( | |
| new DiscordLinkCommand( | |
| this.discordClientManager.getClient(), | |
| discordLinkRepository, | |
| noticeService, | |
| miniMessage, | |
| messageConfig), | |
| new DiscordUnlinkCommand(discordLinkRepository, noticeService) | |
| ); | |
| var discordClient = this.discordClientManager.getClient(); | |
| if (discordClient == null) { | |
| this.getLogger().severe("Failed to initialize Discord client. Discord commands will not be available."); | |
| } | |
| else { | |
| liteCommandsBuilder.commands( | |
| new DiscordLinkCommand( | |
| discordClient, | |
| discordLinkRepository, | |
| noticeService, | |
| miniMessage, | |
| messageConfig), | |
| new DiscordUnlinkCommand(discordLinkRepository, noticeService) | |
| ); | |
| } |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables 'metrics' and 'updaterService' are assigned but never used after initialization. These variables should either be removed if they're not needed, or stored as class fields if they need to be referenced later.
| Metrics metrics = new Metrics(this, 17677); | |
| UpdaterService updaterService = new UpdaterService(this.getPluginMeta().getVersion()); | |
| new Metrics(this, 17677); | |
| new UpdaterService(this.getPluginMeta().getVersion()); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,10 @@ public class MessageConfig extends OkaeriConfig { | |||||
| @Comment("# These messages are used for administrative actions such as deleting all lockers or parcels.") | ||||||
| public AdminMessages admin = new AdminMessages(); | ||||||
|
|
||||||
| @Comment({"", "# Messages related to Discord integration can be configured here." }) | ||||||
| @Comment("# These messages are used for linking Discord accounts with Minecraft accounts.") | ||||||
| public DiscordMessages discord = new DiscordMessages(); | ||||||
|
|
||||||
| public static class ParcelMessages extends OkaeriConfig { | ||||||
| public Notice sent = Notice.builder() | ||||||
| .chat("&2✔ &aParcel sent successfully.") | ||||||
|
|
@@ -178,4 +182,79 @@ public static class AdminMessages extends OkaeriConfig { | |||||
| public Notice deletedContents = Notice.chat("&4⚠ &cAll ({COUNT}) parcel contents have been deleted!"); | ||||||
| public Notice deletedDeliveries = Notice.chat("&4⚠ &cAll ({COUNT}) deliveries have been deleted!"); | ||||||
| } | ||||||
|
|
||||||
| public static class DiscordMessages extends OkaeriConfig { | ||||||
| public Notice verificationAlreadyPending = Notice.builder() | ||||||
| .chat("&4✘ &cYou already have a pending verification. Please complete it or wait for it to expire.") | ||||||
| .sound(SoundEventKeys.ENTITY_VILLAGER_NO) | ||||||
| .build(); | ||||||
| public Notice alreadyLinked = Notice.builder() | ||||||
| .chat("&4✘ &cYour Minecraft account is already linked to a Discord account!") | ||||||
| .sound(SoundEventKeys.ENTITY_VILLAGER_NO) | ||||||
| .build(); | ||||||
| public Notice discordAlreadyLinked = Notice.builder() | ||||||
| .chat("&4✘ &cThis Discord account is already linked to another Minecraft account!") | ||||||
| .sound(SoundEventKeys.ENTITY_VILLAGER_NO) | ||||||
| .build(); | ||||||
| public Notice userNotFound = Notice.builder() | ||||||
| .chat("&4✘ &cCould not find a Discord user with that ID!") | ||||||
| .sound(SoundEventKeys.ENTITY_VILLAGER_NO) | ||||||
| .build(); | ||||||
| public Notice verificationCodeSent = Notice.builder() | ||||||
| .chat("&2✔ &aA verification code has been sent to your Discord DM. Please check your messages.") | ||||||
| .sound(SoundEventKeys.ENTITY_EXPERIENCE_ORB_PICKUP) | ||||||
| .build(); | ||||||
| public Notice cannotSendDm = Notice.builder() | ||||||
| .chat("&4✘ &cCould not send a DM to your Discord account. Please make sure your DMs are open.") | ||||||
| .sound(SoundEventKeys.ENTITY_VILLAGER_NO) | ||||||
| .build(); | ||||||
| public Notice verificationExpired = Notice.builder() | ||||||
| .chat("&4✘ &cYour verification code has expired. Please run the command again.") | ||||||
| .sound(SoundEventKeys.ENTITY_VILLAGER_NO) | ||||||
| .build(); | ||||||
| public Notice invalidCode = Notice.builder() | ||||||
| .chat("&4✘ &cInvalid verification code. Please try again in 2 minutes.") | ||||||
|
||||||
| .chat("&4✘ &cInvalid verification code. Please try again in 2 minutes.") | |
| .chat("&4✘ &cInvalid verification code. Please run the command again to restart the verification process.") |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,9 @@ public class PluginConfig extends OkaeriConfig { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment({ "", "# The plugin GUI settings." }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public GuiSettings guiSettings = new GuiSettings(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment({ "", "# The plugin Discord integration settings." }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public DiscordSettings discord = new DiscordSettings(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static class Settings extends OkaeriConfig { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment("# Whether the player after entering the server should receive information about the new version of the plugin?") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -357,4 +360,22 @@ public static class GuiSettings extends OkaeriConfig { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment({ "", "# The lore line showing when the parcel has arrived. Placeholders: {DATE} - arrival date" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String parcelArrivedLine = "&aArrived on: &2{DATE}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static class DiscordSettings extends OkaeriConfig { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment("# Whether Discord integration is enabled.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean enabled = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment("# The Discord bot token.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String botToken = System.getenv("DISCORD_BOT_TOKEN"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment("# The Discord server ID.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String serverId = "1179117429301977251"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment("# The Discord channel ID for parcel notifications.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String channelId = "1317827115147853834"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Comment("# The Discord role ID for bot administrators.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String botAdminRoleId = "1317589501169893427"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+372
to
+379
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default values for
Suggested change
Comment on lines
+373
to
+379
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String serverId = "1179117429301977251"; | |
| @Comment("# The Discord channel ID for parcel notifications.") | |
| public String channelId = "1317827115147853834"; | |
| @Comment("# The Discord role ID for bot administrators.") | |
| public String botAdminRoleId = "1317589501169893427"; | |
| public String serverId = ""; | |
| @Comment("# The Discord channel ID for parcel notifications.") | |
| public String channelId = ""; | |
| @Comment("# The Discord role ID for bot administrators.") | |
| public String botAdminRoleId = ""; |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Discord-related configuration fields (serverId, channelId, botAdminRoleId) are defined but never used in the implementation. These fields suggest incomplete functionality - they appear to be for server notifications or admin role verification, but no code utilizes them. Consider either implementing the intended functionality or removing these unused configuration fields.
| @Comment("# The Discord server ID.") | |
| public String serverId = "1179117429301977251"; | |
| @Comment("# The Discord channel ID for parcel notifications.") | |
| public String channelId = "1317827115147853834"; | |
| @Comment("# The Discord role ID for bot administrators.") | |
| public String botAdminRoleId = "1317589501169893427"; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.eternalcode.parcellockers.discord; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import discord4j.core.DiscordClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import discord4j.core.GatewayDiscordClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.logging.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import reactor.core.scheduler.Schedulers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class DiscordClientManager { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final String token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final Logger logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private GatewayDiscordClient client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public DiscordClientManager(String token, Logger logger) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.token = token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.logger = logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void initialize() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.logger.info("Discord integration is enabled. Logging in to Discord..."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DiscordClient.create(this.token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .login() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .subscribeOn(Schedulers.boundedElastic()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .doOnSuccess(client -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.client = client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.logger.info("Successfully logged in to Discord."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .doOnError(error -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.logger.severe("Failed to log in to Discord: " + error.getMessage()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .subscribe(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+33
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DiscordClient.create(this.token) | |
| .login() | |
| .subscribeOn(Schedulers.boundedElastic()) | |
| .doOnSuccess(client -> { | |
| this.client = client; | |
| this.logger.info("Successfully logged in to Discord."); | |
| }) | |
| .doOnError(error -> { | |
| this.logger.severe("Failed to log in to Discord: " + error.getMessage()); | |
| error.printStackTrace(); | |
| }) | |
| .subscribe(); | |
| try { | |
| GatewayDiscordClient loggedInClient = DiscordClient.create(this.token) | |
| .login() | |
| .block(); | |
| if (loggedInClient == null) { | |
| this.logger.severe("Failed to log in to Discord: login returned null client."); | |
| throw new IllegalStateException("Discord login failed: client is null"); | |
| } | |
| this.client = loggedInClient; | |
| this.logger.info("Successfully logged in to Discord."); | |
| } catch (Exception error) { | |
| this.logger.severe("Failed to log in to Discord: " + error.getMessage()); | |
| error.printStackTrace(); | |
| throw new IllegalStateException("Discord login failed", error); | |
| } |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Discord client login is performed asynchronously in the initialize() method, but getClient() can be called immediately after, potentially returning null. This creates a race condition where commands or other components trying to use the client might receive null before the login completes. Consider blocking until the client is initialized or implementing a check mechanism to ensure the client is ready before use.
| DiscordClient.create(this.token) | |
| .login() | |
| .subscribeOn(Schedulers.boundedElastic()) | |
| .doOnSuccess(client -> { | |
| this.client = client; | |
| this.logger.info("Successfully logged in to Discord."); | |
| }) | |
| .doOnError(error -> { | |
| this.logger.severe("Failed to log in to Discord: " + error.getMessage()); | |
| error.printStackTrace(); | |
| }) | |
| .subscribe(); | |
| try { | |
| GatewayDiscordClient loggedInClient = DiscordClient.create(this.token) | |
| .login() | |
| .block(); | |
| if (loggedInClient != null) { | |
| this.client = loggedInClient; | |
| this.logger.info("Successfully logged in to Discord."); | |
| } else { | |
| this.logger.severe("Failed to log in to Discord: login returned null client."); | |
| } | |
| } catch (Exception error) { | |
| this.logger.severe("Failed to log in to Discord: " + error.getMessage()); | |
| error.printStackTrace(); | |
| } |
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.eternalcode.parcellockers.discord; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record DiscordLink(UUID minecraftUuid, String discordId) { | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||||||||
| package com.eternalcode.parcellockers.discord; | ||||||||||||||||
|
|
||||||||||||||||
| public enum DiscordNotificationType { | ||||||||||||||||
| SERVER, | ||||||||||||||||
| DM, | ||||||||||||||||
| BOTH | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+3
to
+7
|
||||||||||||||||
| public enum DiscordNotificationType { | |
| SERVER, | |
| DM, | |
| BOTH | |
| } | |
| // Previously contained the DiscordNotificationType enum, which was unused | |
| // and has been removed to eliminate dead code and placeholder functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DiscordLinkRepository is initialized on line 199 even when Discord integration is disabled (config.discord.enabled = false). This creates an unnecessary database table and wastes resources. The repository should only be initialized when Discord integration is enabled.