aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRime <81419447+Emirlol@users.noreply.github.com>2024-06-27 16:14:40 +0300
committerRime <81419447+Emirlol@users.noreply.github.com>2024-07-10 02:08:24 +0300
commit478451fdc0a24b1b3616ca1d43c19fc5b90cfe70 (patch)
tree8c410241b611b048c61e64a87ea034d207af0239 /src
parent26af94886e964b5f83a26bf4a6866fd1553d0d79 (diff)
downloadSkyblocker-478451fdc0a24b1b3616ca1d43c19fc5b90cfe70.tar.gz
Skyblocker-478451fdc0a24b1b3616ca1d43c19fc5b90cfe70.tar.bz2
Skyblocker-478451fdc0a24b1b3616ca1d43c19fc5b90cfe70.zip
Add some javadocs for ItemUtils and simplify getLoreLine methods
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/ItemUtils.java29
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;
}