Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copyFrom to EmbedBuilder #1738

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 57 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;
}
reset(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());
}
reset(embed);
}

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

/**
* Resets this builder to the state of the given builder.
freya022 marked this conversation as resolved.
Show resolved Hide resolved
* <br>All the parts of the given builder will be applied to this one.
*
* @param builder
* the existing builder
*/
public void reset(EmbedBuilder builder)
freya022 marked this conversation as resolved.
Show resolved Hide resolved
{
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;
}
}

/**
* Resets this builder to the state of the given embed.
freya022 marked this conversation as resolved.
Show resolved Hide resolved
* <br>All the parts of the given embed will be applied to this builder.
*
* @param embed
* the existing embed
*/
public void reset(MessageEmbed embed)
freya022 marked this conversation as resolved.
Show resolved Hide resolved
{
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());
}
}

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