Skip to content

Commit

Permalink
refactor: update coremod config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMVoid95 committed Jan 11, 2023
1 parent 16f79f5 commit f1485b1
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/main/java/micdoodle8/mods/miccore/ConfigManagerMicCore.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Team Galacticraft
* Copyright (c) 2023 Team Galacticraft
*
* Licensed under the MIT license.
* See LICENSE file in the project root for details.
Expand All @@ -8,41 +8,60 @@
package micdoodle8.mods.miccore;

import java.io.File;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

public class ConfigManagerMicCore
{

public static boolean loaded;

static Configuration configuration;
static Configuration configuration;

public static boolean enableSmallMoons;
public static boolean enableDebug;

public static void init()
{
File oldCoreConfig = new File(MicdoodlePlugin.canonicalConfigDir, "Galacticraft/miccore.conf");
File coremodConfig = new File(MicdoodlePlugin.canonicalConfigDir, "Galacticraft/MicdoodleCore.cfg");

if (!ConfigManagerMicCore.loaded)
{
ConfigManagerMicCore.configuration = new Configuration(new File(MicdoodlePlugin.canonicalConfigDir, "Galacticraft/miccore.conf"));
if (oldCoreConfig.exists())
{
ConfigManagerMicCore.configuration = ConfigManagerMicCore.handleConfigFileMove(new Configuration(oldCoreConfig), coremodConfig);
oldCoreConfig.delete();
}
else
{
ConfigManagerMicCore.configuration = new Configuration(coremodConfig);
}
}

ConfigManagerMicCore.configuration.load();
ConfigManagerMicCore.syncConfig();
}

private static Configuration handleConfigFileMove(Configuration oldConfig, File newFile)
{
Property logDebugOutput = oldConfig.get(Configuration.CATEGORY_GENERAL, "Enable Debug messages", false);

Configuration newConfig = new Configuration(newFile);
newConfig.get(Configuration.CATEGORY_GENERAL, "logDebugOutput", logDebugOutput.getBoolean(), "If `true` Enable debug messages during Galacticraft bytecode injection at startup");
newConfig.save();

return newConfig;
}

public static void syncConfig()
{
try
{
ConfigManagerMicCore.enableSmallMoons = ConfigManagerMicCore.configuration
.get(Configuration.CATEGORY_GENERAL, "Enable Small Moons", true, "This will cause some dimensions to appear round, disable if render transformations cause a conflict.")
.getBoolean(true);
ConfigManagerMicCore.enableDebug = ConfigManagerMicCore.configuration
.get(Configuration.CATEGORY_GENERAL, "Enable Debug messages", false, "Enable debug messages during Galacticraft bytecode injection at startup.").getBoolean(false);
ConfigManagerMicCore.enableDebug = ConfigManagerMicCore.configuration.get(Configuration.CATEGORY_GENERAL, "logDebugOutput", false, "If `true` Enable debug messages during Galacticraft bytecode injection at startup").getBoolean(false);
} catch (final Exception e)
{
MicdoodlePlugin.miccoreLogger.error("Problem loading core config (\"miccore.conf\")");
MicdoodlePlugin.miccoreLogger.error("Problem loading core config (\"MicdoodleCore.conf\")");
} finally
{
if (ConfigManagerMicCore.configuration.hasChanged())
Expand Down

0 comments on commit f1485b1

Please sign in to comment.