From a3f048d5a06a1ea4e4e8f22a886a9c9c8160434d Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:26:37 -0400 Subject: [PATCH] Add `LazyEmbed#disabledDefaults` --- .../java/xyz/srnyx/lazylibrary/LazyEmbed.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java index cb3442a..955c8fe 100644 --- a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java +++ b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java @@ -35,6 +35,10 @@ public class LazyEmbed { * Replacements for all values that will be replaced when building the {@link MessageEmbed} */ @NotNull protected final Map replacements = new HashMap<>(); + /** + * The {@link Key keys} that are disabled from being set by the {@link LazySettings#embedDefaults} + */ + @NotNull protected final Set disabledDefaults = new HashSet<>(); /** * The color of the embed @@ -132,6 +136,10 @@ public LazyEmbed(@NotNull ConfigurationNode node) { * @param lazyEmbed the {@link LazyEmbed} to copy */ public LazyEmbed(@NotNull LazyEmbed lazyEmbed) { + replacements.putAll(lazyEmbed.replacements); + disabledDefaults.addAll(lazyEmbed.disabledDefaults); + + // Embed data setColor(lazyEmbed.color); setAuthor(lazyEmbed.authorName, lazyEmbed.authorUrl, lazyEmbed.authorIcon); setTitle(lazyEmbed.titleText, lazyEmbed.titleUrl); @@ -318,6 +326,44 @@ public LazyEmbed replace(@NotNull String key, @Nullable Object value) { return this; } + /** + * Replaces multiple keys with values in all parameters of the {@link LazyEmbed embed} + * + * @param replacements the replacements to make + * + * @return the {@link LazyEmbed} instance + */ + @NotNull + public LazyEmbed replace(@NotNull Map replacements) { + for (final Map.Entry entry : replacements.entrySet()) replace(entry.getKey(), entry.getValue()); + return this; + } + + /** + * Disables keys from being set by the {@link LazySettings#embedDefaults} + * + * @param keys the keys to disable + * + * @return the {@link LazyEmbed} instance + */ + @NotNull + public LazyEmbed disableDefaults(@NotNull Key... keys) { + return disableDefaults(Arrays.asList(keys)); + } + + /** + * Disables keys from being set by the {@link LazySettings#embedDefaults} + * + * @param keys the keys to disable + * + * @return the {@link LazyEmbed} instance + */ + @NotNull + public LazyEmbed disableDefaults(@NotNull Collection keys) { + disabledDefaults.addAll(keys); + return this; + } + /** * Convenience method for {@link Factory#Factory(LazyEmbed) new Factory(LazyEmbed)} using this {@link LazyEmbed} * @@ -381,8 +427,10 @@ public MessageEmbed build(@NotNull LazyLibrary library) { // Set defaults for (final Map.Entry entry : library.settings.embedDefaults.entrySet()) { + final Key key = entry.getKey(); + if (disabledDefaults.contains(key)) continue; final Object value = entry.getValue(); - if (value != null) entry.getKey().setter.accept(this, value); + if (value != null) key.setter.accept(this, value); } return builder.build();