From 3d2745eace41f0b1e637bf62e120830c2353ea2e Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:57:04 -0400 Subject: [PATCH] Add more field methods to `LazyEmbed` --- .../java/xyz/srnyx/lazylibrary/LazyEmbed.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java index 3b5b575..0ef1626 100644 --- a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java +++ b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java @@ -570,6 +570,81 @@ public LazyEmbed addFields(@NotNull Collection<MessageEmbed.Field> newFields) { return this; } + /** + * Adds multiple fields to the embed + * + * @param newFields the fields to add + * + * @return this + */ + @NotNull + public LazyEmbed addFields(@NotNull MessageEmbed.Field... newFields) { + return addFields(Arrays.asList(newFields)); + } + + /** + * Adds an empty field to the embed + * + * @param inline whether the field should be inline or not + * + * @return this + */ + @NotNull + public LazyEmbed addEmptyField(boolean inline) { + return addField("", "", inline); + } + + /** + * Adds multiple empty fields to the embed + * + * @param amount the amount of empty fields to add + * @param inline whether the fields should be inline or not + * + * @return this + */ + @NotNull + public LazyEmbed addEmptyFields(int amount, boolean inline) { + for (int i = 0; i < amount; i++) addEmptyField(inline); + return this; + } + + /** + * Creates a grid of fields in the embed + * + * @param rows the rows of fields to add + * + * @return this + */ + @NotNull + public LazyEmbed gridFields(@NotNull Collection<Map<String, String>> rows) { + for (final Map<String, String> row : rows) { + // Add fields + int added = 0; + for (final Map.Entry<String, String> entry : row.entrySet()) { + final String value = entry.getValue(); + if (value == null || value.isEmpty()) continue; + addField(entry.getKey(), entry.getValue(), true); + added++; + } + // Add empty fields to make the grid + final int remainder = added % 3; + if (remainder != 0) addEmptyFields(3 - remainder, true); + } + return this; + } + + /** + * Creates a grid of fields in the embed + * + * @param rows the rows of fields to add + * + * @return this + */ + @NotNull @SafeVarargs + public final LazyEmbed gridFields(@NotNull Map<String, String>... rows) { + return gridFields(Arrays.asList(rows)); + } + /** * Returns an unmodifiable list of all fields in the embed *