Class Embed

java.lang.Object
com.marcpg.libpg.web.discord.Embed

public final class Embed extends Object
Represents a Discord embed that can be converted into a raw JSON.
Since:
0.0.4
See Also:
  • Field Details

  • Constructor Details

    • Embed

      public 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.
      Parameters:
      author - The embed's author information.
      title - The embed's title.
      titleLink - The embed's link, which gets opened when clicking the 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 all Embed.Fields that are in the embed.
      thumbnailUrl - The small image on the top right corner or bottom.
      timestamp - The time shown besides the footer, but is still a separate setting.
      footer - Tge embed's footer information.
    • Embed

      public Embed(String title, String description, Color color, List<Embed.Field> fields)
      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 all Embed.Fields that are in the embed.
    • Embed

      public Embed(Embed.Field... fields)
      Creates a very minimal and plain embed with only fields.
      Parameters:
      fields - A list of all Embed.Fields that are in the embed.
    • Embed

      public Embed()
      Creates a completely empty embed. Same as Embed.EMPTY.
  • Method Details

    • build

      public String 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

      public Embed clear()
      Clears the whole embed by setting all values to null.
      Returns:
      A reference to this object.
    • clearNullAvoiding

      public Embed 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 are null, but also if they are empty/blank.
      Returns:
      true if the embed is empty, false otherwise.
    • getAuthor

      public Embed.Author getAuthor()
      Gets the embed's author.
      Returns:
      The embed's Embed.Author.
    • setAuthor

      public Embed setAuthor(Embed.Author author)
      Sets the embed's author.
      Parameters:
      author - The embed's author information.
      Returns:
      A reference to this object.
    • getTitle

      public String getTitle()
      Gets the embed's title.
      Returns:
      The embed's title.
    • setTitle

      public Embed setTitle(String title)
      Sets the embed's title.
      Parameters:
      title - The embed's title.
      Returns:
      A reference to this object.
    • getTitleLink

      public URL getTitleLink()
      Gets the embed's title link.
      Returns:
      The embed's title link that opens when clicking the title.
    • setTitleLink

      public Embed setTitleLink(URL titleLink)
      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

      public Embed setTitleWithLink(String title, URL titleLink)
      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

      public String getDescription()
      Gets the embed's description, which is the big text below the title.
      Returns:
      The embed's description.
    • setDescription

      public Embed setDescription(String description)
      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

      public Color getColor()
      Gets the embed's color.
      Returns:
      The embed's color.
    • setColor

      public Embed setColor(Color color)
      Sets the embed's color.
      Parameters:
      color - The embed's color.
      Returns:
      A reference to this object.
    • getFields

      public List<Embed.Field> getFields()
      Gets all of the embed's field.
      Returns:
      A list of all fields.
    • setFields

      public Embed setFields(List<Embed.Field> fields)
      Sets all of the embed's field.
      Parameters:
      fields - All new fields for this embed.
      Returns:
      A reference to this object.
    • addField

      public Embed addField(Embed.Field... field)
      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

      public Embed addField(String name, String value, boolean inline)
      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

      public Embed removeField(Embed.Field... field)
      Removes a field based on the object.
      Parameters:
      field - The removed fields from this embed.
      Returns:
      A reference to this object.
    • removeField

      public Embed removeField(String fieldName)
      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

      public URL 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

      public Embed setThumbnailUrl(URL thumbnailUrl)
      Sets the embed's thumbnail image URL.
      Parameters:
      thumbnailUrl - The embed's thumbnail image URL.
      Returns:
      A reference to this object.
    • getFooter

      public Embed.Footer getFooter()
      Gets the embed's footer.
      Returns:
      The embed's footer information.
    • setFooter

      public Embed setFooter(Embed.Footer footer)
      Sets the embed's footer.
      Parameters:
      footer - The embed's footer.
      Returns:
      A reference to this object.
    • colorToDecimal

      public static int colorToDecimal(@NotNull @NotNull Color color)
      Converts a AWT Color to a decimal integer, using some simple binary shifting.
      Parameters:
      color - The color to convert.
      Returns:
      The converted decimal integer.