1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
package com.thatgravyboat.skyblockhud.dungeons;
import com.thatgravyboat.skyblockhud.Utils;
import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent;
import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent;
import com.thatgravyboat.skyblockhud.location.LocationHandler;
import com.thatgravyboat.skyblockhud.location.Locations;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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){}
}
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; }
}
|