Search in sources :

Example 1 with ConfigurateException

use of org.spongepowered.configurate.ConfigurateException in project SpongeCommon by SpongePowered.

the class WorldMigrator method getOldWorldContainer.

/**
 * Gets the old world container used when this server used to be running Bukkit.
 *
 * @return The world container
 */
public static Path getOldWorldContainer() {
    Path worldContainer = Paths.get(".");
    final Path bukkitYml = worldContainer.resolve("bukkit.yml");
    if (Files.exists(bukkitYml)) {
        try {
            final ConfigurationNode node = YamlConfigurationLoader.builder().path(bukkitYml).build().load();
            final String containerCandidate = node.node("settings", "world-container").getString("");
            if (!containerCandidate.isEmpty()) {
                try {
                    worldContainer = worldContainer.resolve(containerCandidate);
                } catch (final InvalidPathException ipe) {
                    SpongeCommon.logger().warn("Cannot use path [{}] specified under [world-container] in bukkit" + ".yml. Will use [{}] instead.", containerCandidate, worldContainer, ipe);
                }
            }
        } catch (final ConfigurateException ex) {
            SpongeCommon.logger().warn("Cannot load bukkit.yml. Will use [{}] instead.", worldContainer, ex);
        }
    }
    return worldContainer;
}
Also used : Path(java.nio.file.Path) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) ConfigurateException(org.spongepowered.configurate.ConfigurateException) InvalidPathException(java.nio.file.InvalidPathException)

Example 2 with ConfigurateException

use of org.spongepowered.configurate.ConfigurateException 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);
    }
}
Also used : HoconConfigurationLoader(org.spongepowered.configurate.hocon.HoconConfigurationLoader) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) ConfigurateException(org.spongepowered.configurate.ConfigurateException) IOException(java.io.IOException)

Example 3 with ConfigurateException

use of org.spongepowered.configurate.ConfigurateException in project SpongeCommon by SpongePowered.

the class ConfigTest method onConstruction.

@Listener
public void onConstruction(final ConstructPluginEvent event) {
    final URL testOne = this.getClass().getResource("/configtest/test.txt");
    final URL testTwo = this.getClass().getResource("/configtest/test2.txt");
    this.logger.info("Asset one: {}, asset two: {}", testOne, testTwo);
    try {
        this.config = this.reference.referenceTo(ExampleConfiguration.class);
        this.reference.save();
    } catch (final ConfigurateException ex) {
        this.logger.error("Unable to load test configuration", ex);
    }
}
Also used : ConfigurateException(org.spongepowered.configurate.ConfigurateException) URL(java.net.URL) Listener(org.spongepowered.api.event.Listener)

Aggregations

ConfigurateException (org.spongepowered.configurate.ConfigurateException)3 ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)2 IOException (java.io.IOException)1 URL (java.net.URL)1 InvalidPathException (java.nio.file.InvalidPathException)1 Path (java.nio.file.Path)1 Listener (org.spongepowered.api.event.Listener)1 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)1 HoconConfigurationLoader (org.spongepowered.configurate.hocon.HoconConfigurationLoader)1