aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
}