From bb700ef0d9280d2f3169df385972eb27a1f48536 Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:16:31 -0400 Subject: [PATCH] Add field getter methods to `LazyEmbed` - `#getField(String)` - `#getFieldValue(String)` --- .../java/xyz/srnyx/lazylibrary/LazyEmbed.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java index 0ef1626..cb3442a 100644 --- a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java +++ b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java @@ -655,6 +655,34 @@ public List getFields() { return Collections.unmodifiableList(fields); } + /** + * Returns a field from the embed by its name + * + * @param name the name of the field + * + * @return the field, or {@link Optional#empty() empty} if not found + */ + @NotNull + public Optional getField(@NotNull String name) { + for (final MessageEmbed.Field field : fields) { + final String fieldName = field.getName(); + if (fieldName != null && fieldName.equals(name)) return Optional.of(field); + } + return Optional.empty(); + } + + /** + * Returns the value of a field from the embed by its name + * + * @param name the name of the field + * + * @return the value of the field, or {@link Optional#empty() empty} if not found + */ + @NotNull + public Optional getFieldValue(@NotNull String name) { + return getField(name).map(MessageEmbed.Field::getValue); + } + /** * Clears all fields from the embed *