aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/loot/LootTracker.java
blob: 27f077931168ad8176a205099ea63f5be6fa64be (plain)
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
package me.Danker.features.loot;

import me.Danker.handlers.ConfigHandler;
import me.Danker.handlers.ScoreboardHandler;
import me.Danker.utils.Utils;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.List;

public class LootTracker {

    public static long itemsChecked = 0;

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onSound(PlaySoundEvent event) {
        if (!Utils.inSkyblock) return;
        if (event.name.equals("note.pling")) {
            // Don't check twice within 3 seconds
            long checkItemsNow = System.currentTimeMillis() / 1000;
            if (checkItemsNow - itemsChecked < 3) return;

            List<String> scoreboard = ScoreboardHandler.getSidebarLines();

            for (String line : scoreboard) {
                String cleanedLine = ScoreboardHandler.cleanSB(line);
                // If Hypixel lags and scoreboard doesn't update
                if (cleanedLine.contains("Boss slain!") || cleanedLine.contains("Slay the boss!")) {
                    int itemTeeth = Utils.getItems("Wolf Tooth");
                    int itemWebs = Utils.getItems("Tarantula Web");
                    int itemRev = Utils.getItems("Revenant Flesh");
                    int itemNullSphere = Utils.getItems("Null Sphere");
                    int itemDerelictAshe = Utils.getItems("Derelict Ashe");

                    // If no items, are detected, allow check again. Should fix items not being found
                    if (itemTeeth + itemWebs + itemRev + itemNullSphere + itemDerelictAshe > 0) {
                        itemsChecked = System.currentTimeMillis() / 1000;
                        WolfTracker.wolfTeeth += itemTeeth;
                        SpiderTracker.spiderWebs += itemWebs;
                        ZombieTracker.zombieRevFlesh += itemRev;
                        EndermanTracker.endermanNullSpheres += itemNullSphere;
                        BlazeTracker.derelictAshes += itemDerelictAshe;
                        WolfTracker.wolfTeethSession += itemTeeth;
                        SpiderTracker.spiderWebsSession += itemWebs;
                        ZombieTracker.zombieRevFleshSession += itemRev;
                        EndermanTracker.endermanNullSpheresSession += itemNullSphere;
                        BlazeTracker.derelictAshesSession += itemDerelictAshe;

                        ConfigHandler.writeIntConfig("wolf", "teeth", WolfTracker.wolfTeeth);
                        ConfigHandler.writeIntConfig("spider", "web", SpiderTracker.spiderWebs);
                        ConfigHandler.writeIntConfig("zombie", "revFlesh", ZombieTracker.zombieRevFlesh);
                        ConfigHandler.writeIntConfig("enderman", "nullSpheres", EndermanTracker.endermanNullSpheres);
                        ConfigHandler.writeIntConfig("blaze", "derelictAshe", BlazeTracker.derelictAshes);
                    }
                }
            }
        }
    }

    public static int getAmountfromMessage(String message) {
        if (message.charAt(message.indexOf("(") + 2) == 'x' || message.charAt(message.indexOf("(") + 3) == 'x') {
            return Integer.parseInt(message.substring(message.indexOf("(") + 1, message.indexOf("x")));
        } else {
            return 1;
        }
    }
    
}