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")));
}
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations