/** * Loads this {@link FileConfiguration} from the specified location. * <p> * All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded * from the given file. * <p> * If the file cannot be loaded for any reason, an exception will be * thrown. * * @param file File to load from. * @throws FileNotFoundException Thrown when the given file cannot be * opened. * @throws IOException Thrown when the given file cannot be read. * @throws InvalidConfigurationException Thrown when the given file is not * a valid Configuration. * @throws IllegalArgumentException Thrown when file is null. */ public void load(String file) throws FileNotFoundException, IOException, InvalidConfigurationException { Validate.notNull(file, "File cannot be null"); load(new File(file)); }
/** * Loads this {@link FileConfiguration} from the specified stream. * <p> * All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded * from the given stream. * <p> * This will attempt to use the {@link Charset#defaultCharset()}, unless * {@link #UTF8_OVERRIDE} or {@link #UTF_BIG} is specified. * * @param stream Stream to load from * @throws IOException Thrown when the given file cannot be read. * @throws InvalidConfigurationException Thrown when the given file is not * a valid Configuration. * @throws IllegalArgumentException Thrown when stream is null. * @deprecated This does not consider encoding * @see #load(Reader) */ @Deprecated public void load(InputStream stream) throws IOException, InvalidConfigurationException { Validate.notNull(stream, "Stream cannot be null"); load(new InputStreamReader(stream, UTF8_OVERRIDE ? Charsets.UTF_8 : Charset.defaultCharset())); }
/** * Loads this {@link FileConfiguration} from the specified location. * <p> * All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded * from the given file. * <p> * If the file cannot be loaded for any reason, an exception will be * thrown. * <p> * This will attempt to use the {@link Charset#defaultCharset()} for * files, unless {@link #UTF8_OVERRIDE} but not {@link #UTF_BIG} is * specified. * * @param file File to load from. * @throws FileNotFoundException Thrown when the given file cannot be * opened. * @throws IOException Thrown when the given file cannot be read. * @throws InvalidConfigurationException Thrown when the given file is not * a valid Configuration. * @throws IllegalArgumentException Thrown when file is null. */ public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException { Validate.notNull(file, "File cannot be null"); final FileInputStream stream = new FileInputStream(file); load(new InputStreamReader(stream, UTF8_OVERRIDE && !UTF_BIG ? Charsets.UTF_8 : Charset.defaultCharset())); }
@Override public boolean load() { try { config.load(file); return true; } catch (Exception ex) { ex.printStackTrace(); return false; } }
@Override public void reloadConfig() { if (this.pluginConfig != null) { try { this.config.load(this.dataFolder); } catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); } } }
/** * Loads this {@link FileConfiguration} from the specified location. * <p> * All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded * from the given file. * <p> * If the file cannot be loaded for any reason, an exception will be * thrown. * * @param file File to load from. * @throws FileNotFoundException Thrown when the given file cannot be * opened. * @throws IOException Thrown when the given file cannot be read. * @throws InvalidConfigurationException Thrown when the given file is not * a valid Configuration. * @throws IllegalArgumentException Thrown when file is null. */ public void load(String file) throws FileNotFoundException, IOException, InvalidConfigurationException { Validate.notNull(file, "File cannot be null"); load(new File(file)); }
public boolean loadConfig() { clearConfig(); try { config.load(yamlFile); return true; } catch (Exception ignored) { return false; } }
/** * Reloads the {@link FileConfiguration} object. If the config object does * not exist it will run {@link #create()} first before loading the config. */ public void reload() { this.create(); try { this.config.load(this.file); } catch (final Exception e) { e.printStackTrace(); } }
/** * Loads this {@link FileConfiguration} from the specified stream. * <p> * All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded * from the given stream. * <p> * This will attempt to use the {@link Charset#defaultCharset()}, unless * {@link #UTF8_OVERRIDE} or {@link #UTF_BIG} is specified. * * @param stream Stream to load from * @throws IOException Thrown when the given file cannot be read. * @throws InvalidConfigurationException Thrown when the given file is not * a valid Configuration. * @throws IllegalArgumentException Thrown when stream is null. * @deprecated This does not consider encoding * @see #load(Reader) */ @Deprecated public void load(InputStream stream) throws IOException, InvalidConfigurationException { Validate.notNull(stream, "Stream cannot be null"); load(new InputStreamReader(stream, UTF8_OVERRIDE ? Charsets.UTF_8 : Charset.defaultCharset())); }
/** * Loads this {@link FileConfiguration} from the specified location. * <p> * All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded * from the given file. * <p> * If the file cannot be loaded for any reason, an exception will be * thrown. * <p> * This will attempt to use the {@link Charset#defaultCharset()} for * files, unless {@link #UTF8_OVERRIDE} but not {@link #UTF_BIG} is * specified. * * @param file File to load from. * @throws FileNotFoundException Thrown when the given file cannot be * opened. * @throws IOException Thrown when the given file cannot be read. * @throws InvalidConfigurationException Thrown when the given file is not * a valid Configuration. * @throws IllegalArgumentException Thrown when file is null. */ public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException { Validate.notNull(file, "File cannot be null"); final FileInputStream stream = new FileInputStream(file); load(new InputStreamReader(stream, UTF8_OVERRIDE && !UTF_BIG ? Charsets.UTF_8 : Charset.defaultCharset())); }
void loadTokensAmount() { File tokenFile = getTokenFile(); //Make sure it exists FileConfiguration fileConfig = YamlConfiguration.loadConfiguration(tokenFile); //Load configuration try { fileConfig.load(tokenFile); //Load contents of file for (String id : fileConfig.getKeys(false)) { //Get the keys tokens.put(id, fileConfig.getInt(id)); //Add values to map } } catch (Exception ex) { ex.printStackTrace();; } }
private void loadConfig() { File brokenConfig; try { this.config.load(this.pluginConfig); return; } catch (InvalidConfigurationException e) { brokenConfig = new File(this.dataFolder.getAbsolutePath() + File.separator + "config.broken.yml"); } catch (IOException e) { this.logger.severe("There was an error creating the file to move the broken config to."); e.printStackTrace(); return; } try { Files.copy(this.pluginConfig.toPath(), brokenConfig.toPath()); Files.copy(this.pluginFile.getDefaultConfig(), this.pluginConfig.toPath()); this.config.load(this.pluginConfig); } catch (IOException e) { this.logger.severe("There was an error copying either the broken config to its new file or the default config to the data folder."); e.printStackTrace(); return; } catch (InvalidConfigurationException e) { this.logger.severe("The internal config is invalid. If you are the plugin maintainer please verify it. If you believe this is a bug submit an issue on GitHub with your configuration."); e.printStackTrace(); } this.logger.warning("The config at " + this.pluginConfig.getAbsolutePath() + " was invalid. It has been moved to config.broken.yml and the default config has been exported to config.yml."); }
private FileConfiguration loadMain() throws SkyConfigurationException { FileConfiguration config = new YamlConfiguration(); config.options().pathSeparator('%'); try { config.load(configFile.toFile()); } catch (IOException ex) { throw new SkyConfigurationException("IOException loading messages file " + configFile.toAbsolutePath(), ex); } catch (InvalidConfigurationException ex) { throw new SkyConfigurationException("Messages file " + configFile.toAbsolutePath() + " is invalid", ex); } return config; }
public MagicSpellsListener(MobArena plugin) { this.plugin = plugin; // Set up the MagicSpells config-file. File file = new File(plugin.getDataFolder(), "magicspells.yml"); if (!file.exists()) { plugin.saveResource("magicspells.yml", false); plugin.getLogger().info("magicspells.yml created."); } try { FileConfiguration config = new YamlConfiguration(); config.load(file); setupSpells(config); } catch (Exception e) { e.printStackTrace(); } }
/** * Reloads the content from the fileSystem. */ @Override public void reload() { this.items.clear(); try { synchronized (this.fileName) { final File storage = new File(this.plugin.getDataFolder(), this.fileName); final FileConfiguration configuration = new YamlConfiguration(); configuration.load(storage); final Map<String, Object> data = ((MemorySection) configuration.get("meta")).getValues(false); for (final String key : data.keySet()) { try { final BallMeta ballMeta = new BallData(((MemorySection) ((MemorySection) data.get(key)).get("ball")).getValues(true)); this.items.add(ballMeta); } catch (final Exception e) { this.plugin.getLogger().log(Level.WARNING, "Failed to load meta " + key + '.', e); } } } } catch (IOException | InvalidConfigurationException ex) { this.plugin.getLogger().log(Level.WARNING, "Failed to load meta.", ex); } }
public SkyArenaConfig loadArena(Path file, String name) throws SkyConfigurationException { FileConfiguration config = new YamlConfiguration(); try { config.load(file.toFile()); } catch (FileNotFoundException ex) { throw new SkyConfigurationException("File " + file.toAbsolutePath() + " could not be found.", ex); } catch (IOException ex) { throw new SkyConfigurationException("IOException loading file " + file.toAbsolutePath(), ex); } catch (InvalidConfigurationException ex) { throw new SkyConfigurationException("Failed to load configuration file " + file.toAbsolutePath(), ex); } if (!checkVersion(config)) { throw new SkyConfigurationException("Unknown config-version " + config.getInt("config-version") + " in file " + file.toAbsolutePath()); } SkyArenaConfig arenaConfig = SkyArenaConfig.deserialize(config); arenaConfig.setArenaName(name); arenaConfig.setFile(file); return arenaConfig; }
/** * Saves all stored items into the file asynchronly. */ @Override public void persist() { final BallMeta[] items = this.items.toArray(new BallMeta[this.items.size()]); this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { try { synchronized (this.fileName) { final File storage = new File(this.plugin.getDataFolder(), this.fileName); final FileConfiguration configuration = new YamlConfiguration(); configuration.load(storage); for (int i = 0; i < items.length; i++) { final ConfigurationSerializable serializable = (ConfigurationSerializable) items[i]; configuration.set("meta." + (i + 1) + ".ball", serializable.serialize()); configuration.save(storage); } } } catch (IOException | InvalidConfigurationException ex) { this.plugin.getLogger().log(Level.WARNING, "Failed to save meta.", ex); } }); }
public void loadAndSpawn(UUID uuid) { this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { try { synchronized (this.fileName) { final File storageFile = new File(this.plugin.getDataFolder(), this.fileName); if (!storageFile.exists()) return; final FileConfiguration configuration = new YamlConfiguration(); configuration.load(storageFile); final String dataUUID = uuid.toString(); final Map<String, Object> balls = ((MemorySection) configuration.get("balls")).getValues(false); if (balls.containsKey(dataUUID)) { final Map<String, Object> data = ((MemorySection) balls.get(dataUUID)).getValues(true); this.plugin.getServer().getScheduler().runTask(this.plugin, () -> { final BukkitBall ball = this.create(uuid, data); this.store(ball); }); } } } catch (IOException | InvalidConfigurationException ex) { this.plugin.getLogger().log(Level.WARNING, "Failed to load ball.", ex); } }); }
/** * Saves the current ball and destroys the entity from the server. * * @param destroy should ball be destroyed after saving * @param ball ball */ public void saveAndDestroy(Ball ball, boolean destroy) { this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { try { synchronized (this.fileName) { final File storageFile = new File(this.plugin.getDataFolder(), this.fileName); final FileConfiguration configuration = new YamlConfiguration(); configuration.load(storageFile); final ConfigurationSerializable serializable = (ConfigurationSerializable) ball; configuration.set("balls." + ball.getUUID().toString(), serializable.serialize()); configuration.save(storageFile); if (destroy) { this.plugin.getServer().getScheduler().runTask(this.plugin, ball::remove); } } } catch (IOException | InvalidConfigurationException ex) { this.plugin.getLogger().log(Level.WARNING, "Failed to save ball.", ex); } }); }
public boolean doExport() { try { callback.begin(); config.load(file); loadCompletions(); exportPlayers(); exportMinigames(); exportStats(); notifyNext("Done"); callback.end(); notifier.onComplete(); return true; } catch (InvalidConfigurationException | IOException e) { notifier.onError(e, notifyState, notifyCount); return false; } }