aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gg/skytils/skytilsmod/utils/SuperSecretSettings.java
blob: 7037e69c978341f906fe8e2d66330e997dc571f8 (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
/*
 * Skytils - Hypixel Skyblock Quality of Life Mod
 * Copyright (C) 2022 Skytils
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package gg.skytils.skytilsmod.utils;

import net.minecraft.launchwrapper.Launch;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedHashSet;
import java.util.List;

public class SuperSecretSettings {
    public static final LinkedHashSet<String> settings = new LinkedHashSet<>();
    public static final File saveLoc = new File(Launch.minecraftHome, "config/skytils/supersecretsettings.txt");
    public static boolean dirty = false;

    // Secrets
    public static boolean azooPuzzoo = false;
    public static boolean bennettArthur = false;
    public static boolean breefingDog = false;
    public static boolean jamCat = false;
    public static boolean noSychic = false;
    public static boolean smolPeople = false;
    public static boolean tryItAndSee = false;

    static {
        if (!saveLoc.exists()) {
            try {
                saveLoc.getParentFile().mkdirs();
                saveLoc.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            load();
        }
        Runtime.getRuntime().addShutdownHook(new Thread(SuperSecretSettings::save, "Skytils-SuperSecretSave"));
    }

    public static void add(String setting) {
        settings.add(setting);
        dirty = true;
        setSecrets();
    }

    public static void remove(String setting) {
        settings.remove(setting);
        dirty = true;
        setSecrets();
    }

    public static void clear() {
        settings.clear();
        dirty = true;
        setSecrets();
    }

    public static void load() {
        settings.clear();
        try {
            List<String> lines = IOUtils.readLines(Files.newInputStream(saveLoc.toPath()), Charsets.UTF_8);
            for (String line : lines) {
                if (!line.isEmpty()) {
                    settings.add(line);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        setSecrets();
    }

    public static void save() {
        if (!dirty) return;
        dirty = false;
        try {
            IOUtils.writeLines(settings, "\n", Files.newOutputStream(saveLoc.toPath()), Charsets.UTF_8);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void setSecrets() {
        azooPuzzoo = settings.contains("azoopuzzoo");
        bennettArthur = settings.contains("bennettarthur");
        breefingDog = settings.contains("breefingdog");
        jamCat = settings.contains("jamcat");
        noSychic = settings.contains("nosychic");
        smolPeople = settings.contains("smolpeople");
        tryItAndSee = settings.contains("tryItAndSee");
    }
}