aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/DungeonTimer.java
blob: 394f2defdc0eabf60f956101663e0f2494f893f3 (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
package me.Danker.features;

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.util.EnumChatFormatting;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class DungeonTimer {

    static double dungeonStartTime = 0;
    static double bloodOpenTime = 0;
    static double watcherClearTime = 0;
    static double bossClearTime = 0;
    static int witherDoors = 0;
    static int dungeonDeaths = 0;
    static int puzzleFails = 0;

    @SubscribeEvent(receiveCanceled = true)
    public void onChat(ClientChatReceivedEvent event) {
        String message = StringUtils.stripControlCodes(event.message.getUnformattedText());

        if (!Utils.inDungeons) return;

        if (message.contains("[BOSS] The Watcher: You have proven yourself. You may pass.")) {
            watcherClearTime = System.currentTimeMillis() / 1000;
        } else if (message.contains("PUZZLE FAIL! ") || message.contains("chose the wrong answer! I shall never forget this moment")) {
            puzzleFails++;
        }

        if (message.contains(":")) return;

        if (message.contains("Dungeon starts in 1 second.")) { // Dungeons Stuff
            dungeonStartTime = System.currentTimeMillis() / 1000 + 1;
            bloodOpenTime = dungeonStartTime;
            watcherClearTime = dungeonStartTime;
            bossClearTime = dungeonStartTime;
            witherDoors = 0;
            dungeonDeaths = 0;
            puzzleFails = 0;
        } else if (message.contains("The BLOOD DOOR has been opened!")) {
            bloodOpenTime = System.currentTimeMillis() / 1000;
        } else if (message.contains(" opened a WITHER door!")) {
            witherDoors++;
        } else if (message.contains(" and became a ghost.")) {
            dungeonDeaths++;
        } else if (message.contains(" Defeated ") && message.contains(" in ")) {
            bossClearTime = System.currentTimeMillis() / 1000;
        }
    }

    @SubscribeEvent
    public void renderPlayerInfo(RenderOverlay event) {
        if (ToggleCommand.dungeonTimerToggled && Utils.inDungeons) {
            Minecraft mc = Minecraft.getMinecraft();
            String dungeonTimerText = EnumChatFormatting.GRAY + "Wither Doors:\n" +
                    EnumChatFormatting.DARK_RED + "Blood Open:\n" +
                    EnumChatFormatting.RED + "Watcher Clear:\n" +
                    EnumChatFormatting.BLUE + "Boss Clear:\n" +
                    EnumChatFormatting.YELLOW + "Deaths:\n" +
                    EnumChatFormatting.YELLOW + "Puzzle Fails:";
            String dungeonTimers = EnumChatFormatting.GRAY + "" + witherDoors + "\n" +
                    EnumChatFormatting.DARK_RED + Utils.getTimeBetween(dungeonStartTime, bloodOpenTime) + "\n" +
                    EnumChatFormatting.RED + Utils.getTimeBetween(dungeonStartTime, watcherClearTime) + "\n" +
                    EnumChatFormatting.BLUE + Utils.getTimeBetween(dungeonStartTime, bossClearTime) + "\n" +
                    EnumChatFormatting.YELLOW + dungeonDeaths + "\n" +
                    EnumChatFormatting.YELLOW + puzzleFails;
            new TextRenderer(mc, dungeonTimerText, MoveCommand.dungeonTimerXY[0], MoveCommand.dungeonTimerXY[1], ScaleCommand.dungeonTimerScale);
            new TextRenderer(mc, dungeonTimers, (int) (MoveCommand.dungeonTimerXY[0] + (80 * ScaleCommand.dungeonTimerScale)), MoveCommand.dungeonTimerXY[1], ScaleCommand.dungeonTimerScale);
        }
    }

}