From bd9ac1e138b997f21813a59e10eae6e75e45dac4 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 3 Jul 2024 23:23:23 +0100 Subject: [PATCH] maybe fix npe?? --- .../java/cc/fascinated/bat/model/BatGuild.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/bat/model/BatGuild.java b/src/main/java/cc/fascinated/bat/model/BatGuild.java index fb40213..8b886a5 100644 --- a/src/main/java/cc/fascinated/bat/model/BatGuild.java +++ b/src/main/java/cc/fascinated/bat/model/BatGuild.java @@ -49,11 +49,21 @@ public class BatGuild extends ProfileHolder { */ private Date createdAt; + /** + * The guild as the JDA Guild + */ + private Guild guild; + public BatGuild(@NonNull String id, @NonNull org.bson.Document document) { this.id = id; this.document = document; boolean newAccount = this.document.isEmpty(); this.createdAt = newAccount ? new Date() : document.getDate("createdAt"); + + Guild guild = DiscordService.JDA.getGuildById(id); + if (guild != null) { + this.guild = guild; + } } /** @@ -71,7 +81,10 @@ public class BatGuild extends ProfileHolder { * @return the guild */ public Guild getDiscordGuild() { - return DiscordService.JDA.getGuildById(id); + if (guild == null) { + guild = DiscordService.JDA.getGuildById(id); + } + return guild; } /**