Search in sources :

Example 16 with CommentedFileConfig

use of com.electronwill.nightconfig.core.file.CommentedFileConfig in project UnlitCampfire by cech12.

the class ServerConfig method loadConfig.

public static void loadConfig(ForgeConfigSpec spec, Path path) {
    final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build();
    configData.load();
    spec.setConfig(configData);
}
Also used : CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig)

Example 17 with CommentedFileConfig

use of com.electronwill.nightconfig.core.file.CommentedFileConfig in project Tetra-Pak by Noobulus.

the class Config method loadConfig.

public static void loadConfig(ForgeConfigSpec spec, Path path) {
    final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build();
    configData.load();
    spec.setConfig(configData);
}
Also used : CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig)

Example 18 with CommentedFileConfig

use of com.electronwill.nightconfig.core.file.CommentedFileConfig in project MinecraftForge by MinecraftForge.

the class ForgeConfigSpecTest method executeSpeedTest.

private <T> void executeSpeedTest(final String configKey, final T defaultKeyValue, final String testName) throws IOException {
    final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
    final ForgeConfigSpec.ConfigValue<T> simpleValue = builder.define(configKey, defaultKeyValue);
    final ForgeConfigSpec spec = builder.build();
    final String configPath = String.format(Locale.ROOT, TEST_CONFIG_PATH_TEMPLATE, testName);
    final File configFile = new File(configPath);
    configFile.getParentFile().mkdirs();
    configFile.createNewFile();
    final CommentedFileConfig configData = CommentedFileConfig.builder(configPath).sync().preserveInsertionOrder().onFileNotFound((newfile, configFormat) -> {
        Files.createFile(newfile);
        return true;
    }).writingMode(WritingMode.REPLACE).build();
    spec.setConfig(configData);
    final List<TestResult> results = runTestHarness(defaultKeyValue, testName, simpleValue, spec, 3, 20);
    final double averageEnabled = results.stream().mapToLong(value -> value.enabledWatch.elapsed(TimeUnit.NANOSECONDS)).average().getAsDouble();
    final double averageDisabled = results.stream().mapToLong(value -> value.disabledWatch.elapsed(TimeUnit.NANOSECONDS)).average().getAsDouble();
    final double maxEnabledDeviation = results.stream().mapToLong(value -> value.enabledWatch.elapsed(TimeUnit.NANOSECONDS)).mapToDouble(e -> e - averageEnabled).map(Math::abs).max().getAsDouble();
    final double maxDisabledDeviation = results.stream().mapToLong(value -> value.disabledWatch.elapsed(TimeUnit.NANOSECONDS)).mapToDouble(e -> e - averageDisabled).map(Math::abs).max().getAsDouble();
    System.out.printf("Computed test results for: %s:%n", testName);
    System.out.printf("  > Enabled:  ~%10.2f ns.   +- %10.2f ns.%n", averageEnabled, maxEnabledDeviation);
    System.out.printf("  > Disabled: ~%10.2f ns.   +- %10.2f ns.%n", averageDisabled, maxDisabledDeviation);
    configFile.delete();
}
Also used : Files(java.nio.file.Files) Stopwatch(com.google.common.base.Stopwatch) WritingMode(com.electronwill.nightconfig.core.io.WritingMode) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) Test(org.junit.Test) IOException(java.io.IOException) CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig) Field(java.lang.reflect.Field) File(java.io.File) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) Assert(org.junit.Assert) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig) File(java.io.File)

Example 19 with CommentedFileConfig

use of com.electronwill.nightconfig.core.file.CommentedFileConfig in project pollen by MoonflowerTeam.

the class ConfigTracker method openConfig.

private void openConfig(PollinatedModConfigImpl config, Path configBasePath) {
    CommentedFileConfig configData = config.getHandler().reader(configBasePath).apply(config);
    config.setConfigData(configData);
    ConfigEvent.LOADING.invoker().configChanged(config);
    config.save();
}
Also used : CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig)

Example 20 with CommentedFileConfig

use of com.electronwill.nightconfig.core.file.CommentedFileConfig in project RFToolsBuilder by McJtyMods.

the class Config method loadConfig.

public static void loadConfig(ForgeConfigSpec spec, Path path) {
    final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build();
    configData.load();
    spec.setConfig(configData);
}
Also used : CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig)

Aggregations

CommentedFileConfig (com.electronwill.nightconfig.core.file.CommentedFileConfig)45 File (java.io.File)12 Path (java.nio.file.Path)2 CommentedConfig (com.electronwill.nightconfig.core.CommentedConfig)1 ObjectConverter (com.electronwill.nightconfig.core.conversion.ObjectConverter)1 WritingMode (com.electronwill.nightconfig.core.io.WritingMode)1 Stopwatch (com.google.common.base.Stopwatch)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 TimeUnit (java.util.concurrent.TimeUnit)1 ForgeConfigSpec (net.minecraftforge.common.ForgeConfigSpec)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1