Search in sources :

Example 6 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Bukkit by Bukkit.

the class ColorTest method testSerialization.

@Test
public void testSerialization() throws Throwable {
    for (TestColor testColor : examples) {
        Color base = Color.fromRGB(testColor.rgb);
        YamlConfiguration toSerialize = new YamlConfiguration();
        toSerialize.set("color", base);
        String serialized = toSerialize.saveToString();
        YamlConfiguration deserialized = new YamlConfiguration();
        deserialized.loadFromString(serialized);
        assertThat(testColor.name + " on " + serialized, base, is(deserialized.getColor("color")));
    }
}
Also used : YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Test(org.junit.Test)

Example 7 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Glowstone by GlowstoneMC.

the class ServerConfig method migrate.

private boolean migrate() {
    boolean migrateStatus = false;
    File bukkitYml = new File("bukkit.yml");
    if (bukkitYml.exists()) {
        YamlConfiguration bukkit = new YamlConfiguration();
        try {
            bukkit.load(bukkitYml);
        } catch (InvalidConfigurationException e) {
            report(bukkitYml, e);
        } catch (IOException e) {
            GlowServer.logger.log(Level.WARNING, "Could not migrate from " + bukkitYml, e);
        }
        for (Key key : Key.values()) {
            if (key.migrate == Migrate.BUKKIT && bukkit.contains(key.migratePath)) {
                config.set(key.path, bukkit.get(key.migratePath));
                migrateStatus = true;
            }
        }
        config.set("aliases", bukkit.get("aliases"));
        config.set("worlds", bukkit.get("worlds"));
    }
    File serverProps = new File("server.properties");
    if (serverProps.exists()) {
        Properties props = new Properties();
        try {
            props.load(new FileInputStream(serverProps));
        } catch (IOException e) {
            GlowServer.logger.log(Level.WARNING, "Could not migrate from " + serverProps, e);
        }
        for (Key key : Key.values()) {
            if (key.migrate == Migrate.PROPS && props.containsKey(key.migratePath)) {
                String value = props.getProperty(key.migratePath);
                if (key.def instanceof Integer) {
                    try {
                        config.set(key.path, Integer.parseInt(value));
                    } catch (NumberFormatException e) {
                        GlowServer.logger.log(Level.WARNING, "Could not migrate " + key.migratePath + " from " + serverProps, e);
                        continue;
                    }
                } else if (key.def instanceof Boolean) {
                    config.set(key.path, Boolean.parseBoolean(value));
                } else {
                    config.set(key.path, value);
                }
                migrateStatus = true;
            }
        }
    }
    return migrateStatus;
}
Also used : YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Properties(java.util.Properties) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 8 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project xAuth by CypherX.

the class MessageHandler method reloadConfig.

public void reloadConfig() {
    config = YamlConfiguration.loadConfiguration(configFile);
    InputStream defConfigStream = plugin.getResource(fileName);
    if (defConfigStream != null) {
        YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
        config.setDefaults(defConfig);
    }
}
Also used : InputStream(java.io.InputStream) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration)

Example 9 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Bukkit by Bukkit.

the class JavaPlugin method reloadConfig.

@SuppressWarnings("deprecation")
@Override
public void reloadConfig() {
    newConfig = YamlConfiguration.loadConfiguration(configFile);
    final InputStream defConfigStream = getResource("config.yml");
    if (defConfigStream == null) {
        return;
    }
    final YamlConfiguration defConfig;
    if (isStrictlyUTF8() || FileConfiguration.UTF8_OVERRIDE) {
        defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8));
    } else {
        final byte[] contents;
        defConfig = new YamlConfiguration();
        try {
            contents = ByteStreams.toByteArray(defConfigStream);
        } catch (final IOException e) {
            getLogger().log(Level.SEVERE, "Unexpected failure reading config.yml", e);
            return;
        }
        final String text = new String(contents, Charset.defaultCharset());
        if (!text.equals(new String(contents, Charsets.UTF_8))) {
            getLogger().warning("Default system encoding may have misread config.yml from plugin jar");
        }
        try {
            defConfig.loadFromString(text);
        } catch (final InvalidConfigurationException e) {
            getLogger().log(Level.SEVERE, "Cannot load configuration from jar", e);
        }
    }
    newConfig.setDefaults(defConfig);
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 10 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Dragonet-Legacy by DragonetMC.

the class PluginAdapter method initialize.

public void initialize(String name) {
    if (initialized)
        return;
    this.name = name;
    dataFolder = new File(server.getDragonetServer().getPluginFolder(), this.getName().replace(".", "_").concat("-data"));
    if (dataFolder.isFile()) {
        server.getLogger().warning("Faild to load plugin [" + getName() + "] due to plugin folder is occupied by a regular file. ");
        throw new IllegalStateException("Plugin folder for [" + getName() + "] is occupied by a regular file. ");
    }
    config = new YamlConfiguration();
    try {
        config.load(new File(dataFolder, "config.yml"));
    } catch (IOException | InvalidConfigurationException ex) {
    }
    logger = new PluginLogger(this);
    initialized = true;
}
Also used : IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginLogger(org.bukkit.plugin.PluginLogger) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Aggregations

YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)16 File (java.io.File)7 IOException (java.io.IOException)7 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)3 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 InputStream (java.io.InputStream)2 Location (org.bukkit.Location)2 World (org.bukkit.World)2 Test (org.junit.Test)2 ActionType (com.gamingmesh.jobs.container.ActionType)1 DisplayMethod (com.gamingmesh.jobs.container.DisplayMethod)1 Job (com.gamingmesh.jobs.container.Job)1 JobInfo (com.gamingmesh.jobs.container.JobInfo)1 JobPermission (com.gamingmesh.jobs.container.JobPermission)1 RestrictedArea (com.gamingmesh.jobs.container.RestrictedArea)1 Title (com.gamingmesh.jobs.container.Title)1 Parser (com.gamingmesh.jobs.resources.jfep.Parser)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1