aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjani270 <69345714+jani270@users.noreply.github.com>2023-12-31 14:26:12 +0100
committerGitHub <noreply@github.com>2023-12-31 14:26:12 +0100
commit13a1c03698716178822b81b4510e63908ce8e5dd (patch)
treeba4812bb6132183f971e9df22c4e42abdad5ba4b
parent2ba842ebd2cdd4768b3745cacfbce50c835ba82f (diff)
downloadNotEnoughUpdates-13a1c03698716178822b81b4510e63908ce8e5dd.tar.gz
NotEnoughUpdates-13a1c03698716178822b81b4510e63908ce8e5dd.tar.bz2
NotEnoughUpdates-13a1c03698716178822b81b4510e63908ce8e5dd.zip
Changed gatherJacobData to a regex and fixed a NFE (#980)
* Fixed cleanSpecialChars not working Co-Authored-By: hannibal2 <24389977+hannibal002@users.noreply.github.com> * Changed logic of gatherjacobdata and fixed #808 Co-Authored-By: hannibal2 <24389977+hannibal002@users.noreply.github.com> * Removed unused import * Moved Pattern outside gatherJacobData * Made the regex more explicit. --------- Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java20
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/SidebarUtil.kt2
2 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java
index 3c8f377d..f071c788 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java
@@ -29,6 +29,7 @@ import io.github.moulberry.notenoughupdates.util.SidebarUtil;
import io.github.moulberry.notenoughupdates.util.Utils;
import io.github.moulberry.notenoughupdates.util.XPInformation;
import io.github.moulberry.notenoughupdates.util.hypixelapi.HypixelItemAPI;
+import lombok.val;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -40,6 +41,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
+import java.util.regex.Pattern;
public class FarmingSkillOverlay extends TextOverlay {
private static final NumberFormat format = NumberFormat.getIntegerInstance();
@@ -88,6 +90,9 @@ public class FarmingSkillOverlay extends TextOverlay {
private String skillType = "Farming";
+ private static final Pattern CONTEST_AMOUNT_PATTERN = Pattern.compile(
+ " (Collected|(BRONZE|SILVER|GOLD|PLATINUM|DIAMOND) with) (?<amount>[\\d,]+)");
+
public FarmingSkillOverlay(
Position position,
Supplier<List<String>> dummyStrings,
@@ -136,14 +141,17 @@ public class FarmingSkillOverlay extends TextOverlay {
inJacobContest = false;
if (isJacobTime()) {
int timeLeftInContest = (20 * 60) - ((int) ((System.currentTimeMillis() % 3600000 - 900000) / 1000));
-
int cropsFarmed = -1;
for (String line : SidebarUtil.readSidebarLines()) {
- if (line.contains("Collected") || line.contains("BRONZE") || line.contains("SILVER") ||
- line.contains("GOLD") || line.contains("PLATINUM") || line.contains("DIAMOND")) {
- inJacobContest = true;
- String l = line.replaceAll("[^A-Za-z0-9() ]", "");
- cropsFarmed = Integer.parseInt(l.substring(l.lastIndexOf(" ") + 1).replace(",", ""));
+ val matcher = CONTEST_AMOUNT_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ String amount = matcher.group("amount").replace(",", "");
+ try {
+ inJacobContest = true;
+ cropsFarmed = Integer.parseInt(amount);
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ }
}
jacobPrediction = (int) (cropsFarmed + (cropsPerSecond * timeLeftInContest));
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SidebarUtil.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SidebarUtil.kt
index d51c2ea9..47663bca 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SidebarUtil.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SidebarUtil.kt
@@ -29,7 +29,7 @@ object SidebarUtil {
fun readSidebarLines(cleanColor: Boolean = true, cleanSpecialCharacters: Boolean = true): List<String> {
var result = readRawSidebarLines()
if (cleanColor) result = result.map { Utils.cleanColour(it) }
- if (cleanSpecialCharacters) result.map { cleanTeamName(it) }
+ if (cleanSpecialCharacters) result = result.map { cleanTeamName(it) }
return result
}