diff options
author | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-06-27 16:14:40 +0300 |
---|---|---|
committer | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-07-10 02:08:24 +0300 |
commit | 478451fdc0a24b1b3616ca1d43c19fc5b90cfe70 (patch) | |
tree | 8c410241b611b048c61e64a87ea034d207af0239 /src/main/java/de/hysky | |
parent | 26af94886e964b5f83a26bf4a6866fd1553d0d79 (diff) | |
download | Skyblocker-478451fdc0a24b1b3616ca1d43c19fc5b90cfe70.tar.gz Skyblocker-478451fdc0a24b1b3616ca1d43c19fc5b90cfe70.tar.bz2 Skyblocker-478451fdc0a24b1b3616ca1d43c19fc5b90cfe70.zip |
Add some javadocs for ItemUtils and simplify getLoreLine methods
Diffstat (limited to 'src/main/java/de/hysky')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/ItemUtils.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index ff6daad2..b8e99633 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -43,7 +43,8 @@ import java.util.regex.Pattern; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -public class ItemUtils { +public final class ItemUtils { + private ItemUtils() {} public static final String ID = "id"; public static final String UUID = "uuid"; public static final Pattern NOT_DURABILITY = Pattern.compile("[^0-9 /]"); @@ -198,6 +199,10 @@ public class ItemUtils { return null; } + /** + * Gets the first line of the lore that matches the specified predicate. + * @return The first line of the lore that matches the predicate, or {@code null} if no line matches. + */ @Nullable public static String getLoreLineIf(ItemStack item, Predicate<String> predicate) { for (Text line : getLore(item)) { @@ -210,29 +215,35 @@ public class ItemUtils { return null; } + /** + * Gets the first line of the lore that matches the specified pattern, using {@link Matcher#matches()}. + * @return A matcher that contains match results if the pattern was found in the lore, otherwise {@code null}. + */ @Nullable public static Matcher getLoreLineIfMatch(ItemStack item, Pattern pattern) { + Matcher matcher = pattern.matcher(""); for (Text line : getLore(item)) { - String string = line.getString(); - Matcher matcher = pattern.matcher(string); - if (matcher.matches()) { + if (matcher.reset(line.getString()).matches()) { return matcher; } } - return null; } + /** + * Gets the first line of the lore that matches the specified pattern, using {@link Matcher#find()}. + * @param pattern the pattern to search for + * @param item the item to search the lore of + * @return A {@link Matcher matcher} that contains match results if the pattern was found in the lore, otherwise {@code null}. + */ @Nullable public static Matcher getLoreLineIfContainsMatch(ItemStack item, Pattern pattern) { + Matcher matcher = pattern.matcher(""); for (Text line : getLore(item)) { - String string = line.getString(); - Matcher matcher = pattern.matcher(string); - if (matcher.find()) { + if (matcher.reset(line.getString()).find()) { return matcher; } } - return null; } |