diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/ItemUtils.java')
-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; } |