Package com.marcpg.libpg.web.discord
Class Embed
java.lang.Object
com.marcpg.libpg.web.discord.Embed
Represents a Discord embed that can be converted into a raw JSON.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Represents the author information of an embed.static final record
Represents a field of an embed.static final record
Represents the footer information of an embed. -
Field Summary
-
Constructor Summary
ConstructorDescriptionEmbed()
Creates a completely empty embed.Embed
(Embed.Author author, String title, URL titleLink, String description, Color color, List<Embed.Field> fields, URL thumbnailUrl, OffsetDateTime timestamp, Embed.Footer footer) Creates a new embed with all values as parameters.Embed
(Embed.Field... fields) Creates a very minimal and plain embed with only fields.Creates a minimal embed with only the most basic stuff, so title, description, color and fields. -
Method Summary
Modifier and TypeMethodDescriptionaddField
(Embed.Field... field) Appends a new field to the end of the fields.Appends a new field to the end of the fields.build()
Formats the embed into a compact representation in JSON, which is required for sending it to the Discord API.clear()
Clears the whole embed by setting all values to null.Clears the whole embed while trying to avoid settings values to null.static int
colorToDecimal
(@NotNull Color color) Converts aAWT Color
to a decimal integer, using some simple binary shifting.Gets the embed's author.getColor()
Gets the embed's color.Gets the embed's description, which is the big text below the title.Gets all of the embed's field.Gets the embed's footer.Gets the embed's thumbnail image URL.getTitle()
Gets the embed's title.Gets the embed's title link.boolean
isEmpty()
Checks if the embed is empty.removeField
(Embed.Field... field) Removes a field based on the object.removeField
(String fieldName) Removes a field based on the field's name.setAuthor
(Embed.Author author) Sets the embed's author.Sets the embed's color.setDescription
(String description) Gets the embed's description, which is the big text below the title.setFields
(List<Embed.Field> fields) Sets all of the embed's field.setFooter
(Embed.Footer footer) Sets the embed's footer.setThumbnailUrl
(URL thumbnailUrl) Sets the embed's thumbnail image URL.Sets the embed's title.setTitleLink
(URL titleLink) Sets the embed's title link.setTitleWithLink
(String title, URL titleLink) Sets the embed's title and the title link.
-
Field Details
-
EMPTY
A completely emptyEmbed
object. Same asnew Embed()
.
-
-
Constructor Details
-
Embed
Creates a minimal embed with only the most basic stuff, so title, description, color and fields.- Parameters:
title
- The embed's title.description
- The embed's plain text description, which appears under the title.color
- The embed's color, which appears as the bar on the left side.fields
- A list of allEmbed.Field
s that are in the embed.
-
Embed
Creates a very minimal and plain embed with only fields.- Parameters:
fields
- A list of allEmbed.Field
s that are in the embed.
-
Embed
public Embed()Creates a completely empty embed. Same asEmbed.EMPTY
.
-
Method Details
-
build
Formats the embed into a compact representation in JSON, which is required for sending it to the Discord API.- Returns:
- The formatted JSON representation.
-
clear
Clears the whole embed by setting all values to null.- Returns:
- A reference to this object.
-
clearNullAvoiding
Clears the whole embed while trying to avoid settings values to null.- Returns:
- A reference to this object.
-
isEmpty
public boolean isEmpty()Checks if the embed is empty. This doesn't only include if the values arenull
, but also if they are empty/blank.- Returns:
true
if the embed is empty,false
otherwise.
-
getAuthor
Gets the embed's author.- Returns:
- The embed's
Embed.Author
.
-
setAuthor
Sets the embed's author.- Parameters:
author
- The embed's author information.- Returns:
- A reference to this object.
-
getTitle
Gets the embed's title.- Returns:
- The embed's title.
-
setTitle
Sets the embed's title.- Parameters:
title
- The embed's title.- Returns:
- A reference to this object.
-
getTitleLink
Gets the embed's title link.- Returns:
- The embed's title link that opens when clicking the title.
-
setTitleLink
Sets the embed's title link.- Parameters:
titleLink
- The embed's title link that opens when clicking the title.- Returns:
- A reference to this object.
-
setTitleWithLink
Sets the embed's title and the title link.- Parameters:
title
- The embed's title link that opens when clicking the title.titleLink
- The embed's title.- Returns:
- A reference to this object.
-
getDescription
Gets the embed's description, which is the big text below the title.- Returns:
- The embed's description.
-
setDescription
Gets the embed's description, which is the big text below the title.
Can use most of the markdown formatting.- Parameters:
description
- The embed's description.- Returns:
- A reference to this object.
-
getColor
Gets the embed's color.- Returns:
- The embed's color.
-
setColor
Sets the embed's color.- Parameters:
color
- The embed's color.- Returns:
- A reference to this object.
-
getFields
Gets all of the embed's field.- Returns:
- A list of all fields.
-
setFields
Sets all of the embed's field.- Parameters:
fields
- All new fields for this embed.- Returns:
- A reference to this object.
-
addField
Appends a new field to the end of the fields.- Parameters:
field
- The new fields for this embed.- Returns:
- A reference to this object.
-
addField
Appends a new field to the end of the fields.- Parameters:
name
- The name/title of the field.value
- The plaintext that appears below the name and holds the main information.inline
- If the field should be inline with other fields.- Returns:
- A reference to this object.
-
removeField
Removes a field based on the object.- Parameters:
field
- The removed fields from this embed.- Returns:
- A reference to this object.
-
removeField
Removes a field based on the field's name.- Parameters:
fieldName
- The removed field's name from this embed.- Returns:
- A reference to this object.
-
getThumbnailUrl
Gets the embed's thumbnail image URL.- Returns:
- The URL of the thumbnail, which is the small image at the upper right corner or the bottom.
-
setThumbnailUrl
Sets the embed's thumbnail image URL.- Parameters:
thumbnailUrl
- The embed's thumbnail image URL.- Returns:
- A reference to this object.
-
colorToDecimal
Converts aAWT Color
to a decimal integer, using some simple binary shifting.- Parameters:
color
- The color to convert.- Returns:
- The converted decimal integer.
-