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

import me.Danker.events.PacketReadEvent;
import me.Danker.handlers.ConfigHandler;
import me.Danker.utils.Utils;
import net.minecraft.network.play.server.S29PacketSoundEffect;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LootTracker {

    public static long itemsChecked = 0;
    static Pattern dropPattern = Pattern.compile(".*? \\((?<amount>\\d+)x .*\\).*");

    @SubscribeEvent
    public void onPacketRead(PacketReadEvent event) {
        if (!Utils.inSkyblock) return;

        if (event.packet instanceof S29PacketSoundEffect) {
            S29PacketSoundEffect packet = (S29PacketSoundEffect) event.packet;

            if (packet.getSoundName().equals("note.pling")) {
                if (System.currentTimeMillis() / 1000 - itemsChecked < 3) return;

                if (Utils.isInScoreboard("Boss slain!") || Utils.isInScoreboard("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.teeth += itemTeeth;
                        SpiderTracker.webs += itemWebs;
                        ZombieTracker.revFlesh += itemRev;
                        EndermanTracker.nullSpheres += itemNullSphere;
                        BlazeTracker.derelictAshes += itemDerelictAshe;
                        WolfTracker.teethSession += itemTeeth;
                        SpiderTracker.websSession += itemWebs;
                        ZombieTracker.revFleshSession += itemRev;
                        EndermanTracker.nullSpheresSession += itemNullSphere;
                        BlazeTracker.derelictAshesSession += itemDerelictAshe;

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

    public static int getAmountfromMessage(String message) {
        Matcher matcher = dropPattern.matcher(message);
        if (matcher.find()) {
            return Integer.parseInt(matcher.group("amount"));
        }
        return 1;
    }
    
}