aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/location/DwarvenMineHandler.java
blob: 3b17899621a0901fa672ae8c635f1f27b33da1e6 (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
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
package com.thatgravyboat.skyblockhud.location;

import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent;
import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class DwarvenMineHandler {

    public enum Event {
        NONE(0, "Unknown"),
        TICKET(107, "Raffle"),
        GOBLIN(99, "Goblin Raid");

        public int x;
        public String displayName;

        Event(int x, String displayName) {
            this.x = x;
            this.displayName = displayName;
        }
    }

    public static int mithril;

    public static int eventMax;
    public static int eventProgress;
    public static Event currentEvent;

    private static final DecimalFormat formatter = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CANADA));

    public static String getMithrilFormatted() {
        String output = formatter.format(mithril);
        if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0";
        return output;
    }

    public static void parseMithril(String line) {
        try {
            mithril = Integer.parseInt(line.toLowerCase().replace("mithril powder:", "").trim());
        } catch (Exception ignored) {}
    }

    @SubscribeEvent
    public void onSidebarLineUpdate(SidebarLineUpdateEvent event) {
        if (event.formattedLine.toLowerCase().contains("mithril")) {
            try {
                mithril = Integer.parseInt(event.formattedLine.toLowerCase().replace("mithril:", "").trim());
            } catch (Exception ignored) {}
        }
        if (event.formattedLine.toLowerCase().contains("event")) {
            if (event.formattedLine.toLowerCase().contains("raffle")) {
                DwarvenMineHandler.currentEvent = Event.TICKET;
            } else if (event.formattedLine.toLowerCase().contains("goblin raid")) {
                DwarvenMineHandler.currentEvent = Event.GOBLIN;
            }
        }
        if (DwarvenMineHandler.currentEvent != Event.NONE) {
            if (DwarvenMineHandler.currentEvent == Event.TICKET && event.formattedLine.toLowerCase().contains("tickets:")) {
                if (event.formattedLine.toLowerCase().contains("pool:")) {
                    try {
                        eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("pool:", "").trim().split("/")[0].trim());
                    } catch (Exception ignored) {}
                } else if (event.formattedLine.toLowerCase().contains("tickets:")) {
                    try {
                        eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("tickets:", "").split("\\(")[0].trim());
                    } catch (Exception ignored) {}
                }
            } else if (DwarvenMineHandler.currentEvent == Event.GOBLIN) {
                if (event.formattedLine.toLowerCase().contains("remaining:")) {
                    try {
                        eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("goblins", "").replace("remaining:", "").trim());
                    } catch (Exception ignored) {}
                } else if (event.formattedLine.toLowerCase().contains("your kills:") && !event.formattedLine.toLowerCase().contains("(")) {
                    try {
                        eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("your kills:", "").trim());
                    } catch (Exception ignored) {}
                }
            }
        }
    }

    @SubscribeEvent
    public void onSidebarPost(SidebarPostEvent event) {
        String arrayString = Arrays.toString(event.arrayScores);
        if (!arrayString.toLowerCase().contains("event:")) {
            DwarvenMineHandler.currentEvent = Event.NONE;
            DwarvenMineHandler.eventProgress = 0;
            DwarvenMineHandler.eventMax = 0;
        }
    }
}