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

import me.Danker.DankersSkyblockMod;
import me.Danker.commands.ToggleCommand;
import me.Danker.handlers.ScoreboardHandler;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.util.List;

public class LowHealthNotifications {

    @SubscribeEvent
    public void onTick(TickEvent.ClientTickEvent event) {
        if (event.phase != TickEvent.Phase.START) return;

        World world = Minecraft.getMinecraft().theWorld;
        if (DankersSkyblockMod.tickAmount % 2 == 0) {
            if (ToggleCommand.lowHealthNotifyToggled && Utils.inDungeons && world != null) {
                List<String> scoreboard = ScoreboardHandler.getSidebarLines();
                for (String score : scoreboard) {
                    if (score.endsWith("❤") && score.matches(".* §c\\d.*")) {
                        String name = score.substring(score.indexOf(" ") + 1);
                        Utils.createTitle(EnumChatFormatting.RED + "LOW HEALTH!\n" + name, 1);
                        break;
                    }
                }
            }
        }
    }

}