Skip to content

Commit

Permalink
Add field getter methods to LazyEmbed
Browse files Browse the repository at this point in the history
- `#getField(String)`
- `#getFieldValue(String)`
  • Loading branch information
srnyx committed Oct 3, 2024
1 parent 0da6778 commit bb700ef
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,34 @@ public List<MessageEmbed.Field> 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<MessageEmbed.Field> 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<String> getFieldValue(@NotNull String name) {
return getField(name).map(MessageEmbed.Field::getValue);
}

/**
* Clears all fields from the embed
*
Expand Down

0 comments on commit bb700ef

Please sign in to comment.