diff --git a/src/main/java/net/dv8tion/jda/api/entities/MessageSticker.java b/src/main/java/net/dv8tion/jda/api/entities/MessageSticker.java index 9d6276c63e..6db24e67e8 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/MessageSticker.java +++ b/src/main/java/net/dv8tion/jda/api/entities/MessageSticker.java @@ -15,6 +15,11 @@ */ package net.dv8tion.jda.api.entities; +import net.dv8tion.jda.annotations.DeprecatedSince; +import net.dv8tion.jda.annotations.ForRemoval; +import net.dv8tion.jda.annotations.ReplaceWith; +import net.dv8tion.jda.internal.utils.Helpers; + import javax.annotation.Nonnull; import java.util.Set; @@ -30,21 +35,29 @@ public class MessageSticker implements ISnowflake private final String description; private final long packId; private final String asset; - private final String previewAsset; private final StickerFormat formatType; private final Set tags; - /** Template for {@link #getAssetUrl()} */ + /** + * Template for {@link #getAssetUrl()} + * + * @deprecated Use {@link #ICON_URL} instead + */ + @Deprecated + @ForRemoval + @ReplaceWith("ICON_URL") + @DeprecatedSince("4.3.1") public static final String ASSET_URL = "https://cdn.discordapp.com/stickers/%s/%s.%s"; + /** Template for {@link #getIconUrl()} */ + public static final String ICON_URL = "https://cdn.discordapp.com/stickers/%s.%s"; - public MessageSticker(final long id, final String name, final String description, final long packId, final String asset, final String previewAsset, final StickerFormat formatType, final Set tags) + public MessageSticker(final long id, final String name, final String description, final long packId, final String asset, final StickerFormat formatType, final Set tags) { this.id = id; this.name = name; this.description = description; this.packId = packId; this.asset = asset; - this.previewAsset = previewAsset; this.formatType = formatType; this.tags = tags; } @@ -80,6 +93,8 @@ public String getDescription() /** * The ID of the pack the sticker is from. * + *

If this sticker is from a guild, this will be the guild id instead. + * * @return the ID of the pack the sticker is from */ @Nonnull @@ -91,6 +106,8 @@ public String getPackId() /** * The ID of the pack the sticker is from. * + *

If this sticker is from a guild, this will be the guild id instead. + * * @return the ID of the pack the sticker is from */ public long getPackIdLong() @@ -103,8 +120,14 @@ public long getPackIdLong() *
The URL for fetching sticker assets is currently private. * * @return the Discord hash-id of the sticker + * + * @deprecated Use {@link #getIconUrl()} instead */ @Nonnull + @Deprecated + @ForRemoval + @ReplaceWith("getIconUrl()") + @DeprecatedSince("4.3.1") public String getAssetHash() { return asset; @@ -117,13 +140,33 @@ public String getAssetHash() * If the {@link StickerFormat StickerFormat} of this sticker is {@link StickerFormat#UNKNOWN UNKNOWN} * * @return the url of the sticker + * + * @deprecated Use {@link #getIconUrl()} instead */ @Nonnull + @Deprecated + @ForRemoval + @ReplaceWith("getIconUrl()") + @DeprecatedSince("4.3.1") public String getAssetUrl() { return String.format(ASSET_URL, id, asset, formatType.getExtension()); } + /** + * The url of the sticker image. + * + * @throws java.lang.IllegalStateException + * If the {@link StickerFormat StickerFormat} of this sticker is {@link StickerFormat#UNKNOWN UNKNOWN} + * + * @return The image url of the sticker + */ + @Nonnull + public String getIconUrl() + { + return Helpers.format(ICON_URL, getId(), formatType.getExtension()); + } + /** * The {@link StickerFormat Format} of the sticker. * 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 24d2766adc..b4a33745d0 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1464,9 +1464,8 @@ public MessageSticker createSticker(DataObject content) final long id = content.getLong("id"); final String name = content.getString("name"); final String description = content.getString("description"); - final long packId = content.getLong("pack_id"); - final String asset = content.getString("asset"); - final String previewAsset = content.getString("preview_asset", null); + final long packId = content.getLong("pack_id", content.getLong("guild_id", 0L)); + final String asset = content.getString("asset", ""); final MessageSticker.StickerFormat format = MessageSticker.StickerFormat.fromId(content.getInt("format_type")); final Set tags; if (content.isNull("tags")) @@ -1479,7 +1478,7 @@ public MessageSticker createSticker(DataObject content) final Set tmp = new HashSet<>(Arrays.asList(split)); tags = Collections.unmodifiableSet(tmp); } - return new MessageSticker(id, name, description, packId, asset, previewAsset, format, tags); + return new MessageSticker(id, name, description, packId, asset, format, tags); } @Nullable