aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-09-04 11:35:02 +0200
committerLorenz <lo.scherf@gmail.com>2022-09-04 11:35:02 +0200
commit66d0e21b3e9a573806dc4f0f3d5990ee2f740f0e (patch)
tree3b78c3e9835398055b90d462f79b6cbc302a4ba1
parent8821010142db46a6b5983738d814d5942e28104b (diff)
downloadNotEnoughUpdates-66d0e21b3e9a573806dc4f0f3d5990ee2f740f0e.tar.gz
NotEnoughUpdates-66d0e21b3e9a573806dc4f0f3d5990ee2f740f0e.tar.bz2
NotEnoughUpdates-66d0e21b3e9a573806dc4f0f3d5990ee2f740f0e.zip
I like regex
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java28
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java20
2 files changed, 32 insertions, 16 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java
index 592ebc0e..02559115 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java
@@ -20,7 +20,6 @@
package io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
import io.github.moulberry.notenoughupdates.util.Utils;
@@ -28,10 +27,21 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
public class MinionHelperChatLoader {
private final MinionHelperManager manager;
+ //§aYou crafted a §eTier I Redstone Minion§a! That's a new one!
+ // §aCraft §e7 §amore unique Minions to unlock your §e9th Minion slot§a!
+ private final Pattern PATTERN_OWN_MINION = Pattern.compile(
+ "§aYou crafted a §eTier (\\S+) (.+) Minion§a! That's a new one!(\\r\\n|\\r|\\n)(.*)");
+
+ //§b[MVP§3+§b] Eisengolem§f §acrafted a §eTier I Birch Minion§a!
+ private final Pattern PATTERN_COOP_MINION = Pattern.compile("(.+)§f §acrafted a §eTier (\\S+) (.+) Minion§a!");
+
public MinionHelperChatLoader(MinionHelperManager manager) {
this.manager = manager;
}
@@ -43,20 +53,20 @@ public class MinionHelperChatLoader {
if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) return;
try {
- if (message.startsWith("§r§aYou crafted a §eTier ") && message.contains("§a! That's a new one!")) {
- String text = StringUtils.substringBetween(message, "§eTier ", "§a! That's");
- String rawTier = text.split(" ")[0];
+ Matcher ownMatcher = PATTERN_OWN_MINION.matcher(message);
+ if (ownMatcher.matches()) {
+ String name = ownMatcher.group(1) + " Minion";
+ String rawTier = ownMatcher.group(2);
int tier = Utils.parseRomanNumeral(rawTier);
- String name = text.substring(rawTier.length() + 1);
setCrafted(manager.getMinionByName(name, tier));
}
- if (message.contains("§f §acrafted a §eTier ") && message.contains(" Minion§a!")) {
- String text = StringUtils.substringBetween(message, "§eTier ", "§a!");
- String rawTier = text.split(" ")[0];
+ Matcher coopMatcher = PATTERN_COOP_MINION.matcher(message);
+ if (coopMatcher.matches()) {
+ String name = coopMatcher.group(2) + " Minion";
+ String rawTier = coopMatcher.group(3);
int tier = Utils.parseRomanNumeral(rawTier);
- String name = text.substring(rawTier.length() + 1);
setCrafted(manager.getMinionByName(name, tier));
manager.getOverlay().resetCache();
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java
index f23db532..de9dadb3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java
@@ -36,6 +36,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MinionHelperInventoryLoader {
@@ -45,6 +46,12 @@ public class MinionHelperInventoryLoader {
private int ticks = 0;
+ //§7Craft §b5 §7more §aunique §7minions
+ private final Pattern PATTERN_MINIONS_NEEDED = Pattern.compile("§7Craft §b(\\d) §7more §aunique §7minions");
+
+ //§r §r§fPelts: §r§59§r
+ private final Pattern PATTERN_PELTS = Pattern.compile("§r §r§fPelts: §r§5(\\d)§r");
+
public MinionHelperInventoryLoader(MinionHelperManager manager) {
this.manager = manager;
}
@@ -86,10 +93,9 @@ public class MinionHelperInventoryLoader {
private void checkLocalPelts() {
int pelts = -1;
for (String name : TabListUtils.getTabList()) {
- if (name.startsWith("§r §r§fPelts: ")) {
- name = name.replaceAll(Pattern.quote("§r"), "");
- String rawNumber = name.split("§5")[1];
- pelts = Integer.parseInt(rawNumber);
+ Matcher matcher = PATTERN_PELTS.matcher(name);
+ if (matcher.matches()) {
+ pelts = Integer.parseInt(matcher.group(1));
break;
}
}
@@ -102,9 +108,9 @@ public class MinionHelperInventoryLoader {
if (informationSlot.getHasStack()) {
ItemStack informationStack = informationSlot.getStack();
for (String line : ItemUtils.getLore(informationStack)) {
- if (line.contains("§aunique")) {
- String[] split = line.split(" ");
- int needForNextSlot = Integer.parseInt(StringUtils.cleanColour(split[1]));
+ Matcher matcher = PATTERN_MINIONS_NEEDED.matcher(line);
+ if (matcher.matches()) {
+ int needForNextSlot = Integer.parseInt(matcher.group(1));
manager.setNeedForNextSlot(needForNextSlot);
return;
}