Search in sources :

Example 6 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class ToggleChatConfig method loadToggles.

public void loadToggles() {
    if (exists(toggleFile)) {
        try {
            FileReader fileReader = new FileReader(toggleFile);
            BufferedReader reader = new BufferedReader(fileReader);
            toggleJson = new BetterJsonObject(reader.lines().collect(Collectors.joining()));
            fileReader.close();
            reader.close();
        } catch (Exception ex) {
            log("Could not read toggles properly, saving.");
            saveToggles();
        }
        theMod.getToggleHandler().getToggles().values().forEach(base -> base.setEnabled(toggleJson.has("show" + base.getName().replace(" ", "_")) && toggleJson.get("show" + base.getName().replace(" ", "_")).getAsBoolean()));
    } else {
        saveToggles();
    }
}
Also used : BetterJsonObject(cc.hyperium.utils.BetterJsonObject) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 7 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class KeyBindConfig method load.

public void load() {
    if (exists(keybindFile)) {
        try {
            FileReader fileReader = new FileReader(keybindFile);
            BufferedReader reader = new BufferedReader(fileReader);
            keyBindJson = new BetterJsonObject(reader.lines().collect(Collectors.joining()));
            fileReader.close();
            reader.close();
        } catch (Exception ex) {
            // Error occured while loading
            save();
            return;
        }
        handler.getKeybinds().values().forEach(bind -> bind.setKeyCode(keyBindJson.optInt(bind.getRealDescription(), bind.getDefaultKeyCode())));
    } else {
        // Config file doesn't exist, yay!
        save();
    }
}
Also used : BetterJsonObject(cc.hyperium.utils.BetterJsonObject) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException)

Aggregations

BetterJsonObject (cc.hyperium.utils.BetterJsonObject)7 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4 JsonHolder (cc.hyperium.utils.JsonHolder)2 JsonArray (com.google.gson.JsonArray)2 CustomKey (cc.hyperium.mods.keystrokes.keys.impl.CustomKey)1 CustomKeyWrapper (cc.hyperium.mods.keystrokes.render.CustomKeyWrapper)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1