aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/handlers
diff options
context:
space:
mode:
authorThatGravyBoat <thatgravyboat@gmail.com>2021-07-06 18:18:26 -0230
committerThatGravyBoat <thatgravyboat@gmail.com>2021-07-06 18:18:26 -0230
commit002dfdd18b908bda3e784dd303c15bbef79cdd2e (patch)
tree0c732879b7a851a4782205c2da5027944eb69acf /src/main/java/com/thatgravyboat/skyblockhud/handlers
parenta4131a48e58cf55587d1ea1838e1ff2a5d692080 (diff)
downloadSkyblockHud-Death-Defied-002dfdd18b908bda3e784dd303c15bbef79cdd2e.tar.gz
SkyblockHud-Death-Defied-002dfdd18b908bda3e784dd303c15bbef79cdd2e.tar.bz2
SkyblockHud-Death-Defied-002dfdd18b908bda3e784dd303c15bbef79cdd2e.zip
Switched SlayerHandler to use regex instead of .replace and .split
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/handlers')
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java
index 36833cc..b34a156 100644
--- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java
+++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java
@@ -7,8 +7,13 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.Arrays;
import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class SlayerHandler {
+ //Optional Characters are required because Hypixel dumb and cuts off text
+ private static final Pattern COMBAT_XP_REGEX = Pattern.compile("\\(([\\d,]+)/([\\dkm]+)\\) comb?a?t? x?p?");
+ private static final Pattern KILLS_REGEX = Pattern.compile("(\\d+)/(\\d+) kills?");
public enum slayerTypes {
@@ -77,25 +82,32 @@ public class SlayerHandler {
@SubscribeEvent
public void onSidebarLineUpdate(SidebarLineUpdateEvent event){
+ if (!isDoingSlayer && event.formattedLine.equals("Slayer Quest")) isDoingSlayer = true;
+
if (isDoingSlayer){
String line = event.formattedLine.toLowerCase();
- if (line.contains("/") && (line.contains("kills") || (line.contains("xp")))){
+ Matcher killMatcher = KILLS_REGEX.matcher(line);
+ Matcher xpMatcher = COMBAT_XP_REGEX.matcher(line);
+
+ if (killMatcher.find()){
+ SlayerHandler.bossSlain = false;
+ SlayerHandler.isKillingBoss = false;
+ try {
+ progress = Integer.parseInt(killMatcher.group(1));
+ } catch (Exception ignored){}
+ try {
+ maxKills = Integer.parseInt(killMatcher.group(2));
+ } catch (Exception ignored){}
+ }else if (xpMatcher.find()){
SlayerHandler.bossSlain = false;
SlayerHandler.isKillingBoss = false;
- String[] killsText = line.replace(" ", "").replace("kills", "").split("/");
- if (line.contains("xp"))
- killsText = line.replace(" ", "")
- .replace("(", "")
- .replace(")", "")
- .replace("combatxp", "")
- .split("/");
try {
- progress = Integer.parseInt(killsText[0]);
+ progress = Integer.parseInt(xpMatcher.group(1));
} catch (Exception ignored){}
try {
- maxKills = Integer.parseInt(killsText[1]);
+ maxKills = Integer.parseInt(xpMatcher.group(2).replace("k", "")) * (xpMatcher.group(2).contains("k") ? 1000 : xpMatcher.group(2).contains("m") ? 1000000 : 1);
} catch (Exception ignored){}
- }else if(line.contains("slay the boss")) {
+ } else if(line.contains("slay the boss")) {
SlayerHandler.bossSlain = false;
SlayerHandler.isKillingBoss = true;
SlayerHandler.maxKills = 0;