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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
package me.Danker.features;
import me.Danker.DankersSkyblockMod;
import me.Danker.commands.MoveCommand;
import me.Danker.commands.ScaleCommand;
import me.Danker.commands.ToggleCommand;
import me.Danker.events.RenderOverlay;
import me.Danker.handlers.TextRenderer;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.apache.commons.lang3.time.StopWatch;
import java.text.NumberFormat;
import java.util.Locale;
public class SkillTracker {
static String lastSkill = "Farming";
public static boolean showSkillTracker;
public static StopWatch skillStopwatch = new StopWatch();
static double farmingXP = 0;
public static double farmingXPGained = 0;
static double miningXP = 0;
public static double miningXPGained = 0;
static double combatXP = 0;
public static double combatXPGained = 0;
static double foragingXP = 0;
public static double foragingXPGained = 0;
static double fishingXP = 0;
public static double fishingXPGained = 0;
static double enchantingXP = 0;
public static double enchantingXPGained = 0;
static double alchemyXP = 0;
public static double alchemyXPGained = 0;
static double xpLeft = 0;
static double timeSinceGained = 0;
public static String SKILL_TRACKER_COLOUR;
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onChat(ClientChatReceivedEvent event) {
if (!Utils.inSkyblock || event.type != 2) return;
String[] actionBarSections = event.message.getUnformattedText().split(" {3,}");
for (String section : actionBarSections) {
if (section.contains("+") && section.contains("(") && section.contains(")") && !section.contains("Runecrafting") && !section.contains("Carpentry")) {
if (ToggleCommand.autoSkillTrackerToggled && System.currentTimeMillis() / 1000 - timeSinceGained <= 2) {
if (skillStopwatch.isStarted() && skillStopwatch.isSuspended()) {
skillStopwatch.resume();
} else if (!skillStopwatch.isStarted()) {
skillStopwatch.start();
}
}
timeSinceGained = System.currentTimeMillis() / 1000;
String skill = section.substring(section.indexOf(" ") + 1, section.lastIndexOf(" "));
double totalXP;
if (section.contains("/")) {
int limit = section.contains("Farming") || section.contains("Enchanting") || section.contains("Mining") || section.contains("Combat") ? 60 : 50;
double currentXP = Double.parseDouble(section.substring(section.indexOf("(") + 1, section.indexOf("/")).replace(",", ""));
int xpToLevelUp;
String nextLevelXpString = section.substring(section.indexOf("/") + 1, section.indexOf(")")).replaceAll(",", "");
if (nextLevelXpString.contains("k")) {
xpToLevelUp = Integer.parseInt(nextLevelXpString.substring(0, nextLevelXpString.indexOf("k"))) * 1000;
} else {
xpToLevelUp = Integer.parseInt(nextLevelXpString);
}
xpLeft = xpToLevelUp - currentXP;
int previousXP = Utils.getPastXpEarned(xpToLevelUp, limit);
totalXP = currentXP + previousXP;
} else {
if (!Utils.skillsInitialized()) {
return;
}
int level = 1;
if (section.contains("Farming")) {
level = DankersSkyblockMod.farmingLevel;
} else if (section.contains("Mining")) {
level = DankersSkyblockMod.miningLevel;
} else if (section.contains("Combat")) {
level = DankersSkyblockMod.combatLevel;
} else if (section.contains("Foraging")) {
level = DankersSkyblockMod.foragingLevel;
} else if (section.contains("Fishing")) {
level = DankersSkyblockMod.fishingLevel;
} else if (section.contains("Enchanting")) {
level = DankersSkyblockMod.enchantingLevel;
} else if (section.contains("Alchemy")) {
level = DankersSkyblockMod.alchemyLevel;
} else if (section.contains("Carpentry")) {
level = DankersSkyblockMod.carpentryLevel;
}
totalXP = Utils.getTotalXpEarned(level, Double.parseDouble(section.substring(section.indexOf("(") + 1, section.indexOf("%"))));
xpLeft = Utils.getTotalXpEarned(level + 1, 0) - totalXP;
}
switch (skill) {
case "Farming":
lastSkill = "Farming";
if (farmingXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) farmingXPGained += totalXP - farmingXP;
}
farmingXP = totalXP;
break;
case "Mining":
lastSkill = "Mining";
if (miningXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) miningXPGained += totalXP - miningXP;
}
miningXP = totalXP;
break;
case "Combat":
lastSkill = "Combat";
if (combatXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) combatXPGained += totalXP - combatXP;
}
combatXP = totalXP;
break;
case "Foraging":
lastSkill = "Foraging";
if (foragingXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) foragingXPGained += totalXP - foragingXP;
}
foragingXP = totalXP;
break;
case "Fishing":
lastSkill = "Fishing";
if (fishingXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) fishingXPGained += totalXP - fishingXP;
}
fishingXP = totalXP;
break;
case "Enchanting":
lastSkill = "Enchanting";
if (enchantingXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) enchantingXPGained += totalXP - enchantingXP;
}
enchantingXP = totalXP;
break;
case "Alchemy":
lastSkill = "Alchemy";
if (alchemyXP != 0) {
if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) alchemyXPGained += totalXP - alchemyXP;
}
alchemyXP = totalXP;
break;
default:
System.err.println("Unknown skill.");
}
}
}
}
@SubscribeEvent
public void renderPlayerInfo(RenderOverlay event) {
if (showSkillTracker && Utils.inSkyblock) {
if (!Utils.skillsInitialized()) {
new TextRenderer(Minecraft.getMinecraft(), EnumChatFormatting.RED + "Please open the skill menu to use skill features.", MoveCommand.skillTrackerXY[0], MoveCommand.skillTrackerXY[0], ScaleCommand.skillTrackerScale);
return;
}
int xpPerHour;
double xpToShow = 0;
switch (lastSkill) {
case "Farming":
xpToShow = farmingXPGained;
break;
case "Mining":
xpToShow = miningXPGained;
break;
case "Combat":
xpToShow = combatXPGained;
break;
case "Foraging":
xpToShow = foragingXPGained;
break;
case "Fishing":
xpToShow = fishingXPGained;
break;
case "Enchanting":
xpToShow = enchantingXPGained;
break;
case "Alchemy":
xpToShow = alchemyXPGained;
break;
default:
System.err.println("Unknown skill in rendering.");
}
xpPerHour = (int) Math.round(xpToShow / ((skillStopwatch.getTime() + 1) / 3600000d));
String skillTrackerText = SKILL_TRACKER_COLOUR + lastSkill + " XP Earned: " + NumberFormat.getNumberInstance(Locale.US).format(xpToShow) + "\n" +
SKILL_TRACKER_COLOUR + "Time Elapsed: " + Utils.getTimeBetween(0, skillStopwatch.getTime() / 1000d) + "\n" +
SKILL_TRACKER_COLOUR + "XP Per Hour: " + NumberFormat.getIntegerInstance(Locale.US).format(xpPerHour);
if (xpLeft >= 0) {
String time = xpPerHour == 0 ? "Never" : Utils.getTimeBetween(0, xpLeft / (xpPerHour / 3600D));
skillTrackerText += "\n" + SKILL_TRACKER_COLOUR + "Time Until Next Level: " + time;
}
if (!skillStopwatch.isStarted() || skillStopwatch.isSuspended()) {
skillTrackerText += "\n" + EnumChatFormatting.RED + "PAUSED";
}
new TextRenderer(Minecraft.getMinecraft(), skillTrackerText, MoveCommand.skillTrackerXY[0], MoveCommand.skillTrackerXY[1], ScaleCommand.skillTrackerScale);
}
}
@SubscribeEvent
public void onKey(InputEvent.KeyInputEvent event) {
if (!Utils.inSkyblock) return;
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
if (DankersSkyblockMod.keyBindings[2].isPressed()) {
if (skillStopwatch.isStarted() && skillStopwatch.isSuspended()) {
skillStopwatch.resume();
player.addChatMessage(new ChatComponentText(DankersSkyblockMod.MAIN_COLOUR + "Skill tracker started."));
} else if (!skillStopwatch.isStarted()) {
skillStopwatch.start();
player.addChatMessage(new ChatComponentText(DankersSkyblockMod.MAIN_COLOUR + "Skill tracker started."));
} else if (skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) {
skillStopwatch.suspend();
player.addChatMessage(new ChatComponentText(DankersSkyblockMod.MAIN_COLOUR + "Skill tracker paused."));
}
}
}
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
if (event.gui instanceof GuiChest && ToggleCommand.autoSkillTrackerToggled && skillStopwatch.isStarted() && !skillStopwatch.isSuspended()) {
skillStopwatch.suspend();
}
}
}
|