From 411d0c58e3faa3b3eef2661ec2b336fd2ec2ee10 Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Sun, 10 Nov 2024 12:18:08 +0100 Subject: [PATCH] Handle user in EntityBuilder#createApplicationEmoji as optional (#2769) --- .../net/dv8tion/jda/internal/JDAImpl.java | 22 ++++++++++++++----- .../jda/internal/entities/EntityBuilder.java | 6 ++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/dv8tion/jda/internal/JDAImpl.java b/src/main/java/net/dv8tion/jda/internal/JDAImpl.java index 9c1be36130..c03cf9f8f7 100644 --- a/src/main/java/net/dv8tion/jda/internal/JDAImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/JDAImpl.java @@ -693,7 +693,8 @@ public RestAction createApplicationEmoji(@Nonnull String name, return new RestActionImpl<>(this, route, body, (response, request) -> { final DataObject obj = response.getObject(); - return entityBuilder.createApplicationEmoji(this, obj); + final User selfUser = getSelfUser(); + return entityBuilder.createApplicationEmoji(this, obj, selfUser); }); } @@ -710,7 +711,12 @@ public RestAction> retrieveApplicationEmojis() { try { - list.add(entityBuilder.createApplicationEmoji(this, emojis.getObject(i))); + final DataObject emoji = emojis.getObject(i); + final User owner = emoji.optObject("user") + .map(entityBuilder::createUser) + .orElse(null); + + list.add(entityBuilder.createApplicationEmoji(this, emoji, owner)); } catch (ParsingException e) { @@ -728,9 +734,15 @@ public RestAction retrieveApplicationEmojiById(@Nonnull String { Checks.isSnowflake(emojiId); Route.CompiledRoute route = Route.Applications.GET_APPLICATION_EMOJI.compile(getSelfUser().getApplicationId(), emojiId); - return new RestActionImpl<>(this, route, - (response, request) -> entityBuilder.createApplicationEmoji(this, response.getObject()) - ); + return new RestActionImpl<>(this, route, (response, request) -> + { + final DataObject emoji = response.getObject(); + final User owner = emoji.optObject("user") + .map(entityBuilder::createUser) + .orElse(null); + + return entityBuilder.createApplicationEmoji(this, emoji, owner); + }); } @Nonnull diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index 7fb94a3abe..2f0cfd65a5 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1021,11 +1021,11 @@ public RichCustomEmojiImpl createEmoji(GuildImpl guildObj, DataObject json) .setAvailable(json.getBoolean("available", true)); } - public ApplicationEmojiImpl createApplicationEmoji(JDAImpl api, DataObject json) + public ApplicationEmojiImpl createApplicationEmoji(JDAImpl api, DataObject json, User owner) { final long emojiId = json.getUnsignedLong("id"); - final User user = createUser(json.getObject("user")); - return new ApplicationEmojiImpl(emojiId, api, user) + + return new ApplicationEmojiImpl(emojiId, api, owner) .setAnimated(json.getBoolean("animated")) .setName(json.getString("name")); }