use of org.bukkit.configuration.InvalidConfigurationException in project EliteMobs by MagmaGuy.
the class CustomConfigConstructor method reload.
/**
* Reload configuration
*/
public void reload() {
if (!file.exists()) {
try {
file.getParentFile().mkdirs();
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while creating file " + file.getName());
}
}
try {
load(file);
if (defaults != null) {
InputStreamReader reader = new InputStreamReader(plugin.getResource(defaults));
FileConfiguration defaultsConfig = YamlConfiguration.loadConfiguration(reader);
setDefaults(defaultsConfig);
options().copyDefaults(true);
reader.close();
save();
}
} catch (IOException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while loading file " + file.getName());
} catch (InvalidConfigurationException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while loading file " + file.getName());
}
}
use of org.bukkit.configuration.InvalidConfigurationException in project TotalFreedomMod by TotalFreedom.
the class MainConfig method load.
public void load() {
try {
YamlConfiguration config = new YamlConfiguration();
config.load(getConfigFile());
for (ConfigEntry entry : ConfigEntry.values()) {
String path = entry.getConfigName();
if (config.contains(path)) {
Object value = config.get(path);
if (value == null || entry.getType().isAssignableFrom(value.getClass())) {
entries.put(entry, value);
} else {
FLog.warning("Value for " + entry.getConfigName() + " is of type " + value.getClass().getSimpleName() + ". Needs to be " + entry.getType().getSimpleName() + ". Using default value.");
}
} else {
FLog.warning("Missing configuration entry " + entry.getConfigName() + ". Using default value.");
}
}
} catch (IOException | InvalidConfigurationException ex) {
FLog.severe(ex);
}
}
use of org.bukkit.configuration.InvalidConfigurationException in project Bukkit by Bukkit.
the class YamlConfiguration method loadFromString.
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
Validate.notNull(contents, "Contents cannot be null");
Map<?, ?> input;
try {
input = (Map<?, ?>) yaml.load(contents);
} catch (YAMLException e) {
throw new InvalidConfigurationException(e);
} catch (ClassCastException e) {
throw new InvalidConfigurationException("Top level is not a Map.");
}
String header = parseHeader(contents);
if (header.length() > 0) {
options().header(header);
}
if (input != null) {
convertMapsToSections(input, this);
}
}
use of org.bukkit.configuration.InvalidConfigurationException 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.InvalidConfigurationException 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);
}
Aggregations