static public void loadMessage(){ File messageFile = new File("plugins" + File.separator + "PVPAsWantedManager" + File.separator + "message.yml"); if(!messageFile.exists()){ if(Config.getConfig("language").equals("CN")){ createCNMessage(); }else if(Config.getConfig("language").equals("EN")){ //TODO createENMessage(); }else{ createCNMessage(); } }else{ Bukkit.getConsoleSender().sendMessage("§8[§6PVPAsWantedManager§8] §aFind Message.yml"); } messages = new YamlConfiguration(); try {messages.load(messageFile);} catch (IOException | InvalidConfigurationException e) {e.printStackTrace();Bukkit.getConsoleSender().sendMessage("§8[§6PVPAsWantedManager§8] §a读取message时发生错误");} }
@EventHandler public void onJoin(PlayerJoinEvent event){ Player p = event.getPlayer(); if(!Files.user.contains("Users." + p.getName())){ Files.user.set("Users." + p.getName() + ".pvp", false); manager.addNewbie(p); try{ Files.user.save(Files.users); Files.user.load(Files.users); }catch(IOException | InvalidConfigurationException e){ e.printStackTrace(); } return; } }
@EventHandler public void onLeave(PlayerQuitEvent event){ Player p = event.getPlayer(); if(Files.user.contains("Users." + p.getName())){ try{ Files.user.save(Files.users); Files.user.load(Files.users); }catch(IOException | InvalidConfigurationException e){ // TODO Auto-generated catch block e.printStackTrace(); } if(manager.isInPvP(p)){ p.setHealth(0D); Bukkit.broadcastMessage(Message.prefix + ChatColor.GRAY + " ¡" + ChatColor.GOLD + p.getName() + Message.leave_in_pvp); } } }
public void saveFiles(){ try{ config.save(fileConfig); users.save(fileUsers); fl.save(fileFL); casino.save(fileCasino); rain.save(fileRain); config.load(fileConfig); users.load(fileUsers); fl.load(fileFL); casino.load(fileCasino); rain.load(fileRain); }catch (java.io.IOException | InvalidConfigurationException e){ e.printStackTrace(); } }
public static ItemStack StringToItemStack(String string) { if (string == null) { return null; } YamlConfiguration yaml = new YamlConfiguration(); try { yaml.loadFromString(string); } catch (InvalidConfigurationException e) { e.printStackTrace(); } if (yaml.contains("item")) { return yaml.getItemStack("item", null); } else { return yaml.getItemStack("i", null); } }
private void load(JavaPlugin plugin) { try { final FileConfiguration configuration = new YamlConfiguration(); final File file = new File(plugin.getDataFolder(), "bungeecord_signs.yml"); if (!file.exists()) { if (!file.createNewFile()) { Bukkit.getLogger().log(Level.WARNING, "File cannot get created."); } } configuration.load(file); if (configuration.getConfigurationSection("signs") != null) { final Map<String, Object> data = configuration.getConfigurationSection("signs").getValues(false); for (final String s : data.keySet()) { this.signs.add(new BungeeCordSignInfo.Container(((ConfigurationSection) data.get(s)).getValues(true))); } } } catch (IOException | InvalidConfigurationException e) { Bukkit.getLogger().log(Level.WARNING, "Save load location.", e); } }
void save(Arena item) { if (item != null && item.getName() != null) { try { final FileConfiguration configuration = new YamlConfiguration(); final File file = new File(this.getFolder(), "arena_" + item.getName() + ".yml"); if (file.exists()) { if (!file.delete()) throw new IllegalStateException("Cannot delete file!"); } if (!file.createNewFile()) throw new IllegalStateException("Cannot create file!"); configuration.load(file); final Map<String, Object> data = item.serialize(); for (final String key : data.keySet()) { configuration.set("arena." + key, data.get(key)); } configuration.save(file); } catch (IOException | InvalidConfigurationException ex) { Bukkit.getLogger().log(Level.WARNING,"Cannot save arena." ,ex.getMessage()); } } }
public static void create() throws IOException{ File pluginFolder = DogTags.getInstance().getDataFolder(); f = new File(pluginFolder, "config.yml"); if(!f.exists()){ f.getParentFile().mkdirs(); DogTags.getInstance().saveResource(f.getName(), false); LogUtil.outputMsg("File &6%file% &fdoesn't exist, creating file!".replace("%file%", f.getName())); } fc = new YamlConfiguration(); try { fc.load(f); } catch (InvalidConfigurationException e) { e.printStackTrace(); } }
/**Static method to get a modules config alone, returns null if failed. * The loading is tested during the initial yml test and should therefore work during DunGen runtime. * @param parent The parent plugin * @param name The modules name for witch the config should be loaded (file 'name'.yml) * @return The config object. Returns null if errors occured and sets plugin state to ERROR. */ public static YamlConfiguration getConfig(DunGen parent, String name) { File confFile = new File(parent.getDataFolder(),name+".yml"); if (!confFile.exists()) { parent.setStateAndNotify(State.ERROR, "Config file for module " + name + " could not be found!"); return null; } YamlConfiguration conf = new YamlConfiguration(); try { conf.load(confFile); }catch (IOException | InvalidConfigurationException e) { parent.setStateAndNotify(State.ERROR, "Loading of config file for module " + name + " failed:"); e.printStackTrace(); return null; } // everything ok, if code reached here. parent.getLogger().info("YML file for module " + name + " loaded."); return conf; }
private void finishHandshake(ChannelHandlerContext ctx, FullHttpResponse response) { if (response.getStatus().equals(HttpResponseStatus.SWITCHING_PROTOCOLS)) { try { handshaker.finishHandshake(ctx.channel(), response); connection.handshakeFuture.setSuccess(); logger.info("Successfully connected to AudioConnect server!"); return; } catch (Exception e) { connection.handshakeFuture.setFailure(e); } } else { connection.handshakeFuture.setFailure(new InvalidConfigurationException()); } String responseMsg = response.content().toString(StandardCharsets.UTF_8); logger.severe("Failed to Connect with AudioConnect server: " + responseMsg); logger.severe("Stopping client event loop due to failure to establish connection with AudioConnect server"); disconnect(); }
/** * Creates the config file if it doesn't exist yet. * If there are exceptions the stacktrace will be printed. */ private void createFile() { if (file == null) { new InvalidConfigurationException("File cannot be null!").printStackTrace(); } try { if (!file.exists()) { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } file.createNewFile(); } } catch (Exception e) { e.printStackTrace(); } }
/** * Load the config file in to memory. * The value of all fields will be set with the config values. */ public void load() { if (file != null) { try { if (!file.exists()) { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } file.createNewFile(); } conf.load(file); if (fields == null) { onLoad(conf); } else { onLoad(conf, fields); } conf.save(file); } catch (Exception e) { e.printStackTrace(); } } else { new InvalidConfigurationException("File cannot be null!").printStackTrace(); } }
/** * Save the config file to disk. * All values from the fields will be placed in the config. */ public void save() { if (file != null) { try { if (!file.exists()) { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } file.createNewFile(); } if (fields == null) { onSave(conf); } else { onSave(conf, fields); } conf.save(file); } catch (Exception e) { e.printStackTrace(); } } else { new InvalidConfigurationException("File cannot be null!").printStackTrace(); } }
public List<ItemStack> getTemporaryStorage(OfflinePlayer player) { Query<TempStorageRepo> result = query(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString()); if (result == null || result.count() == 0) return Collections.emptyList(); YamlConfiguration cfg = new YamlConfiguration(); try { cfg.loadFromString(result.selectUnique().yaml); } catch (InvalidConfigurationException ex) { ex.printStackTrace(); return Collections.emptyList(); } List<ItemStack> ret = new ArrayList<>(); for (String key : cfg.getKeys(false)) { ret.add(cfg.getItemStack(key)); } return ret; }
public List<ShopItem> loadItems(String path) { YamlConfiguration configuration = new YamlConfiguration(); try { configuration.loadFromString(this.yaml); } catch (InvalidConfigurationException e) { e.printStackTrace(); } ArrayList<ShopItem> list = new ArrayList<>(); if (configuration.isConfigurationSection(path)) { ConfigurationSection section = configuration.getConfigurationSection(path); for (String k : section.getKeys(false)) { list.add(new ShopItem(section.getConfigurationSection(k))); } } return list; }
public void saveItems(String path, List<ShopItem> list) { YamlConfiguration configuration = new YamlConfiguration(); try { configuration.loadFromString(this.yaml); } catch (InvalidConfigurationException e) { e.printStackTrace(); } configuration.set(path, null); ConfigurationSection section = configuration.createSection(path); for (int i = 0; i < list.size(); i++) { ShopItem item = list.get(i); if (item.getAmount() > 0 && item.getItemStack(1).getType() != Material.AIR) { list.get(i).save(section.createSection(String.valueOf(i))); } } this.yaml = configuration.saveToString(); }
/** * Loads this {@link FileConfiguration} from the specified reader. * <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. * * @param reader the reader to load from * @throws IOException thrown when underlying reader throws an IOException * @throws InvalidConfigurationException thrown when the reader does not * represent a valid Configuration * @throws IllegalArgumentException thrown when reader is null */ public void load(Reader reader) throws IOException, InvalidConfigurationException { BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); StringBuilder builder = new StringBuilder(); try { String line; while ((line = input.readLine()) != null) { builder.append(line); builder.append('\n'); } } finally { input.close(); } loadFromString(builder.toString()); }
public void load(ConfigurationSection config) throws InvalidConfigurationException { if (!config.contains("type") || !config.getString("type").equals("ecnf")) { throw new InvalidConfigurationException(); } head = config.getItemStack("head"); chest = config.getItemStack("chest"); legs = config.getItemStack("legs"); boots = config.getItemStack("boots"); if (config.contains("held")) { heldMain = config.getItemStack("held"); heldOff = null; } else { heldMain = config.getItemStack("main"); heldOff = config.getItemStack("offhand"); } }
public void load(ConfigurationSection config) throws InvalidConfigurationException { if (!config.contains("type") || !config.getString("type").equals("goalstate") || !config.contains("name")) { throw new InvalidConfigurationException(); } name = config.getString("name"); requirementStates = new LinkedList<>(); if (config.contains("requirementStates")) for (String reqKey : config.getConfigurationSection("requirementStates").getKeys(false)) { requirementStates.add( new RequirementState( config.getConfigurationSection("requirementStates") .getConfigurationSection(reqKey)) ); } }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { /* * type: intr * location: [loc] * [face]: [face enum name] * [action]: {LEFT/RIGHT} */ if (!config.contains("type") || !config.getString("type").equals("intr")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'intr' but got " + config.get("type", "null")); } this.location = ((LocationState) config.get("location")).getLocation(); if (config.contains("face")) { this.face = BlockFace.valueOf(config.getString("face")); } if (config.contains("action")) { this.action = getAction(config.getString("action")); } this.desc = config.getString("description", config.getString("action", "Right") + " click the area"); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { //we'll need start and end times //our config is // type: "timer" // startTime: <long> // endTime: <long> if (!config.contains("type") || !config.getString("type").equals("timer")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'timer' but got " + config.getString("type", "null")); } this.startTime = config.getLong("startTime"); this.endTime = config.getLong("endTime"); this.desc = config.getString("description", "Wait until between " + startTime + " and " + endTime); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { // same of Position Requirements's loading // type: "arrr" // range: [double] // destination: [location] if (!config.contains("type") || !config.getString("type").equals("arrr")) { throw new InvalidConfigurationException(); } this.desc = config.getString("description", "Arrive at the location"); this.targetRange = config.getDouble("range", 1.0); this.destination = ((LocationState) config.get("destination")).getLocation(); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { /* * type: talk * npc: [name] * message: [menu] */ if (!config.contains("type") || !config.getString("type").equals("talk")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'talk' but got " + config.get("type", "null")); } if (config.getString("npc") == null) { System.out.println("npc-null"); } npc = QuestManagerPlugin.questManagerPlugin.getManager().getNPC( config.getString("npc") ); Message message = (Message) config.get("message"); message.setSourceLabel(new FancyMessage(npc.getName())); menu = ChatMenu.getDefaultMenu(message); this.desc = config.getString("description", "Talk to " + npc.getName()); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { /* * type: craft * crafttype: [MATERIAL] * craftname: [string] * count: [int] */ if (!config.contains("type") || !config.getString("type").equals("craft")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'craft' but got " + config.get("type", "null")); } this.craftType = Material.matchMaterial(config.getString("craftType")); this.craftName = config.getString("craftName"); this.targetCount = config.getInt("count"); this.desc = config.getString("description", "Craft " + targetCount + " " + (craftName == null ? YamlWriter.toStandardFormat(craftType.name()) : craftName) + "(s)"); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { //we need to load information about what we need to possess and how much //our config is // type: "delr" // itemYype: (Material. ENUM CONSTANT NAME) // count: [int] // name: [string] if (!config.contains("type") || !config.getString("type").equals("delr")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'delr' but got " + config.getString("type", "null")); } this.itemType = Material.valueOf( config.getString("itemType", "AIR")); this.itemCount = config.getInt("count", 1); this.itemName = config.getString("name", ""); if (itemName.trim().isEmpty()) { itemName = null; } this.desc = config.getString("description", "Collect " + itemCount + " " + itemName == null ? itemType.toString() : itemName); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { //we need location information and range information // type: "posr" // range: [double] // destination: [location] if (!config.contains("type") || !config.getString("type").equals("posr")) { throw new InvalidConfigurationException(); } this.desc = config.getString("description", "Be in the target area"); this.targetRange = config.getDouble("range", 1.0); this.destination = ((LocationState) config.get("destination")).getLocation(); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { /* * type: chestr * chest: [chest] */ if (!config.contains("type") || !config.getString("type").equals("chestr")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'chestr' but got " + config.get("type", "null")); } if (!config.contains("chest")) { throw new InvalidConfigurationException("\nChest configuration did not contain chest information!"); } this.chest = (Chest) config.get("chest"); this.inv = null; this.desc = config.getString("description", "Search the chest"); }
@Override public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException { //we need to load information about what we need to possess and how much //our config is // type: "pr" // itemYype: (Material. ENUM CONSTANT NAME) // count: [int] if (!config.contains("type") || !config.getString("type").equals("pr")) { throw new InvalidConfigurationException("\n ---Invalid type! Expected 'pr' but got " + config.getString("type", "null")); } this.itemType = Material.valueOf( config.getString("itemType", "AIR")); this.itemCount = config.getInt("count", 1); this.itemName = config.getString("name", ""); if (itemName.trim().isEmpty()) { itemName = null; } this.desc = config.getString("description", "Collect " + itemCount + " " + itemName == null ? itemType.toString() : itemName); }
public static History fromConfig(ConfigurationSection configurationSection) throws InvalidConfigurationException { if (configurationSection == null) { return null; } if (!configurationSection.contains("HistoryEvents")) { throw new InvalidConfigurationException(); } History history = new History(); List<String> list; list = configurationSection.getStringList("HistoryEvents"); if (list != null && !list.isEmpty()) { for (String line : list) { history.addHistoryEvent(new HistoryEvent(line)); } } return history; }
public void loadState(GoalState state) throws InvalidConfigurationException { if (!state.getName().equals(name)) { QuestManagerPlugin.logger.warning("Loading state information" + "from a file that has a mismatched goal name!"); } //WARNING: //this is assuming that the lists are maintianed in the right order. //it should work this way, but this is a point of error! ListIterator<RequirementState> states = state.getRequirementStates().listIterator(); for (Requirement req : requirements) { req.sync(); try { if (req instanceof StatekeepingRequirement) { ((StatekeepingRequirement) req).loadState(states.next()); } } catch (NoSuchElementException e) { QuestManagerPlugin.logger.warning("Error when loading state for quest" + this.getQuest().getName() + "; Not enough requirement states!"); } } }
private void loadConfig() { FileConfiguration config = new YamlConfiguration(); try { config.load(new File(getDataFolder(), "config.yml")); config.options().copyDefaults(true); String user = config.getString("jdbc-username", "root"); String password = config.getString("jdbc-password", "password"); String jdbcUrl = config.getString("jdbc-url", "jdbc:mysql://localhost:3306/minecraft"); databaseManager = new DatabaseManager(jdbcUrl, user, password); databaseManager.connect(); ConfigurationSection definitions = config.getConfigurationSection("definitions"); for (String definitionKey : definitions.getKeys(false)) { ConfigurationSection definition = definitions.getConfigurationSection(definitionKey); int priority = definition.getInt("priority", 1); ImageType type = ImageType.valueOf(definition.getString("type", ImageType.OVERLAY.name())); String permission = definition.getString("permission"); List<String> images = definition.getStringList("images"); SpigotImageDetails imageDetails = new SpigotImageDetails(priority, type, permission, images); imageHandler.addImage(imageDetails); } config.save(new File(getDataFolder(), "config.yml")); } catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); } }
static public void loadConfig(){ if(!configFile.exists()){ createConfig(); return; }else{ Bukkit.getConsoleSender().sendMessage("§8[§6PVPAsWantedManager§8] §aFind Config.yml"); } config = new YamlConfiguration(); try {config.load(configFile);} catch (IOException | InvalidConfigurationException e) {e.printStackTrace();Bukkit.getConsoleSender().sendMessage("§8[§6PVPAsWantedManager§8] §a读取config时发生错误");} }
public void saveFiles(){ try{ config.save(fileConfig); config.load(fileConfig); users.save(fileUsers); users.load(fileUsers); clans.save(fileClans); clans.load(fileClans); }catch(IOException | InvalidConfigurationException e){ e.printStackTrace(); } }
private void save() { try { Files.user.save(Files.users); Files.user.load(Files.users); } catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); } }
private void saveFiles(){ try{ clang.save(lang); clang.load(lang); user.save(users); user.load(users); }catch(IOException | InvalidConfigurationException e){ e.printStackTrace(); } }
public void saveFiles(){ try { mobs.save(fileMobs); mobs.load(fileMobs); config.save(fileConfig); config.load(fileConfig); }catch (IOException | InvalidConfigurationException e){ e.printStackTrace(); } }
public void saveFiles(){ try{ player.save(filePlayers); player.load(filePlayers); config.save(fileConfig); config.load(fileConfig); }catch(IOException | InvalidConfigurationException e){ System.out.println("Error Files"); } }
private static YamlConfiguration load(String FileLocation) { File f = new File(FileLocation); YamlConfiguration cfg; cfg = setDefaults(); if ( ! f.exists()) { try { if(f.getParentFile().mkdir() && f.createNewFile()) { Bukkit.getServer().getLogger().log(Level.INFO, "[PrisonPicks] New Config Created at: " + FileLocation); cfg.save(new File(FileLocation)); } else { Bukkit.getServer().getLogger().log(Level.SEVERE, "[PrisonPicks] Failed to create Config file"); } }catch (IOException e1) { e1.printStackTrace(); } }else { try { cfg.load(f); }catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); } } return cfg; }
public void load() { YamlConfiguration cfg = new YamlConfiguration(); try { cfg.load(ensureFile()); } catch (IOException | InvalidConfigurationException ex) { throw new RuntimeException(ex); } deserialize(cfg); save(); }
private static ItemStack deserialize(String text) { if (text != null) { final FileConfiguration configuration = new YamlConfiguration(); try { configuration.loadFromString(text); } catch (final InvalidConfigurationException e) { Bukkit.getLogger().log(Level.WARNING, "Cannot deserialize itemsstack.", e); } return configuration.getItemStack("dummy"); } return null; }