use of org.spongepowered.configurate.hocon.HoconConfigurationLoader in project SpongeCommon by SpongePowered.
the class SpongeConfigs method create.
public static <T extends Config> ConfigHandle<T> create(final Class<T> instance, @Nullable final Supplier<ConfigurationTransformation> versionModifier, final String fileName) {
try {
final HoconConfigurationLoader loader = SpongeConfigs.createLoader(SpongeConfigs.getDirectory().resolve(fileName));
final ConfigHandle<T> handle = new ConfigHandle<>(instance, versionModifier, loader);
handle.load();
return handle;
} catch (final IOException ex) {
SpongeConfigs.LOGGER.error("Unable to load configuration {}. Sponge will operate in " + "fallback mode, with default configuration options and will not write to the invalid file", fileName, ex);
return new ConfigHandle<>(instance);
}
}
use of org.spongepowered.configurate.hocon.HoconConfigurationLoader in project SpongeCommon by SpongePowered.
the class HoconDataFormat method writeTo.
private static void writeTo(final Callable<BufferedWriter> sink, final DataView data) throws IOException {
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder().sink(sink).build();
final ConfigurationNode node = loader.createNode();
ConfigurateTranslator.instance().translateDataToNode(node, data);
try {
loader.save(node);
} catch (final ConfigurateException ex) {
throw new IOException(ex);
}
}
Aggregations