aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
blob: b100e5b36e2c733ec953398c5de64c1067e4008c (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package at.hannibal2.skyhanni;

import at.hannibal2.skyhanni.bazaar.BazaarApi;
import at.hannibal2.skyhanni.bazaar.BazaarOrderHelper;
import at.hannibal2.skyhanni.chat.ChatFilter;
import at.hannibal2.skyhanni.chat.ChatManager;
import at.hannibal2.skyhanni.chat.PlayerChatFilter;
import at.hannibal2.skyhanni.config.Features;
import at.hannibal2.skyhanni.config.commands.Commands;
import at.hannibal2.skyhanni.dungeon.*;
import at.hannibal2.skyhanni.dungeon.damageindicator.DungeonBossDamageIndicator;
import at.hannibal2.skyhanni.fishing.TrophyFishMessages;
import at.hannibal2.skyhanni.items.HideNotClickableItems;
import at.hannibal2.skyhanni.items.ItemDisplayOverlayFeatures;
import at.hannibal2.skyhanni.items.abilitycooldown.ItemAbilityCooldown;
import at.hannibal2.skyhanni.misc.*;
import at.hannibal2.skyhanni.test.LorenzTest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
import java.nio.charset.StandardCharsets;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

@Mod(modid = SkyHanniMod.MODID, version = SkyHanniMod.VERSION)
public class SkyHanniMod {

    public static final String MODID = "skyhanni";
    public static final String VERSION = "0.1";

    public static Features feature;
    private File configFile;

    private final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();

    public static File configDirectory;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        new BazaarApi();
        MinecraftForge.EVENT_BUS.register(this);
        MinecraftForge.EVENT_BUS.register(new ChatManager());
        MinecraftForge.EVENT_BUS.register(new HypixelData());
        MinecraftForge.EVENT_BUS.register(new DungeonData());
        MinecraftForge.EVENT_BUS.register(new ScoreboardData());
        MinecraftForge.EVENT_BUS.register(new ApiData());

        MinecraftForge.EVENT_BUS.register(new BazaarOrderHelper());
        MinecraftForge.EVENT_BUS.register(new ChatFilter());
        MinecraftForge.EVENT_BUS.register(new PlayerChatFilter());
        MinecraftForge.EVENT_BUS.register(new DungeonChatFilter());
        MinecraftForge.EVENT_BUS.register(new HideNotClickableItems());
        MinecraftForge.EVENT_BUS.register(new DungeonHighlightClickedBlocks());
        MinecraftForge.EVENT_BUS.register(new ItemDisplayOverlayFeatures());
        MinecraftForge.EVENT_BUS.register(new CurrentPetDisplay());
        MinecraftForge.EVENT_BUS.register(new ExpBottleOnGroundHider());
        MinecraftForge.EVENT_BUS.register(new DungeonBossDamageIndicator());
        MinecraftForge.EVENT_BUS.register(new ItemAbilityCooldown());
        MinecraftForge.EVENT_BUS.register(new DungeonMilestoneDisplay());
        MinecraftForge.EVENT_BUS.register(new DungeonDeathCounter());
        MinecraftForge.EVENT_BUS.register(new DungeonCleanEnd());
        MinecraftForge.EVENT_BUS.register(new DungeonBossMessages());
        MinecraftForge.EVENT_BUS.register(new TrophyFishMessages());

        Commands.init();

        MinecraftForge.EVENT_BUS.register(new LorenzTest());
        MinecraftForge.EVENT_BUS.register(new ButtonOnPause());

        configDirectory = new File("mods/SkyHanni/config");
        try {
            //noinspection ResultOfMethodCallIgnored
            configDirectory.mkdir();
        } catch (Exception ignored) {}

        configFile = new File(configDirectory, "config.json");

        if (configFile.exists()) {
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) {
                feature = gson.fromJson(reader, Features.class);
            } catch (Exception ignored) {}
        }

        if (feature == null) {
            feature = new Features();
            saveConfig();
        }
        Runtime.getRuntime().addShutdownHook(new Thread(this::saveConfig));
    }

    public void saveConfig() {
        try {
            //noinspection ResultOfMethodCallIgnored
            configFile.createNewFile();

            try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) {
                writer.write(gson.toJson(feature));
            }
        } catch (IOException ignored) {}
    }

    public static GuiScreen screenToOpen = null;
    private static int screenTicks = 0;

    @SubscribeEvent
    public void onClientTick(TickEvent.ClientTickEvent event) {
        if (screenToOpen != null) {
            screenTicks++;
            if (screenTicks == 5) {
                Minecraft.getMinecraft().displayGuiScreen(screenToOpen);
                screenTicks = 0;
                screenToOpen = null;
            }
        }
    }
}