Skip to content

Commit

Permalink
Address breaking changes for stickers
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Jun 24, 2021
1 parent 5a6388a commit 62de8e6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
51 changes: 47 additions & 4 deletions src/main/java/net/dv8tion/jda/api/entities/MessageSticker.java
Expand Up @@ -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;

Expand All @@ -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<String> 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<String> tags)
public MessageSticker(final long id, final String name, final String description, final long packId, final String asset, final StickerFormat formatType, final Set<String> 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;
}
Expand Down Expand Up @@ -80,6 +93,8 @@ public String getDescription()
/**
* The ID of the pack the sticker is from.
*
* <p>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
Expand All @@ -91,6 +106,8 @@ public String getPackId()
/**
* The ID of the pack the sticker is from.
*
* <p>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()
Expand All @@ -103,8 +120,14 @@ public long getPackIdLong()
* <br><b>The URL for fetching sticker assets is currently private.</b>
*
* @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;
Expand All @@ -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.
*
Expand Down
Expand Up @@ -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<String> tags;
if (content.isNull("tags"))
Expand All @@ -1479,7 +1478,7 @@ public MessageSticker createSticker(DataObject content)
final Set<String> 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
Expand Down

0 comments on commit 62de8e6

Please sign in to comment.