diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2023-01-20 11:38:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 21:38:35 +1100 |
commit | 9fb6497c34f64e3c30b7ab5e417f4c2be6f9cc7b (patch) | |
tree | 7ea4a7b75ed0916d89626a11536d30557609c823 | |
parent | 97d3fb41693e97c51ba9e4929cd7f4294f7c68e1 (diff) | |
download | NotEnoughUpdates-9fb6497c34f64e3c30b7ab5e417f4c2be6f9cc7b.tar.gz NotEnoughUpdates-9fb6497c34f64e3c30b7ab5e417f4c2be6f9cc7b.tar.bz2 NotEnoughUpdates-9fb6497c34f64e3c30b7ab5e417f4c2be6f9cc7b.zip |
Fixed Powder Checker (#561)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Fixes https://github.com/NotEnoughUpdates/NotEnoughUpdates/issues/560
3 files changed, 23 insertions, 29 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index c97aaedf..8563189c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -316,10 +316,7 @@ public class ChatListener { } } - if (unformatted.equals("You uncovered a treasure chest!") || - unformatted.equals("You have successfully picked the lock on this chest!") - || (unformatted.startsWith("You received +") && unformatted.endsWith(" Powder"))) - OverlayManager.powderGrindingOverlay.message(unformatted); + OverlayManager.powderGrindingOverlay.onMessage(unformatted); if (unformatted.startsWith("ENDER NODE!")) EnderNodeHighlighter.getInstance().highlightedBlocks.clear(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java index b82b44c2..797083b5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java @@ -738,7 +738,7 @@ public class Mining { @Expose @ConfigOption( name = "Enable Tracker", - desc = "Show an Overlay with useful information related to Power Grinding" + desc = "Show an Overlay with useful information related to Powder Grinding" ) @ConfigAccordionId(id = 9) @ConfigEditorBoolean diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java index 50ecce90..ad8755e3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java @@ -19,8 +19,6 @@ package io.github.moulberry.notenoughupdates.overlays; -import com.google.gson.Gson; -import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; @@ -28,26 +26,19 @@ import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.SBInfo; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; -import java.util.stream.Collectors; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class PowderGrindingOverlay extends TextTabOverlay { private final static JsonParser PARSER = new JsonParser(); + private final static Pattern pattern = + Pattern.compile("You received \\+([0-9]+(?:,\\d+)*) (Mithril|Gemstone) Powder\\."); public int chestCount = 0; public int openedChestCount = 0; @@ -112,7 +103,8 @@ public class PowderGrindingOverlay extends TextTabOverlay { overlayStrings.add("\u00a73Opened Chests: \u00a7a" + format.format(this.openedChestCount)); break; case 2: - overlayStrings.add("\u00a73Unopened Chests: \u00a7c" + format.format(this.chestCount - this.openedChestCount)); + overlayStrings.add( + "\u00a73Unopened Chests: \u00a7c" + format.format(this.chestCount - this.openedChestCount)); break; case 3: overlayStrings.add("\u00a73Mithril Powder Found: \u00a72" + @@ -141,21 +133,26 @@ public class PowderGrindingOverlay extends TextTabOverlay { if (overlayStrings != null && overlayStrings.isEmpty()) overlayStrings = null; } - public void message(String message) { + public void onMessage(String message) { if (message.equals("You uncovered a treasure chest!")) { this.chestCount++; } else if (message.equals("You have successfully picked the lock on this chest!")) { this.openedChestCount++; } else { - boolean mithril = message.endsWith(" Mithril Powder"); - boolean gemstone = message.endsWith(" Gemstone Powder"); - if (!(mithril || gemstone)) return; - try { - int amount = Integer.parseInt(message.split(" ")[2].replaceAll("\\+", "")); - if (mithril) this.mithrilPowderFound += amount; - else this.gemstonePowderFound += amount; - } catch (NumberFormatException | IndexOutOfBoundsException e) { - e.printStackTrace(); + Matcher matcher = pattern.matcher(message); + if (matcher.matches()) { + String rawNumber = matcher.group(1).replace(",", ""); + try { + int amount = Integer.parseInt(rawNumber); + String type = matcher.group(2); + if (type.equals("Mithril")) { + this.mithrilPowderFound += amount; + } else if (type.equals("Gemstone")) { + this.gemstonePowderFound += amount; + } + } catch (NumberFormatException e) { + e.printStackTrace(); + } } } } |