diff options
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/dungeons')
3 files changed, 297 insertions, 286 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java index 1c30045..f0f58da 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java @@ -1,50 +1,50 @@ package com.thatgravyboat.skyblockhud.dungeons; public enum Classes { - H("Healer", "H", 154), - M("Mage", "M", 90), - B("Berserk", "B", 122), - A("Archer", "A", 58), - T("Tank", "T", 186); + H("Healer", "H", 154), + M("Mage", "M", 90), + B("Berserk", "B", 122), + A("Archer", "A", 58), + T("Tank", "T", 186); - private final String displayName; - private final String classId; - private final int textureY; + private final String displayName; + private final String classId; + private final int textureY; - Classes(String name, String id, int textureY) { - this.displayName = name; - this.classId = id; - this.textureY = textureY; - } + Classes(String name, String id, int textureY) { + this.displayName = name; + this.classId = id; + this.textureY = textureY; + } - public String getDisplayName() { - return this.displayName; - } + public String getDisplayName() { + return this.displayName; + } - public String getClassId() { - return this.classId; - } + public String getClassId() { + return this.classId; + } - public int getTextureY() { - return this.textureY; - } + public int getTextureY() { + return this.textureY; + } - public static Classes findClass(String input) { - if (input.length() == 1) { - try { - return Classes.valueOf(input.toUpperCase()); - } catch (IllegalArgumentException ignored) {} - } else if (input.length() == 3) { - try { - return Classes.valueOf( - input.replace("[", "").replace("]", "").toUpperCase() - ); - } catch (IllegalArgumentException ignored) {} - } else { - for (Classes clazz : Classes.values()) { - if (clazz.displayName.equalsIgnoreCase(input)) return clazz; - } + public static Classes findClass(String input) { + if (input.length() == 1) { + try { + return Classes.valueOf(input.toUpperCase()); + } catch (IllegalArgumentException ignored) {} + } else if (input.length() == 3) { + try { + return Classes.valueOf( + input.replace("[", "").replace("]", "").toUpperCase() + ); + } catch (IllegalArgumentException ignored) {} + } else { + for (Classes clazz : Classes.values()) { + if (clazz.displayName.equalsIgnoreCase(input)) return clazz; + } + } + return B; } - return B; - } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java index 5307273..0c9cb2f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java @@ -13,225 +13,236 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class DungeonHandler { - private static final HashMap<String, DungeonPlayer> dungeonPlayersMap = new HashMap<>(); - private static int dungeonTime = 0; - private static int dungeonCleared = 0; - private static boolean bloodKey = false; - private static int witherKeys = 0; - private static int maxSecrets = 0; - private static int secrets = 0; - private static int totalSecrets = 0; - private static int deaths = 0; - private static int crypts = 0; - - private static final Pattern DungeonPlayerRegex = Pattern.compile( - "^\\[([HMBAT])] ([\\w]+) ([0-9]+|DEAD)$" - ); - - @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { - if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { - DungeonHandler.checkForDungeonTime(event.formattedLine); - DungeonHandler.checkForDungeonCleared(event.formattedLine); - DungeonHandler.checkForDungeonKeys(event.formattedLine, event.rawLine); - DungeonHandler.checkForDungeonPlayers( - event.formattedLine, - Minecraft.getMinecraft() - ); - } - } - - @SubscribeEvent - public void onSidebarPost(SidebarPostEvent event) { - if (!LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { - DungeonHandler.clearDungeonStats(); - } - } - - public static void checkForDungeonPlayers(String scoreLine, Minecraft mc) { - Matcher dungeonMatcher = DungeonPlayerRegex.matcher(scoreLine); - if (dungeonMatcher.matches() && DungeonHandler.dungeonTime > 0) { - Classes playerClass = Classes.valueOf(dungeonMatcher.group(1)); - String displayName = dungeonMatcher.group(2); - String health = dungeonMatcher.group(3); - if ( - !mc.thePlayer - .getName() - .toLowerCase() - .startsWith(displayName.toLowerCase().trim()) - ) { - int healthNum = 0; - if (!health.equalsIgnoreCase("dead")) { - try { - healthNum = Integer.parseInt(health); - } catch (NumberFormatException ignored) {} + private static final HashMap<String, DungeonPlayer> dungeonPlayersMap = new HashMap<>(); + private static int dungeonTime = 0; + private static int dungeonCleared = 0; + private static boolean bloodKey = false; + private static int witherKeys = 0; + private static int maxSecrets = 0; + private static int secrets = 0; + private static int totalSecrets = 0; + private static int deaths = 0; + private static int crypts = 0; + + private static final Pattern DungeonPlayerRegex = Pattern.compile( + "^\\[([HMBAT])] ([\\w]+) ([0-9]+|DEAD)$" + ); + + @SubscribeEvent + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { + if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { + DungeonHandler.checkForDungeonTime(event.formattedLine); + DungeonHandler.checkForDungeonCleared(event.formattedLine); + DungeonHandler.checkForDungeonKeys( + event.formattedLine, + event.rawLine + ); + DungeonHandler.checkForDungeonPlayers( + event.formattedLine, + Minecraft.getMinecraft() + ); } - DungeonPlayer player = new DungeonPlayer( - playerClass, - displayName, - healthNum, - health.equalsIgnoreCase("dead") - ); - dungeonPlayersMap.put(displayName.toLowerCase(), player); - } - } - } - - public static void checkForDungeonTime(String scoreLine) { - if (scoreLine.toLowerCase().trim().contains("time elapsed:")) { - String timeLine = scoreLine - .toLowerCase() - .trim() - .replace("time elapsed:", ""); - String[] times = timeLine.split("m "); - int time = 0; - try { - time += - Integer.parseInt(times[0].replace(" ", "").replace("m", "")) * 60; - time += Integer.parseInt(times[1].replace(" ", "").replace("s", "")); - } catch (NumberFormatException ignored) {} - dungeonTime = time; - } - } - - public static void checkForDungeonCleared(String scoreline) { - if (scoreline.toLowerCase().trim().contains("dungeon cleared:")) { - String dungeonClearedText = scoreline - .toLowerCase() - .trim() - .replace("dungeon cleared:", "") - .replace(" ", "") - .replace("%", ""); - try { - dungeonCleared = Integer.parseInt(dungeonClearedText); - } catch (NumberFormatException ignored) {} - } - } - - public static void checkForDungeonKeys(String scoreline, String rawString) { - if (scoreline.toLowerCase().trim().contains("keys:")) { - String dungeonClearedText = scoreline - .toLowerCase() - .trim() - .replace("keys:", "") - .replace(" ", "") - .replace("x", ""); - bloodKey = rawString.contains("\u2713"); - try { - witherKeys = Integer.parseInt(dungeonClearedText); - } catch (NumberFormatException ignored) {} - } - } - - public static void parseSecrets(String statusBar) { - boolean hasSecrets = false; - String[] parts = statusBar.split(" {4,}"); - for (String part : parts) { - if ( - part.toLowerCase().contains("secrets") && - !statusBar.toLowerCase().contains("no secrets") - ) { - hasSecrets = true; - try { - String secret = Utils - .removeColor(part.replace("Secrets", "")) - .replace(" ", ""); - maxSecrets = Integer.parseInt(secret.split("/")[1]); - secrets = Integer.parseInt(secret.split("/")[0]); - } catch (NumberFormatException ignored) {} - } - } - if (!hasSecrets) { - maxSecrets = 0; - secrets = 0; - } - } - - public static void parseTotalSecrets(String playerName) { - if (playerName.toLowerCase().contains("secrets found:")) { - String totalSecret = Utils - .removeColor(playerName.toLowerCase().replace("secrets found:", "")) - .replace(" ", ""); - try { - totalSecrets = Integer.parseInt(totalSecret); - } catch (NumberFormatException ignored) {} - } - } - - public static void parseDeaths(String playerName) { - if (playerName.toLowerCase().contains("deaths:")) { - String death = Utils - .removeColor(playerName.toLowerCase().replace("deaths:", "")) - .replace("(", "") - .replace(")", "") - .replace(" ", ""); - try { - deaths = Integer.parseInt(death); - } catch (NumberFormatException ignored) {} - } - } - - public static void parseCrypts(String playerName) { - if (playerName.toLowerCase().contains("crypts:")) { - String crypt = Utils - .removeColor(playerName.toLowerCase().replace("crypts:", "")) - .replace(" ", ""); - try { - crypts = Integer.parseInt(crypt); - } catch (NumberFormatException ignored) {} - } - } - - public static void clearDungeonStats() { - dungeonPlayersMap.clear(); - dungeonTime = 0; - dungeonCleared = 0; - bloodKey = false; - witherKeys = 0; - maxSecrets = 0; - secrets = 0; - totalSecrets = 0; - deaths = 0; - crypts = 0; - } - - public static HashMap<String, DungeonPlayer> getDungeonPlayers() { - return dungeonPlayersMap; - } - - public static int getDungeonTime() { - return dungeonTime; - } - - public static int getDungeonCleared() { - return dungeonCleared; - } - - public static int getWitherKeys() { - return witherKeys; - } - - public static boolean hasBloodkey() { - return bloodKey; - } - - public static int getMaxSecrets() { - return maxSecrets; - } - - public static int getSecrets() { - return secrets; - } - - public static int getDeaths() { - return deaths; - } - - public static int getTotalSecrets() { - return totalSecrets; - } - - public static int getCrypts() { - return crypts; - } + } + + @SubscribeEvent + public void onSidebarPost(SidebarPostEvent event) { + if (!LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { + DungeonHandler.clearDungeonStats(); + } + } + + public static void checkForDungeonPlayers(String scoreLine, Minecraft mc) { + Matcher dungeonMatcher = DungeonPlayerRegex.matcher(scoreLine); + if (dungeonMatcher.matches() && DungeonHandler.dungeonTime > 0) { + Classes playerClass = Classes.valueOf(dungeonMatcher.group(1)); + String displayName = dungeonMatcher.group(2); + String health = dungeonMatcher.group(3); + if ( + !mc.thePlayer + .getName() + .toLowerCase() + .startsWith(displayName.toLowerCase().trim()) + ) { + int healthNum = 0; + if (!health.equalsIgnoreCase("dead")) { + try { + healthNum = Integer.parseInt(health); + } catch (NumberFormatException ignored) {} + } + DungeonPlayer player = new DungeonPlayer( + playerClass, + displayName, + healthNum, + health.equalsIgnoreCase("dead") + ); + dungeonPlayersMap.put(displayName.toLowerCase(), player); + } + } + } + + public static void checkForDungeonTime(String scoreLine) { + if (scoreLine.toLowerCase().trim().contains("time elapsed:")) { + String timeLine = scoreLine + .toLowerCase() + .trim() + .replace("time elapsed:", ""); + String[] times = timeLine.split("m "); + int time = 0; + try { + time += + Integer.parseInt( + times[0].replace(" ", "").replace("m", "") + ) * + 60; + time += + Integer.parseInt( + times[1].replace(" ", "").replace("s", "") + ); + } catch (NumberFormatException ignored) {} + dungeonTime = time; + } + } + + public static void checkForDungeonCleared(String scoreline) { + if (scoreline.toLowerCase().trim().contains("dungeon cleared:")) { + String dungeonClearedText = scoreline + .toLowerCase() + .trim() + .replace("dungeon cleared:", "") + .replace(" ", "") + .replace("%", ""); + try { + dungeonCleared = Integer.parseInt(dungeonClearedText); + } catch (NumberFormatException ignored) {} + } + } + + public static void checkForDungeonKeys(String scoreline, String rawString) { + if (scoreline.toLowerCase().trim().contains("keys:")) { + String dungeonClearedText = scoreline + .toLowerCase() + .trim() + .replace("keys:", "") + .replace(" ", "") + .replace("x", ""); + bloodKey = rawString.contains("\u2713"); + try { + witherKeys = Integer.parseInt(dungeonClearedText); + } catch (NumberFormatException ignored) {} + } + } + + public static void parseSecrets(String statusBar) { + boolean hasSecrets = false; + String[] parts = statusBar.split(" {4,}"); + for (String part : parts) { + if ( + part.toLowerCase().contains("secrets") && + !statusBar.toLowerCase().contains("no secrets") + ) { + hasSecrets = true; + try { + String secret = Utils + .removeColor(part.replace("Secrets", "")) + .replace(" ", ""); + maxSecrets = Integer.parseInt(secret.split("/")[1]); + secrets = Integer.parseInt(secret.split("/")[0]); + } catch (NumberFormatException ignored) {} + } + } + if (!hasSecrets) { + maxSecrets = 0; + secrets = 0; + } + } + + public static void parseTotalSecrets(String playerName) { + if (playerName.toLowerCase().contains("secrets found:")) { + String totalSecret = Utils + .removeColor( + playerName.toLowerCase().replace("secrets found:", "") + ) + .replace(" ", ""); + try { + totalSecrets = Integer.parseInt(totalSecret); + } catch (NumberFormatException ignored) {} + } + } + + public static void parseDeaths(String playerName) { + if (playerName.toLowerCase().contains("deaths:")) { + String death = Utils + .removeColor(playerName.toLowerCase().replace("deaths:", "")) + .replace("(", "") + .replace(")", "") + .replace(" ", ""); + try { + deaths = Integer.parseInt(death); + } catch (NumberFormatException ignored) {} + } + } + + public static void parseCrypts(String playerName) { + if (playerName.toLowerCase().contains("crypts:")) { + String crypt = Utils + .removeColor(playerName.toLowerCase().replace("crypts:", "")) + .replace(" ", ""); + try { + crypts = Integer.parseInt(crypt); + } catch (NumberFormatException ignored) {} + } + } + + public static void clearDungeonStats() { + dungeonPlayersMap.clear(); + dungeonTime = 0; + dungeonCleared = 0; + bloodKey = false; + witherKeys = 0; + maxSecrets = 0; + secrets = 0; + totalSecrets = 0; + deaths = 0; + crypts = 0; + } + + public static HashMap<String, DungeonPlayer> getDungeonPlayers() { + return dungeonPlayersMap; + } + + public static int getDungeonTime() { + return dungeonTime; + } + + public static int getDungeonCleared() { + return dungeonCleared; + } + + public static int getWitherKeys() { + return witherKeys; + } + + public static boolean hasBloodkey() { + return bloodKey; + } + + public static int getMaxSecrets() { + return maxSecrets; + } + + public static int getSecrets() { + return secrets; + } + + public static int getDeaths() { + return deaths; + } + + public static int getTotalSecrets() { + return totalSecrets; + } + + public static int getCrypts() { + return crypts; + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java index 2326090..f517655 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java @@ -2,36 +2,36 @@ package com.thatgravyboat.skyblockhud.dungeons; public class DungeonPlayer { - private final Classes dungeonClass; - private final String name; - private final int health; - private final boolean dead; + private final Classes dungeonClass; + private final String name; + private final int health; + private final boolean dead; - public DungeonPlayer( - Classes playersClass, - String playersName, - int playersHealth, - boolean isDead - ) { - this.dungeonClass = playersClass; - this.name = playersName; - this.health = isDead ? 0 : playersHealth; - this.dead = isDead; - } + public DungeonPlayer( + Classes playersClass, + String playersName, + int playersHealth, + boolean isDead + ) { + this.dungeonClass = playersClass; + this.name = playersName; + this.health = isDead ? 0 : playersHealth; + this.dead = isDead; + } - public Classes getDungeonClass() { - return this.dungeonClass; - } + public Classes getDungeonClass() { + return this.dungeonClass; + } - public String getName() { - return this.name; - } + public String getName() { + return this.name; + } - public int getHealth() { - return this.dead ? 0 : this.health; - } + public int getHealth() { + return this.dead ? 0 : this.health; + } - public boolean isDead() { - return this.dead; - } + public boolean isDead() { + return this.dead; + } } |