Skip to content

Commit

Permalink
Fix LazyEmbed replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Aug 19, 2024
1 parent aed33d3 commit f3b31c2
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,43 +330,45 @@ public LazyEmbed replace(@NotNull String key, @Nullable Object value) {
*/
@NotNull
public MessageEmbed build(@NotNull LazyLibrary library) {
// Get replaceable values
String authorNameReplace = authorName;
String titleTextReplace = titleText;
String descriptionReplace = description;
String footerTextReplace = footerText;

// Parse replacements for the values
final boolean hasReplacements = !replacements.isEmpty();
if (hasReplacements) for (final Map.Entry<String, String> entry : replacements.entrySet()) {
if (authorNameReplace != null) authorNameReplace = authorNameReplace.replace(entry.getKey(), entry.getValue());
if (titleTextReplace != null) titleTextReplace = titleTextReplace.replace(entry.getKey(), entry.getValue());
if (descriptionReplace != null) descriptionReplace = descriptionReplace.replace(entry.getKey(), entry.getValue());
if (footerTextReplace != null) footerTextReplace = footerTextReplace.replace(entry.getKey(), entry.getValue());
}
// Replacements
if (!replacements.isEmpty()) {
// Get replaceable values
String authorNameReplace = authorName;
String titleTextReplace = titleText;
String descriptionReplace = description;
String footerTextReplace = footerText;

// Parse replacements for the values
for (final Map.Entry<String, String> entry : replacements.entrySet()) {
if (authorNameReplace != null) authorNameReplace = authorNameReplace.replace(entry.getKey(), entry.getValue());
if (titleTextReplace != null) titleTextReplace = titleTextReplace.replace(entry.getKey(), entry.getValue());
if (descriptionReplace != null) descriptionReplace = descriptionReplace.replace(entry.getKey(), entry.getValue());
if (footerTextReplace != null) footerTextReplace = footerTextReplace.replace(entry.getKey(), entry.getValue());
}

// Set the values
setAuthor(authorNameReplace, authorUrl, authorIcon);
setTitle(titleTextReplace, titleUrl);
setDescription(descriptionReplace);
setFooter(footerTextReplace, footerIcon);
// Set the new values
setAuthor(authorNameReplace, authorUrl, authorIcon);
setTitle(titleTextReplace, titleUrl);
setDescription(descriptionReplace);
setFooter(footerTextReplace, footerIcon);

// Fields
if (hasReplacements) {
// Fields
final List<MessageEmbed.Field> newFields = new ArrayList<>(fields);
clearFields();
for (final MessageEmbed.Field field : new ArrayList<>(fields)) {
for (final MessageEmbed.Field field : newFields) {
// Get name and value
String name = field.getName();
String value = field.getValue();
if (name == null || value == null) continue;

// Parse replacements for the name and value
for (final Map.Entry<String, String> entry : replacements.entrySet()) {
if (name != null) name = name.replace(entry.getKey(), entry.getValue());
if (value != null) value = value.replace(entry.getKey(), entry.getValue());
name = name.replace(entry.getKey(), entry.getValue());
value = value.replace(entry.getKey(), entry.getValue());
}

// Add the new field
if (name != null && value != null) addField(name, value, field.isInline());
addField(name, value, field.isInline());
}
}

Expand Down

0 comments on commit f3b31c2

Please sign in to comment.