Skip to content

Commit

Permalink
Add copyFrom to EmbedBuilder (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Aug 2, 2021
1 parent da3ddd8 commit 196f31f
Showing 1 changed file with 58 additions and 27 deletions.
85 changes: 58 additions & 27 deletions src/main/java/net/dv8tion/jda/api/EmbedBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,15 @@ public class EmbedBuilder
*/
public EmbedBuilder() { }

/**
* Creates an EmbedBuilder using fields from an existing builder
*
* @param builder
* the existing builder
*/
public EmbedBuilder(@Nullable EmbedBuilder builder)
{
if (builder != null)
{
setDescription(builder.description.toString());
this.fields.addAll(builder.fields);
this.url = builder.url;
this.title = builder.title;
this.timestamp = builder.timestamp;
this.color = builder.color;
this.thumbnail = builder.thumbnail;
this.author = builder.author;
this.footer = builder.footer;
this.image = builder.image;
}
copyFrom(builder);
}

/**
Expand All @@ -87,20 +81,7 @@ public EmbedBuilder(@Nullable EmbedBuilder builder)
*/
public EmbedBuilder(@Nullable MessageEmbed embed)
{
if(embed != null)
{
setDescription(embed.getDescription());
this.url = embed.getUrl();
this.title = embed.getTitle();
this.timestamp = embed.getTimestamp();
this.color = embed.getColorRaw();
this.thumbnail = embed.getThumbnail();
this.author = embed.getAuthor();
this.footer = embed.getFooter();
this.image = embed.getImage();
if (embed.getFields() != null)
fields.addAll(embed.getFields());
}
copyFrom(embed);
}

/**
Expand Down Expand Up @@ -149,6 +130,56 @@ public EmbedBuilder clear()
return this;
}

/**
* Copies the data from the given builder into this builder.
* <br>All the parts of the given builder will be applied to this one.
*
* @param builder
* the existing builder
*/
public void copyFrom(@Nullable EmbedBuilder builder)
{
if (builder != null)
{
setDescription(builder.description.toString());
this.clearFields();
this.fields.addAll(builder.fields);
this.url = builder.url;
this.title = builder.title;
this.timestamp = builder.timestamp;
this.color = builder.color;
this.thumbnail = builder.thumbnail;
this.author = builder.author;
this.footer = builder.footer;
this.image = builder.image;
}
}

/**
* Copies the data from the given embed into this builder.
* <br>All the parts of the given embed will be applied to this builder.
*
* @param embed
* the existing embed
*/
public void copyFrom(@Nullable MessageEmbed embed)
{
if(embed != null)
{
setDescription(embed.getDescription());
this.clearFields();
this.fields.addAll(embed.getFields());
this.url = embed.getUrl();
this.title = embed.getTitle();
this.timestamp = embed.getTimestamp();
this.color = embed.getColorRaw();
this.thumbnail = embed.getThumbnail();
this.author = embed.getAuthor();
this.footer = embed.getFooter();
this.image = embed.getImage();
}
}

/**
* Checks if the given embed is empty. Empty embeds will throw an exception if built
*
Expand Down

0 comments on commit 196f31f

Please sign in to comment.