aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-09-22 12:58:52 -0400
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-09-22 12:58:52 -0400
commit0ef339b506839c641df5e47bcecebc697fd4a09e (patch)
tree9a44017677f4e0a88506dd6be95cee45991ddeb7 /src/main/java
parent4bb2e49763aff58007da720f79bb50a77bd3066a (diff)
downloadSkyblocker-0ef339b506839c641df5e47bcecebc697fd4a09e.tar.gz
Skyblocker-0ef339b506839c641df5e47bcecebc697fd4a09e.tar.bz2
Skyblocker-0ef339b506839c641df5e47bcecebc697fd4a09e.zip
Update health and speed bar
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java285
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java26
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/RegexUtils.java28
4 files changed, 177 insertions, 164 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java b/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java
index 5938f76e..18448ea5 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java
@@ -2,10 +2,11 @@ package de.hysky.skyblocker.skyblock;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Location;
+import de.hysky.skyblocker.utils.RegexUtils;
import de.hysky.skyblocker.utils.Utils;
+import de.hysky.skyblocker.utils.scheduler.Scheduler;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
@@ -13,143 +14,147 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StatusBarTracker {
- private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)❤(?:(\\+§c(\\d+(,\\d\\d\\d)*). *)| *)");
- private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(\\d+(,\\d\\d\\d)*)§a❈ Defense *");
- private static final Pattern MANA_USE = Pattern.compile("§b-(\\d+(,\\d\\d\\d)*) Mana \\(§\\S+(?:\\s\\S+)* *");
- private static final Pattern MANA_STATUS = Pattern.compile("§b(\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)✎ (?:Mana|§3(\\d+(,\\d\\d\\d)*)ʬ) *");
-
- private Resource health = new Resource(100, 100, 0);
- private Resource mana = new Resource(100, 100, 0);
- private Resource speed = new Resource(100, 400, 0);
- private int defense = 0;
-
- public void init() {
- ClientReceiveMessageEvents.ALLOW_GAME.register(this::allowOverlayMessage);
- ClientReceiveMessageEvents.MODIFY_GAME.register(this::onOverlayMessage);
- }
-
- public Resource getHealth() {
- return this.health;
- }
-
- public Resource getMana() {
- return this.mana;
- }
-
- public int getDefense() {
- return this.defense;
- }
-
- public Resource getSpeed() {
- updateSpeed();
- return this.speed;
- }
-
- private int parseInt(Matcher m, int group) {
- return Integer.parseInt(m.group(group).replace(",", ""));
- }
-
- private void updateMana(Matcher m) {
- int value = parseInt(m, 1);
- int max = parseInt(m, 3);
- int overflow = m.group(5) == null ? 0 : parseInt(m, 5);
- this.mana = new Resource(value, max, overflow);
- }
-
- private void updateSpeed() {
- // Black cat and racing helm are untested - I don't have the money to test atm, but no reason why they shouldn't work
- var player = MinecraftClient.getInstance().player;
- int value = (int) (player.isSprinting() ? (player.getMovementSpeed() / 1.3f) * 1000 : player.getMovementSpeed() * 1000);
- int max = 400; // hardcoded limit (except for with cactus knife, black cat, snail, racing helm, young drag)
- if (player.getMainHandStack().getName().getString().contains("Cactus Knife") && Utils.getLocation() == Location.GARDEN) {
- max = 500;
- }
- Iterable<ItemStack> armor = player.getArmorItems();
- int youngDragCount = 0;
- for (ItemStack armorPiece : armor) {
- if (armorPiece.getName().getString().contains("Racing Helmet")) {
- max = 500;
- } else if (armorPiece.getName().getString().contains("Young Dragon")) {
- youngDragCount++;
- }
- }
- if (youngDragCount == 4) {
- max = 500;
- }
-
- PetCache.PetInfo pet = PetCache.getCurrentPet();
- if (pet != null) {
- if (pet.type().contains("BLACK_CAT")) {
- max = 500;
- } else if (pet.type().contains("SNAIL")) {
- max = 100;
- }
- }
- this.speed = new Resource(value, max, 0);
- }
-
- private void updateHealth(Matcher m) {
- int value = parseInt(m, 1);
- int max = parseInt(m, 3);
- int overflow = Math.max(0, value - max);
- if (MinecraftClient.getInstance() != null && MinecraftClient.getInstance().player != null) {
- ClientPlayerEntity player = MinecraftClient.getInstance().player;
- value = (int) (player.getHealth() * max / player.getMaxHealth());
- overflow = (int) (player.getAbsorptionAmount() * max / player.getMaxHealth());
- }
- this.health = new Resource(Math.min(value, max), max, Math.min(overflow, max));
- }
-
- private String reset(String str, Matcher m) {
- str = str.substring(m.end());
- m.reset(str);
- return str;
- }
-
- private boolean allowOverlayMessage(Text text, boolean overlay) {
- onOverlayMessage(text, overlay);
- return true;
- }
-
- private Text onOverlayMessage(Text text, boolean overlay) {
- if (!overlay || !Utils.isOnSkyblock() || !SkyblockerConfigManager.get().uiAndVisuals.bars.enableBars || Utils.isInTheRift()) {
- return text;
- }
- return Text.of(update(text.getString(), SkyblockerConfigManager.get().chat.hideMana));
- }
-
- public String update(String actionBar, boolean filterManaUse) {
- var sb = new StringBuilder();
- Matcher matcher = STATUS_HEALTH.matcher(actionBar);
- if (!matcher.lookingAt())
- return actionBar;
- updateHealth(matcher);
- if (matcher.group(5) != null) {
- sb.append("§c❤");
- sb.append(matcher.group(5));
- }
- actionBar = reset(actionBar, matcher);
- if (matcher.usePattern(MANA_STATUS).lookingAt()) {
- defense = 0;
- updateMana(matcher);
- actionBar = reset(actionBar, matcher);
- } else {
- if (matcher.usePattern(DEFENSE_STATUS).lookingAt()) {
- defense = parseInt(matcher, 1);
- actionBar = reset(actionBar, matcher);
- } else if (filterManaUse && matcher.usePattern(MANA_USE).lookingAt()) {
- actionBar = reset(actionBar, matcher);
- }
- if (matcher.usePattern(MANA_STATUS).find()) {
- updateMana(matcher);
- matcher.appendReplacement(sb, "");
- }
- }
- matcher.appendTail(sb);
- String res = sb.toString().trim();
- return res.isEmpty() ? null : res;
- }
-
- public record Resource(int value, int max, int overflow) {
- }
+ private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](?<health>[0-9,]+)/(?<max>[0-9,]+)❤ *(?<healing>\\+§c([0-9,]+). *)?");
+ private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(\\d+(,\\d\\d\\d)*)§a❈ Defense *");
+ private static final Pattern MANA_USE = Pattern.compile("§b-(\\d+(,\\d\\d\\d)*) Mana \\(§\\S+(?:\\s\\S+)* *");
+ private static final Pattern MANA_STATUS = Pattern.compile("§b(\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)✎ (?:Mana|§3(\\d+(,\\d\\d\\d)*)ʬ) *");
+
+ private final MinecraftClient client = MinecraftClient.getInstance();
+ private Resource health = new Resource(100, 100, 0);
+ private Resource mana = new Resource(100, 100, 0);
+ private Resource speed = new Resource(100, 400, 0);
+ private int defense = 0;
+
+ public void init() {
+ ClientReceiveMessageEvents.ALLOW_GAME.register(this::allowOverlayMessage);
+ ClientReceiveMessageEvents.MODIFY_GAME.register(this::onOverlayMessage);
+ Scheduler.INSTANCE.scheduleCyclic(this::tick, 1);
+ }
+
+ public Resource getHealth() {
+ return this.health;
+ }
+
+ public Resource getMana() {
+ return this.mana;
+ }
+
+ public int getDefense() {
+ return this.defense;
+ }
+
+ public Resource getSpeed() {
+ return this.speed;
+ }
+
+ private void tick() {
+ if (client == null || client.player == null) return;
+ updateHealth(health.value, health.max, health.overflow);
+ updateSpeed();
+ }
+
+ private void updateMana(Matcher m) {
+ int value = RegexUtils.parseIntFromMatcher(m, 1);
+ int max = RegexUtils.parseIntFromMatcher(m, 3);
+ int overflow;
+ overflow = m.group(5) == null ? 0 : RegexUtils.parseIntFromMatcher(m, 5);
+ this.mana = new Resource(value, max, overflow);
+ }
+
+ private void updateSpeed() {
+ // Black cat and racing helm are untested - I don't have the money to test atm, but no reason why they shouldn't work
+ assert client.player != null;
+ int value = (int) (client.player.isSprinting() ? (client.player.getMovementSpeed() / 1.3f) * 1000 : client.player.getMovementSpeed() * 1000);
+ int max = 400; // hardcoded limit (except for with cactus knife, black cat, snail, racing helm, young drag)
+ if (client.player.getMainHandStack().getName().getString().contains("Cactus Knife") && Utils.getLocation() == Location.GARDEN) {
+ max = 500;
+ }
+ Iterable<ItemStack> armor = client.player.getArmorItems();
+ int youngDragCount = 0;
+ for (ItemStack armorPiece : armor) {
+ if (armorPiece.getName().getString().contains("Racing Helmet")) {
+ max = 500;
+ } else if (armorPiece.getName().getString().contains("Young Dragon")) {
+ youngDragCount++;
+ }
+ }
+ if (youngDragCount == 4) {
+ max = 500;
+ }
+
+ PetCache.PetInfo pet = PetCache.getCurrentPet();
+ if (pet != null) {
+ if (pet.type().contains("BLACK_CAT")) {
+ max = 500;
+ } else if (pet.type().contains("SNAIL")) {
+ max = 100;
+ }
+ }
+ this.speed = new Resource(value, max, 0);
+ }
+
+ private void updateHealth(Matcher matcher) {
+ int health = RegexUtils.parseIntFromMatcher(matcher, "health");
+ int max = RegexUtils.parseIntFromMatcher(matcher, "max");
+ updateHealth(health, max, Math.max(0, health - max));
+ }
+
+ private void updateHealth(int value, int max, int overflow) {
+ if (client != null && client.player != null) {
+ value = (int) (client.player.getHealth() * max / client.player.getMaxHealth());
+ overflow = (int) (client.player.getAbsorptionAmount() * max / client.player.getMaxHealth());
+ }
+ health = new Resource(Math.min(value, max), max, Math.min(overflow, max));
+ }
+
+ private String reset(String str, Matcher m) {
+ str = str.substring(m.end());
+ m.reset(str);
+ return str;
+ }
+
+ private boolean allowOverlayMessage(Text text, boolean overlay) {
+ onOverlayMessage(text, overlay);
+ return true;
+ }
+
+ private Text onOverlayMessage(Text text, boolean overlay) {
+ if (!overlay || !Utils.isOnSkyblock() || !SkyblockerConfigManager.get().uiAndVisuals.bars.enableBars || Utils.isInTheRift()) {
+ return text;
+ }
+ return Text.of(update(text.getString(), SkyblockerConfigManager.get().chat.hideMana));
+ }
+
+ public String update(String actionBar, boolean filterManaUse) {
+ var sb = new StringBuilder();
+ Matcher matcher = STATUS_HEALTH.matcher(actionBar);
+ if (!matcher.lookingAt()) return actionBar;
+ updateHealth(matcher);
+ if (matcher.group("healing") != null) {
+ sb.append("§c❤");
+ sb.append(matcher.group("healing"));
+ }
+ actionBar = reset(actionBar, matcher);
+ if (matcher.usePattern(MANA_STATUS).lookingAt()) {
+ defense = 0;
+ updateMana(matcher);
+ actionBar = reset(actionBar, matcher);
+ } else {
+ if (matcher.usePattern(DEFENSE_STATUS).lookingAt()) {
+ defense = RegexUtils.parseIntFromMatcher(matcher, 1);
+ actionBar = reset(actionBar, matcher);
+ } else if (filterManaUse && matcher.usePattern(MANA_USE).lookingAt()) {
+ actionBar = reset(actionBar, matcher);
+ }
+ if (matcher.usePattern(MANA_STATUS).find()) {
+ updateMana(matcher);
+ matcher.appendReplacement(sb, "");
+ }
+ }
+ matcher.appendTail(sb);
+ String res = sb.toString().trim();
+ return res.isEmpty() ? null : res;
+ }
+
+ public record Resource(int value, int max, int overflow) {}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java
index da0f66c7..9bc45670 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java
@@ -145,19 +145,19 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too
getCoach(slots.get(COACH_SLOT)).ifPresent(cpsIncreaseFactors::add);
//The clickable chocolate is in slot 13, holds the total chocolate
- RegexUtils.getLongFromMatcher(CHOCOLATE_PATTERN.matcher(slots.get(CHOCOLATE_SLOT).getName().getString())).ifPresent(l -> totalChocolate = l);
+ RegexUtils.findLongFromMatcher(CHOCOLATE_PATTERN.matcher(slots.get(CHOCOLATE_SLOT).getName().getString())).ifPresent(l -> totalChocolate = l);
//Cps item (cocoa bean) is in slot 45
String cpsItemLore = ItemUtils.getConcatenatedLore(slots.get(CPS_SLOT));
Matcher cpsMatcher = CPS_PATTERN.matcher(cpsItemLore);
- RegexUtils.getDoubleFromMatcher(cpsMatcher).ifPresent(d -> totalCps = d);
+ RegexUtils.findDoubleFromMatcher(cpsMatcher).ifPresent(d -> totalCps = d);
Matcher multiplierMatcher = TOTAL_MULTIPLIER_PATTERN.matcher(cpsItemLore);
- RegexUtils.getDoubleFromMatcher(multiplierMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0).ifPresent(d -> totalCpsMultiplier = d);
+ RegexUtils.findDoubleFromMatcher(multiplierMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0).ifPresent(d -> totalCpsMultiplier = d);
//Prestige item is in slot 28
String prestigeLore = ItemUtils.getConcatenatedLore(slots.get(PRESTIGE_SLOT));
Matcher prestigeMatcher = PRESTIGE_REQUIREMENT_PATTERN.matcher(prestigeLore);
- OptionalLong currentChocolate = RegexUtils.getLongFromMatcher(prestigeMatcher);
+ OptionalLong currentChocolate = RegexUtils.findLongFromMatcher(prestigeMatcher);
if (currentChocolate.isPresent()) {
String requirement = prestigeMatcher.group(2); //If the first one matched, we can assume the 2nd one is also matched since it's one whole regex
//Since the last character is either M or B we can just try to replace both characters. Only the correct one will actually replace anything.
@@ -178,7 +178,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too
isTimeTowerMaxed = StringUtils.substringAfterLast(slots.get(TIME_TOWER_SLOT).getName().getString(), ' ').equals("XV");
String timeTowerLore = ItemUtils.getConcatenatedLore(slots.get(TIME_TOWER_SLOT));
Matcher timeTowerMultiplierMatcher = TIME_TOWER_MULTIPLIER_PATTERN.matcher(timeTowerLore);
- RegexUtils.getDoubleFromMatcher(timeTowerMultiplierMatcher).ifPresent(d -> timeTowerMultiplier = d);
+ RegexUtils.findDoubleFromMatcher(timeTowerMultiplierMatcher).ifPresent(d -> timeTowerMultiplier = d);
Matcher timeTowerStatusMatcher = TIME_TOWER_STATUS_PATTERN.matcher(timeTowerLore);
if (timeTowerStatusMatcher.find(timeTowerMultiplierMatcher.hasMatch() ? timeTowerMultiplierMatcher.end() : 0)) {
isTimeTowerActive = timeTowerStatusMatcher.group(1).equals("ACTIVE");
@@ -199,10 +199,10 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too
if (totalCps < 0 || totalCpsMultiplier < 0) return Optional.empty(); //We need these 2 to calculate the increase in cps.
Matcher multiplierIncreaseMatcher = MULTIPLIER_INCREASE_PATTERN.matcher(coachLore);
- OptionalDouble currentCpsMultiplier = RegexUtils.getDoubleFromMatcher(multiplierIncreaseMatcher);
+ OptionalDouble currentCpsMultiplier = RegexUtils.findDoubleFromMatcher(multiplierIncreaseMatcher);
if (currentCpsMultiplier.isEmpty()) return Optional.empty();
- OptionalDouble nextCpsMultiplier = RegexUtils.getDoubleFromMatcher(multiplierIncreaseMatcher);
+ OptionalDouble nextCpsMultiplier = RegexUtils.findDoubleFromMatcher(multiplierIncreaseMatcher);
if (nextCpsMultiplier.isEmpty()) { //This means that the coach isn't hired yet.
nextCpsMultiplier = currentCpsMultiplier; //So the first instance of the multiplier is actually the amount we'll get upon upgrading.
currentCpsMultiplier = OptionalDouble.of(0.0); //And so, we can re-assign values to the variables to make the calculation more readable.
@@ -210,7 +210,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too
Matcher costMatcher = COST_PATTERN.matcher(coachLore);
Matcher levelMatcher = COACH_LEVEL_PATTERN.matcher(coachItem.getName().getString());
- OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher, multiplierIncreaseMatcher.hasMatch() ? multiplierIncreaseMatcher.end() : 0); //Cost comes after the multiplier line
+ OptionalLong cost = RegexUtils.findLongFromMatcher(costMatcher, multiplierIncreaseMatcher.hasMatch() ? multiplierIncreaseMatcher.end() : 0); //Cost comes after the multiplier line
int level = -1;
if (levelMatcher.find()) {
level = RomanNumerals.romanToDecimal(levelMatcher.group(1));
@@ -222,18 +222,18 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too
private Optional<Rabbit> getRabbit(ItemStack item, int slot) {
String lore = ItemUtils.getConcatenatedLore(item);
Matcher cpsMatcher = CPS_INCREASE_PATTERN.matcher(lore);
- OptionalInt currentCps = RegexUtils.getIntFromMatcher(cpsMatcher);
+ OptionalInt currentCps = RegexUtils.findIntFromMatcher(cpsMatcher);
if (currentCps.isEmpty()) return Optional.empty();
- OptionalInt nextCps = RegexUtils.getIntFromMatcher(cpsMatcher);
+ OptionalInt nextCps = RegexUtils.findIntFromMatcher(cpsMatcher);
if (nextCps.isEmpty()) {
nextCps = currentCps; //This means that the rabbit isn't hired yet.
currentCps = OptionalInt.of(0); //So the first instance of the cps is actually the amount we'll get upon hiring.
}
Matcher costMatcher = COST_PATTERN.matcher(lore);
- OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0); //Cost comes after the cps line
+ OptionalLong cost = RegexUtils.findLongFromMatcher(costMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0); //Cost comes after the cps line
Matcher levelMatcher = LEVEL_PATTERN.matcher(lore);
- int level = RegexUtils.getIntFromMatcher(levelMatcher).orElse(0) - 1;
+ int level = RegexUtils.findIntFromMatcher(levelMatcher).orElse(0) - 1;
if (cost.isEmpty()) return Optional.empty();
return Optional.of(new Rabbit((nextCps.getAsInt() - currentCps.getAsInt()) * (totalCpsMultiplier < 0 ? 1 : totalCpsMultiplier), cost.getAsLong(), slot, level));
}
@@ -272,7 +272,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too
String lore = ItemUtils.concatenateLore(lines);
Matcher costMatcher = COST_PATTERN.matcher(lore);
- OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher);
+ OptionalLong cost = RegexUtils.findLongFromMatcher(costMatcher);
//Available on all items with a chocolate cost
if (cost.isPresent()) shouldAddLine |= addUpgradeTimerToLore(lines, cost.getAsLong());
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java
index 240a30ed..e4a85ec1 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java
@@ -50,7 +50,7 @@ public class EssenceShopPrice extends SimpleTooltipAdder {
public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) {
String lore = ItemUtils.concatenateLore(lines);
Matcher essenceMatcher = ESSENCE_PATTERN.matcher(lore);
- OptionalLong cost = RegexUtils.getLongFromMatcher(essenceMatcher);
+ OptionalLong cost = RegexUtils.findLongFromMatcher(essenceMatcher);
if (cost.isEmpty()) return;
String type = essenceMatcher.group("type");
diff --git a/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java b/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java
index 5b91a80b..3d6b8842 100644
--- a/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java
@@ -9,14 +9,14 @@ public class RegexUtils {
/**
* @return An OptionalLong of the first group in the matcher, or an empty OptionalLong if the matcher doesn't find anything.
*/
- public static OptionalLong getLongFromMatcher(Matcher matcher) {
- return getLongFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0);
+ public static OptionalLong findLongFromMatcher(Matcher matcher) {
+ return findLongFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0);
}
/**
* @return An OptionalLong of the first group in the matcher, or an empty OptionalLong if the matcher doesn't find anything.
*/
- public static OptionalLong getLongFromMatcher(Matcher matcher, int startingIndex) {
+ public static OptionalLong findLongFromMatcher(Matcher matcher, int startingIndex) {
if (!matcher.find(startingIndex)) return OptionalLong.empty();
return OptionalLong.of(Long.parseLong(matcher.group(1).replace(",", "")));
}
@@ -24,31 +24,39 @@ public class RegexUtils {
/**
* @return An OptionalInt of the first group in the matcher, or an empty OptionalInt if the matcher doesn't find anything.
*/
- public static OptionalInt getIntFromMatcher(Matcher matcher) {
- return getIntFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0);
+ public static OptionalInt findIntFromMatcher(Matcher matcher) {
+ return findIntFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0);
}
/**
* @return An OptionalInt of the first group in the matcher, or an empty OptionalInt if the matcher doesn't find anything.
*/
- public static OptionalInt getIntFromMatcher(Matcher matcher, int startingIndex) {
+ public static OptionalInt findIntFromMatcher(Matcher matcher, int startingIndex) {
if (!matcher.find(startingIndex)) return OptionalInt.empty();
- return OptionalInt.of(Integer.parseInt(matcher.group(1).replace(",", "")));
+ return OptionalInt.of(parseIntFromMatcher(matcher, 1));
+ }
+
+ public static int parseIntFromMatcher(Matcher matcher, int group) {
+ return Integer.parseInt(matcher.group(group).replace(",", ""));
+ }
+
+ public static int parseIntFromMatcher(Matcher matcher, String group) {
+ return Integer.parseInt(matcher.group(group).replace(",", ""));
}
/**
* @return An OptionalDouble of the first group in the matcher, or an empty OptionalDouble if the matcher doesn't find anything.
* @implNote Assumes the decimal separator is `.`
*/
- public static OptionalDouble getDoubleFromMatcher(Matcher matcher) {
- return getDoubleFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0);
+ public static OptionalDouble findDoubleFromMatcher(Matcher matcher) {
+ return findDoubleFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0);
}
/**
* @return An OptionalDouble of the first group in the matcher, or an empty OptionalDouble if the matcher doesn't find anything.
* @implNote Assumes the decimal separator is `.`
*/
- public static OptionalDouble getDoubleFromMatcher(Matcher matcher, int startingIndex) {
+ public static OptionalDouble findDoubleFromMatcher(Matcher matcher, int startingIndex) {
if (!matcher.find(startingIndex)) return OptionalDouble.empty();
return OptionalDouble.of(Double.parseDouble(matcher.group(1).replace(",", "")));
}