From 069ebfcd5b3e581f12e3511bdd83cb56e3d5a284 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sat, 6 May 2023 18:31:23 -0400 Subject: [PATCH] Fix NPE while syncing offline users for discord line module (#5338) Only would happen for users who haven't joined (or been loaded by different parts of the plugin) since the last restart. This change first of all switches to a method to fetch users which will update the User base to the UUIDPlayer dummy base. Secondly, this change will not update the base of a User to a UUIDPlayer dummy unless the base is currently null (which would be the case in the condition described above). --- .../src/main/java/com/earth2me/essentials/Essentials.java | 2 +- .../net/essentialsx/discordlink/rolesync/RoleSyncManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index 287446cd3..f2f1607bb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -1079,7 +1079,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { // Since we already call UserMap#getUser() above, we are already okay with adding the user to the cache, // so we need to manually add the user to the cache in order to avoid a memory leak and maintain behavior. userMap.addCachedUser(user); - } else { + } else if (base.getClass() != UUIDPlayer.class || user.getBase() == null) { user.update(base); } return user; diff --git a/EssentialsDiscordLink/src/main/java/net/essentialsx/discordlink/rolesync/RoleSyncManager.java b/EssentialsDiscordLink/src/main/java/net/essentialsx/discordlink/rolesync/RoleSyncManager.java index 820678754..aeaea4d3d 100644 --- a/EssentialsDiscordLink/src/main/java/net/essentialsx/discordlink/rolesync/RoleSyncManager.java +++ b/EssentialsDiscordLink/src/main/java/net/essentialsx/discordlink/rolesync/RoleSyncManager.java @@ -64,7 +64,7 @@ public class RoleSyncManager implements Listener { if (member == null) { if (ess.getSettings().isUnlinkOnLeave()) { - ess.getLinkManager().removeAccount(ess.getEss().getUser(player.getUniqueId()), DiscordLinkStatusChangeEvent.Cause.UNSYNC_LEAVE); + ess.getLinkManager().removeAccount(ess.getEss().getUser(player), DiscordLinkStatusChangeEvent.Cause.UNSYNC_LEAVE); } else { unSync(player.getUniqueId(), discordId); }