Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#save()
The following examples show how to use
org.bukkit.configuration.file.YamlConfiguration#save() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NMSUtilsHologramInteraction.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
private void updateHologramDatabase() { try { // update hologram-database file File file = new File(Main.getInstance().getDataFolder(), "holodb.yml"); YamlConfiguration config = new YamlConfiguration(); if (!file.exists()) { file.createNewFile(); } config.set("locations", hologramLocations); config.save(file); } catch (Exception ex) { ex.printStackTrace(); } }
Example 2
Source File: CustomGunItem.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@Override public void initIronsights(File dataFolder) { File ironsights = new File(dataFolder, "default_ironsightstoggleitem.yml"); YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights); if (!ironconfig.contains("displayname")) { ironconfig.set("material", Material.CROSSBOW.name()); ironconfig.set("id", 68); ironconfig.set("displayname", IronsightsHandler.ironsightsDisplay); try { ironconfig.save(ironsights); } catch (IOException e) { e.printStackTrace(); } } IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material")); IronsightsHandler.ironsightsData = ironconfig.getInt("id"); IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname"); }
Example 3
Source File: CustomGunItem.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@Override public void initIronsights(File dataFolder) { File ironsights = new File(dataFolder,"default_ironsightstoggleitem.yml"); YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights); if(!ironconfig.contains("displayname")){ ironconfig.set("material",Material.DIAMOND_AXE.name()); ironconfig.set("id",21); ironconfig.set("displayname",IronsightsHandler.ironsightsDisplay); try { ironconfig.save(ironsights); } catch (IOException e) { e.printStackTrace(); } } IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material")); IronsightsHandler.ironsightsData = ironconfig.getInt("id"); IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname"); }
Example 4
Source File: TopTen.java From askyblock with GNU General Public License v2.0 | 6 votes |
public void topTenSave() { if (topTenList == null) { return; } //plugin.getLogger().info("Saving top ten list"); // Make file File topTenFile = new File(plugin.getDataFolder(), "topten.yml"); // Make configuration YamlConfiguration config = new YamlConfiguration(); // Save config int rank = 0; for (Map.Entry<UUID, Long> m : topTenList.entrySet()) { if (rank++ == 10) { break; } config.set("topten." + m.getKey().toString(), m.getValue()); } try { config.save(topTenFile); } catch (Exception e) { plugin.getLogger().severe("Could not save top ten list!"); e.printStackTrace(); } }
Example 5
Source File: HologramAPIInteraction.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
private void updateHologramDatabase() { try { // update hologram-database file File file = new File(BedwarsRel.getInstance().getDataFolder(), "holodb.yml"); YamlConfiguration config = new YamlConfiguration(); List<Map<String, Object>> serializedLocations = new ArrayList<Map<String, Object>>(); for (Location holoLocation : this.hologramLocations) { serializedLocations.add(Utils.locationSerialize(holoLocation)); } if (!file.exists()) { file.createNewFile(); } config.set("locations", serializedLocations); config.save(file); } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); ex.printStackTrace(); } }
Example 6
Source File: UUIDVaultManager.java From PlayerVaults with GNU General Public License v3.0 | 6 votes |
public void saveFileSync(final String holder, final YamlConfiguration yaml) { if (cachedVaultFiles.containsKey(holder)) { cachedVaultFiles.put(holder, yaml); } final boolean backups = PlayerVaults.getInstance().isBackupsEnabled(); final File backupsFolder = PlayerVaults.getInstance().getBackupsFolder(); final File file = new File(directory, holder + ".yml"); if (file.exists() && backups) { file.renameTo(new File(backupsFolder, holder + ".yml")); } try { yaml.save(file); } catch (IOException e) { PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save vault file for: " + holder, e); } }
Example 7
Source File: WorldBorder.java From Carbon with GNU Lesser General Public License v3.0 | 6 votes |
public static void save() { for (Entry<World, WorldBorder> entry : worldsWorldBorder.entrySet()) { WorldBorder worldborder = entry.getValue(); YamlConfiguration config = new YamlConfiguration(); config.set("x", worldborder.x); config.set("z", worldborder.z); config.set("damageAmount", worldborder.damageAmount); config.set("damageBuffer", worldborder.damageBuffer); config.set("warningBlocks", worldborder.warningBlocks); config.set("warningTime", worldborder.warningTime); if (worldborder.getStatus() != EnumWorldBorderStatus.STATIONARY) { config.set("lerpTime", worldborder.lerpEndTime - worldborder.lerpStartTime); config.set("currentRadius", worldborder.currentRadius); } config.set("oldRadius", worldborder.oldRadius); try { config.save(new File(entry.getKey().getWorldFolder(), "worldborder.yml")); } catch (IOException e) { e.printStackTrace(System.out); } } }
Example 8
Source File: NMSUtilsHologramInteraction.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
private void updateHologramDatabase() { try { // update hologram-database file File file = new File(Main.getInstance().getDataFolder(), "holodb.yml"); YamlConfiguration config = new YamlConfiguration(); if (!file.exists()) { file.createNewFile(); } config.set("locations", hologramLocations); config.save(file); } catch (Exception ex) { ex.printStackTrace(); } }
Example 9
Source File: HolographicDisplaysInteraction.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
private void updateHologramDatabase() { try { // update hologram-database file File file = new File(BedwarsRel.getInstance().getDataFolder(), "holodb.yml"); YamlConfiguration config = new YamlConfiguration(); List<Map<String, Object>> serializedLocations = new ArrayList<Map<String, Object>>(); for (Location holoLocation : this.hologramLocations) { serializedLocations.add(Utils.locationSerialize(holoLocation)); } if (!file.exists()) { file.createNewFile(); } config.set("locations", serializedLocations); config.save(file); } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); ex.printStackTrace(); } }
Example 10
Source File: VaultManager.java From PlayerVaults with GNU General Public License v3.0 | 6 votes |
public void saveFileSync(final String holder, final YamlConfiguration yaml) { if (cachedVaultFiles.containsKey(holder)) { cachedVaultFiles.put(holder, yaml); } final boolean backups = PlayerVaults.getInstance().isBackupsEnabled(); final File backupsFolder = PlayerVaults.getInstance().getBackupsFolder(); final File file = new File(directory, holder + ".yml"); if (file.exists() && backups) { file.renameTo(new File(backupsFolder, holder + ".yml")); } try { yaml.save(file); } catch (IOException e) { PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save vault file for: " + holder, e); } PlayerVaults.debug("Saved vault for " + holder); }
Example 11
Source File: UsersFile.java From WildernessTp with MIT License | 5 votes |
private void save(YamlConfiguration users){ try{ users.save(file); }catch(IOException e){ e.printStackTrace(); } }
Example 12
Source File: WorldFlatFileRegionManager.java From RedProtect with GNU General Public License v3.0 | 5 votes |
private void saveYaml(YamlConfiguration fileDB, File file) { try { fileDB.save(file); } catch (IOException e) { RedProtect.get().logger.severe("Error during save database file for world " + world + ": "); CoreUtil.printJarVersion(); e.printStackTrace(); } }
Example 13
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 5 votes |
private void saveYaml(YamlConfiguration fileDB, File file) { try { fileDB.save(file); } catch (IOException e) { RedProtect.get().logger.severe("Error during save database file"); printJarVersion(); e.printStackTrace(); } }
Example 14
Source File: MessageHandler.java From CratesPlus with GNU General Public License v3.0 | 5 votes |
public static void loadMessageConfiguration(CratesPlus cratesPlus, YamlConfiguration config, File file) { MessageHandler.cratesPlus = cratesPlus; MessageHandler.config = config; MessageHandler.file = file; handleConversion(); try { config.save(file); } catch (IOException e) { e.printStackTrace(); } }
Example 15
Source File: FlatFileConfig.java From NametagEdit with GNU General Public License v3.0 | 5 votes |
private void save(YamlConfiguration config, File file) { try { config.save(file); } catch (IOException e) { e.printStackTrace(); } }
Example 16
Source File: ConverterTask.java From NametagEdit with GNU General Public License v3.0 | 5 votes |
private void convertDatabaseToFile(Connection connection) { try { final String GROUP_QUERY = "SELECT name, prefix, suffix, permission, priority FROM " + DatabaseConfig.TABLE_GROUPS; final String PLAYER_QUERY = "SELECT name, uuid, prefix, suffix, priority FROM " + DatabaseConfig.TABLE_PLAYERS; final File groupsFile = new File(plugin.getDataFolder(), "groups_CONVERTED.yml"); final File playersFile = new File(plugin.getDataFolder(), "players_CONVERTED.yml"); final YamlConfiguration groups = Utils.getConfig(groupsFile); final YamlConfiguration players = Utils.getConfig(playersFile); ResultSet results = connection.prepareStatement(GROUP_QUERY).executeQuery(); while (results.next()) { groups.set("Groups." + results.getString("name") + ".Permission", results.getString("permission")); groups.set("Groups." + results.getString("name") + ".Prefix", results.getString("prefix")); groups.set("Groups." + results.getString("name") + ".Suffix", results.getString("suffix")); groups.set("Groups." + results.getString("name") + ".SortPriority", results.getInt("priority")); } results = connection.prepareStatement(PLAYER_QUERY).executeQuery(); while (results.next()) { players.set("Players." + results.getString("uuid") + ".Name", results.getString("name")); players.set("Players." + results.getString("uuid") + ".Prefix", results.getString("prefix")); players.set("Players." + results.getString("uuid") + ".Suffix", results.getString("suffix")); players.set("Players." + results.getString("uuid") + ".SortPriority", results.getInt("priority")); } results.close(); groups.save(groupsFile); players.save(playersFile); } catch (SQLException | IOException e) { e.printStackTrace(); } }
Example 17
Source File: Game.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
private void createGameConfig(File config) { YamlConfiguration yml = new YamlConfiguration(); yml.set("name", this.name); yml.set("world", this.getRegion().getWorld().getName()); yml.set("loc1", Utils.locationSerialize(this.loc1)); yml.set("loc2", Utils.locationSerialize(this.loc2)); yml.set("lobby", Utils.locationSerialize(this.lobby)); yml.set("minplayers", this.getMinPlayers()); if (BedwarsRel.getInstance().getBooleanConfig("store-game-records", true)) { yml.set("record", this.record); if (BedwarsRel.getInstance().getBooleanConfig("store-game-records-holder", true)) { yml.set("record-holders", this.recordHolders); } } if (this.regionName == null) { this.regionName = this.region.getName(); } yml.set("regionname", this.regionName); yml.set("time", this.time); yml.set("targetmaterial", this.getTargetMaterial().name()); yml.set("builder", this.builder); if (this.hologramLocation != null) { yml.set("hololoc", Utils.locationSerialize(this.hologramLocation)); } if (this.mainLobby != null) { yml.set("mainlobby", Utils.locationSerialize(this.mainLobby)); } yml.set("autobalance", this.autobalance); yml.set("spawner", this.resourceSpawners); yml.createSection("teams", this.teams); try { yml.save(config); this.config = yml; } catch (IOException e) { BedwarsRel.getInstance().getBugsnag().notify(e); BedwarsRel.getInstance().getLogger().info(ChatWriter.pluginMessage(e.getMessage())); } }
Example 18
Source File: UCConfig.java From UltimateChat with GNU General Public License v3.0 | 4 votes |
public void addChannel(UCChannel ch) throws IOException { File defch = new File(UChat.get().getDataFolder(), "channels" + File.separator + ch.getName().toLowerCase() + ".yml"); YamlConfiguration chFile = YamlConfiguration.loadConfiguration(defch); chFile.options().header("" + "###################################################\n" + "############## Channel Configuration ##############\n" + "###################################################\n" + "\n" + "This is the channel configuration.\n" + "You can change and copy this file to create as many channels you want.\n" + "This is the default options:\n" + "\n" + "name: Global - The name of channel.\n" + "alias: g - The alias to use the channel\n" + "across-worlds: true - Send messages of this channel to all worlds?\n" + "distance: 0 - If across worlds is false, distance to receive this messages.\n" + "color: &b - The color of channel\n" + "tag-builder: ch-tags,world,clan-tag,marry-tag,group-prefix,nickname,group-suffix,message - Tags of this channel\n" + "need-focus: false - Player can use the alias or need to use '/ch g' to use this channel?\n" + "canLock: true - Change if the player can use /<channel> to lock on channel." + "receivers-message: true - Send chat messages like if 'no players near to receive the message'?\n" + "cost: 0.0 - Cost to player use this channel.\n" + "use-this-builder: false - Use this tag builder or use the 'config.yml' tag-builder?\n" + "channelAlias - Use this channel as a command alias.\n" + " enable: true - Enable this execute a command alias?\n" + " sendAs: player - Send the command alias as 'player' or 'console'?\n" + " cmd: '' - Command to send on every message send by this channel.\n" + "available-worlds - Worlds and only this world where this chat can be used and messages sent/received.\n" + "discord:\n" + " mode: NONE - The options are NONE, SEND, LISTEN, BOTH. If enabled and token code set and the channel ID matches with one discord channel, will react according the choosen mode.\n" + " hover: &3Discord Channel: &a{dd-channel}\\n&3Role Name: {dd-rolecolor}{dd-rolename}\n" + " format-to-mc: {ch-color}[{ch-alias}]&b{dd-rolecolor}[{dd-rolename}]{sender}&r: \n" + " format-to-dd: :thought_balloon: **{sender}**: {message} \n" + " allow-server-cmds: false - Use this channel to send commands from discord > minecraft.\n" + " channelID: '' - The IDs of your Discord Channels. Enable debug on your discord to get the channel ID.\n" + " Note: You can add more than one discord id, just separate by \",\" like: 13246579865498,3216587898754\n"); ch.getProperties().forEach((key, value) -> chFile.set((String) key, value)); chFile.save(defch); if (UChat.get().getChannel(ch.getName()) != null) { ch.setMembers(UChat.get().getChannel(ch.getName()).getMembers()); UChat.get().getChannels().remove(Arrays.asList(ch.getName().toLowerCase(), ch.getAlias().toLowerCase())); } UChat.get().getChannels().put(Arrays.asList(ch.getName().toLowerCase(), ch.getAlias().toLowerCase()), ch); }
Example 19
Source File: UCConfig.java From UltimateChat with GNU General Public License v3.0 | 4 votes |
private void loadChannels() throws IOException { File chfolder = new File(UChat.get().getDataFolder(), "channels"); if (!chfolder.exists()) { chfolder.mkdir(); UChat.get().getUCLogger().info("Created folder: " + chfolder.getPath()); } if (UChat.get().getChannels() == null) { UChat.get().setChannels(new HashMap<>()); } File[] listOfFiles = chfolder.listFiles(); YamlConfiguration channel; if (Objects.requireNonNull(listOfFiles).length == 0) { //create default channels File g = new File(chfolder, "global.yml"); channel = YamlConfiguration.loadConfiguration(g); channel.set("name", "Global"); channel.set("alias", "g"); channel.set("color", "&2"); channel.set("jedis", false); channel.set("dynmap.enable", true); channel.save(g); File l = new File(chfolder, "local.yml"); channel = YamlConfiguration.loadConfiguration(l); channel.set("name", "Local"); channel.set("alias", "l"); channel.set("color", "&e"); channel.set("jedis", false); channel.set("across-worlds", false); channel.set("distance", 40); channel.save(l); File ad = new File(chfolder, "admin.yml"); channel = YamlConfiguration.loadConfiguration(ad); channel.set("name", "Admin"); channel.set("alias", "ad"); channel.set("color", "&b"); channel.set("jedis", false); channel.save(ad); listOfFiles = chfolder.listFiles(); } for (File file : Objects.requireNonNull(listOfFiles)) { if (file.getName().endsWith(".yml")) { channel = YamlConfiguration.loadConfiguration(file); UCChannel ch = new UCChannel(channel.getValues(true)); try { addChannel(ch); } catch (IOException e) { e.printStackTrace(); } } } }
Example 20
Source File: ConverterChestCommands.java From TrMenu with MIT License | 4 votes |
private static int convert(File file, int count) { if (file.isDirectory()) { for (File f : file.listFiles()) { count += convert(f, count); } return count; } else if (!file.getName().endsWith(".yml")) { return count; } try { ListIterator<Character> buttons = Arrays.asList('#', '-', '+', '=', '<', '>', '~', '_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z').listIterator(); YamlConfiguration trmenu = new YamlConfiguration(); YamlConfiguration conf = YamlConfiguration.loadConfiguration(file); List<String> cmds = conf.contains("menu-settings.command") ? Arrays.asList(conf.getString("menu-settings.command").split(";( )?")) : new ArrayList<>(); for (int i = 0; i < cmds.size(); i++) { cmds.set(i, cmds.get(i) + "-fromCC"); } int rows = conf.getInt("menu-settings.rows", 6); int update = conf.getInt("menu-settings.auto-refresh", -1) * 20; trmenu.set("Title", conf.getString("menu-settings.name")); trmenu.set("Open-Commands", cmds); trmenu.set("Open-Actions", conf.contains("menu-settings.open-action") ? conf.getString("menu-settings.open-action").split(";( )?") : ""); List<String> shape = Lists.newArrayList(); while (rows > 0) { shape.add(" "); rows--; } trmenu.set("Shape", shape); conf.getValues(false).forEach((icon, value) -> { if (!"menu-settings".equalsIgnoreCase(icon)) { MemorySection section = (MemorySection) value; int x = section.getInt("POSITION-X") - 1; int y = section.getInt("POSITION-Y") - 1; char[] chars = shape.get(y).toCharArray(); char symbol = buttons.next(); chars[x] = symbol; shape.set(y, new String(chars)); if (update > 0) { trmenu.set("Buttons." + symbol + ".update", update); } trmenu.set("Buttons." + symbol + ".display.mats", section.get("ID")); trmenu.set("Buttons." + symbol + ".display.name", section.get("NAME")); trmenu.set("Buttons." + symbol + ".display.lore", section.get("LORE")); if (section.contains("COMMAND")) { trmenu.set("Buttons." + symbol + ".actions.all", section.getString("COMMAND").split(";( )?")); } if (section.contains("ENCHANTMENT")) { trmenu.set("Buttons." + symbol + ".display.shiny", true); } } }); trmenu.set("Shape", fixShape(shape)); file.renameTo(new File(file.getParent(), file.getName().replace(".yml", "") + ".CONVERTED.TRMENU")); trmenu.save(new File(TrMenu.getPlugin().getDataFolder(), "menus/" + file.getName().replace(".yml", "") + "-fromcc.yml")); return count + 1; } catch (Throwable e) { e.printStackTrace(); } return count; }