Package org.bukkit.configuration.file

Examples of org.bukkit.configuration.file.YamlConfiguration


                        sender.sendMessage(ChatColor.DARK_RED + "I'm sorry, something funky happened... Import aborted.");
                        return;
                    }
                    List<WorldGroupProfile> mvgroups = mvinventories.getGroupManager().getGroups();
                    MultiInv.log.info("No groups.yml found. Creating example file...");
                    YamlConfiguration groups = new YamlConfiguration();
                    MIYamlFiles.getGroups().clear();
                    for(WorldGroupProfile mvgroup : mvgroups) {
                        Set<String> mvworlds = mvgroup.getWorlds();
                        ArrayList<String> exampleGroup = new ArrayList<String>();
                        for(String world : mvworlds) {
                            exampleGroup.add(world);
                            MIYamlFiles.getGroups().put(world, mvgroup.getName());
                        }
                        String group = mvgroup.getName();
                        groups.set(group, exampleGroup);
                        MIYamlFiles.saveYamlFile(groups, "groups.yml");
                        for(OfflinePlayer player1 : Bukkit.getServer().getOfflinePlayers()) {
                            PlayerProfile playerdata = mvgroup.getPlayerData(ProfileTypes.SURVIVAL, player1);
                            if(playerdata != null && playerdata.get(Sharables.INVENTORY) != null) {
                                ItemStack[] inventory = playerdata.get(Sharables.INVENTORY);
                                ItemStack[] armor = playerdata.get(Sharables.ARMOR);
                                Integer health = playerdata.get(Sharables.HEALTH);
                                Integer hunger = playerdata.get(Sharables.FOOD_LEVEL);
                                Float saturation = playerdata.get(Sharables.SATURATION);
                                Integer totalexp = playerdata.get(Sharables.TOTAL_EXPERIENCE);
                                PotionEffect[] potioneffects = playerdata.get(Sharables.POTIONS);
                                LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
                                if(potioneffects != null) {
                                    for(int i = 0; i < potioneffects.length; i++) {
                                        effects.add(potioneffects[i]);
                                    }
                                }
                                if(MIYamlFiles.usesql) {
                                    MIYamlFiles.con.saveInventory(player, group, new MIInventory(inventory, armor, effects), "SURVIVAL");
                                    MIYamlFiles.con.saveHealth(player, group, health);
                                    MIYamlFiles.con.saveHunger(player, group, hunger);
                                    MIYamlFiles.con.saveSaturation(player, group, saturation);
                                    MIYamlFiles.con.saveExperience(player, group, totalexp);
                                } else {
                                    MIPlayerFile config = new MIPlayerFile(player1, group);
                                    config.saveInventory(new MIInventory(inventory, armor, effects), "SURVIVAL");
                                    config.saveHealth(health);
                                    config.saveHunger(hunger);
                                    config.saveSaturation(saturation);
                                    int[] levels = plugin.getXP(totalexp);
                                    config.saveExperience(totalexp, levels[0], (float) ((float) levels[1] / (float) levels[2]));
                                }
                            }
                            PlayerProfile adventureplayerdata = mvgroup.getPlayerData(ProfileTypes.ADVENTURE, player1);
                            if(adventureplayerdata != null && adventureplayerdata.get(Sharables.INVENTORY) != null) {
                                ItemStack[] inventory = adventureplayerdata.get(Sharables.INVENTORY);
                                ItemStack[] armor = adventureplayerdata.get(Sharables.ARMOR);
                                PotionEffect[] potioneffects = adventureplayerdata.get(Sharables.POTIONS);
                                LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
                                if(potioneffects != null) {
                                    for(int i = 0; i < potioneffects.length; i++) {
                                        effects.add(potioneffects[i]);
                                    }
                                }
                                if(MIYamlFiles.usesql) {
                                    MIYamlFiles.con.saveInventory(player, group, new MIInventory(inventory, armor, effects), "ADVENTURE");
                                } else {
                                    MIPlayerFile config = new MIPlayerFile(player1, group);
                                    config.saveInventory(new MIInventory(inventory, armor, effects), "ADVENTURE");
                                }
                            }
                        }
                    }
                    for(World world : Bukkit.getWorlds()) {
                        String worldName = world.getName();
                        if(!MIYamlFiles.getGroups().containsKey(worldName)) {
                            WorldProfile worldprofile = mvinventories.getWorldManager().getWorldProfile(worldName);
                            for(OfflinePlayer player1 : Bukkit.getServer().getOfflinePlayers()) {
                                PlayerProfile playerdata = worldprofile.getPlayerData(ProfileTypes.SURVIVAL, player1);
                                if(playerdata != null && playerdata.get(Sharables.INVENTORY) != null) {
                                    ItemStack[] inventory = playerdata.get(Sharables.INVENTORY);
                                    ItemStack[] armor = playerdata.get(Sharables.ARMOR);
                                    Integer health = playerdata.get(Sharables.HEALTH);
                                    Integer hunger = playerdata.get(Sharables.FOOD_LEVEL);
                                    Float saturation = playerdata.get(Sharables.SATURATION);
                                    Integer totalexp = playerdata.get(Sharables.TOTAL_EXPERIENCE);
                                    PotionEffect[] potioneffects = playerdata.get(Sharables.POTIONS);
                                    LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
                                    if(potioneffects != null) {
                                        for(int i = 0; i < potioneffects.length; i++) {
                                            effects.add(potioneffects[i]);
                                        }
                                    }
                                    if(MIYamlFiles.usesql) {
                                        MIYamlFiles.con.saveInventory(player, worldName, new MIInventory(inventory, armor, effects), "SURVIVAL");
                                        MIYamlFiles.con.saveHealth(player, worldName, health);
                                        MIYamlFiles.con.saveHunger(player, worldName, hunger);
                                        MIYamlFiles.con.saveSaturation(player, worldName, saturation);
                                        MIYamlFiles.con.saveExperience(player, worldName, totalexp);
                                    } else {
                                        MIPlayerFile config = new MIPlayerFile(player1, worldName);
                                        config.saveInventory(new MIInventory(inventory, armor, effects), "SURVIVAL");
                                        config.saveHealth(health);
                                        config.saveHunger(hunger);
                                        config.saveSaturation(saturation);
                                        int[] levels = plugin.getXP(totalexp);
                                        config.saveExperience(totalexp, levels[0], (float) ((float) levels[1] / (float) levels[2]));
                                    }
                                }
                                PlayerProfile adventureplayerdata = worldprofile.getPlayerData(ProfileTypes.ADVENTURE, player1);
                                if(adventureplayerdata != null && adventureplayerdata.get(Sharables.INVENTORY) != null) {
                                    ItemStack[] inventory = adventureplayerdata.get(Sharables.INVENTORY);
                                    ItemStack[] armor = adventureplayerdata.get(Sharables.ARMOR);
                                    PotionEffect[] potioneffects = adventureplayerdata.get(Sharables.POTIONS);
                                    LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
                                    if(potioneffects != null) {
                                        for(int i = 0; i < potioneffects.length; i++) {
                                            effects.add(potioneffects[i]);
                                        }
                                    }
                                    if(MIYamlFiles.usesql) {
                                        MIYamlFiles.con.saveInventory(player, worldName, new MIInventory(inventory, armor, effects), "ADVENTURE");
                                    } else {
                                        MIPlayerFile config = new MIPlayerFile(player1, worldName);
                                        config.saveInventory(new MIInventory(inventory, armor, effects), "ADVENTURE");
                                    }
                                }
                            }
                        }
                    }
                    // Once the groups are loaded, let's load them into MultiInv
                    MIYamlFiles.parseGroups(groups);
                    // Once the import is done let's disable MultiVerse-Inventories.
                    Bukkit.getPluginManager().disablePlugin(mvinventories);
                    sender.sendMessage(ChatColor.DARK_GREEN + "Multiverse-Inventories inventories imported successfuly!");
                    sender.sendMessage(ChatColor.DARK_GREEN + "Please disable/delete Multiverse-Inventories now.");
                }
            } else if(command.equalsIgnoreCase("miimport")) {
                Plugin p = plugin.getServer().getPluginManager().getPlugin("WorldInventories");
                if(p == null) {
                    sender.sendMessage(ChatColor.DARK_RED + "I'm sorry, WorldInventories isn't loaded... Import aborted.");
                } else {
                    WorldInventories mvinventories;
                    try {
                        mvinventories = (WorldInventories) p;
                    } catch(Exception e) {
                        MultiInv.log.severe("Unable to import inventories from WorldInventories.");
                        sender.sendMessage(ChatColor.DARK_RED + "I'm sorry, something funky happened... Import aborted.");
                        return;
                    }
                    ArrayList<Group> mvgroups = WorldInventories.groups;
                    YamlConfiguration groups = new YamlConfiguration();
                    MIYamlFiles.getGroups().clear();
                    for(Group mvgroup : mvgroups) {
                        List<String> mvworlds = mvgroup.getWorlds();
                        ArrayList<String> exampleGroup = new ArrayList<String>();
                        for(String world : mvworlds) {
                            exampleGroup.add(world);
                            MIYamlFiles.getGroups().put(world, mvgroup.getName());
                        }
                        String group = mvgroup.getName();
                        groups.set(group, exampleGroup);
                        MIYamlFiles.saveYamlFile(groups, "groups.yml");
                        for(OfflinePlayer player1 : Bukkit.getServer().getOfflinePlayers()) {
                            plugin.getLogger().info("Importing player " + player1.getName() + "'s inventory from group " + mvgroup.getName());
                            HashMap<Integer, ItemStack[]> pinventory = mvinventories.loadPlayerInventory(player1.getName(), mvgroup, InventoryLoadType.INVENTORY);
                            HashMap<Integer, ItemStack[]> playerenderchest = mvinventories.loadPlayerInventory(player1.getName(), mvgroup, InventoryLoadType.ENDERCHEST);
View Full Code Here


        String filename = getString(key);
        if (extraConfig.containsKey(filename)) {
            return extraConfig.get(filename);
        }

        final YamlConfiguration conf = new YamlConfiguration();
        final File file = getFile(filename), migrateFrom = new File(key.def.toString());

        // create file if it doesn't exist
        if (!file.exists()) {
            if (migrateFrom.exists()) {
                FileUtil.copy(migrateFrom, file);
            } else {
                copyDefaults(key.def.toString(), file);
            }
        }

        // read in config
        try {
            conf.load(file);
        } catch (IOException e) {
            GlowServer.logger.log(Level.SEVERE, "Failed to read config: " + file, e);
        } catch (InvalidConfigurationException e) {
            report(file, e);
        }
View Full Code Here

    private boolean migrate() {
        boolean migrateStatus = false;

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

        final File serverProps = new File("server.properties");
        if (serverProps.exists()) {
            Properties props = new Properties();
View Full Code Here

    /**
     * Migrate the worlds.yml to SerializationConfig.
     */
    private void migrateWorldConfig() { // SUPPRESS CHECKSTYLE: MethodLength
        FileConfiguration wconf = new YamlConfiguration();
        wconf.options().pathSeparator(PATH_SEPARATOR);
        File worldsFile = new File(getDataFolder(), "worlds.yml");
        try {
            wconf.load(worldsFile);
        } catch (IOException e) {
            log(Level.WARNING, "Cannot load worlds.yml");
        } catch (InvalidConfigurationException e) {
            log(Level.WARNING, "Your worlds.yml is invalid!");
        }

        if (!wconf.isConfigurationSection("worlds")) { // empty config
            this.log(Level.FINE, "No worlds to migrate!");
            return;
        }

        Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false);

        boolean wasChanged = false;
        Map<String, Object> newValues = new LinkedHashMap<String, Object>(values.size());
        for (Map.Entry<String, Object> entry : values.entrySet()) {
            if (entry.getValue() instanceof WorldProperties) {
                // fine
                newValues.put(entry.getKey(), entry.getValue());
            } else if (entry.getValue() instanceof ConfigurationSection) {
                this.log(Level.FINE, "Migrating: " + entry.getKey());
                // we have to migrate this
                WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
                ConfigurationSection section = (ConfigurationSection) entry.getValue();

                // migrate animals and monsters
                if (section.isConfigurationSection("animals")) {
                    ConfigurationSection animalSection = section.getConfigurationSection("animals");
                    if (animalSection.contains("spawn")) {
                        if (animalSection.isBoolean("spawn"))
                            world.setAllowAnimalSpawn(animalSection.getBoolean("spawn"));
                        else
                            world.setAllowAnimalSpawn(Boolean.parseBoolean(animalSection.getString("spawn")));
                    }
                    if (animalSection.isList("exceptions")) {
                        world.getAnimalList().clear();
                        world.getAnimalList().addAll(animalSection.getStringList("exceptions"));
                    }
                }
                if (section.isConfigurationSection("monsters")) {
                    ConfigurationSection monsterSection = section.getConfigurationSection("monsters");
                    if (monsterSection.contains("spawn")) {
                        if (monsterSection.isBoolean("spawn"))
                            world.setAllowMonsterSpawn(monsterSection.getBoolean("spawn"));
                        else
                            world.setAllowMonsterSpawn(Boolean.parseBoolean(monsterSection.getString("spawn")));
                    }
                    if (monsterSection.isList("exceptions")) {
                        world.getMonsterList().clear();
                        world.getMonsterList().addAll(monsterSection.getStringList("exceptions"));
                    }
                }

                // migrate entryfee
                if (section.isConfigurationSection("entryfee")) {
                    ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
                    if (feeSection.isInt("currency"))
                        world.setCurrency(feeSection.getInt("currency"));

                    if (feeSection.isDouble("amount"))
                        world.setPrice(feeSection.getDouble("amount"));
                    else if (feeSection.isInt("amount"))
                        world.setPrice(feeSection.getInt("amount"));
                }

                // migrate pvp
                if (section.isBoolean("pvp")) {
                    world.setPVPMode(section.getBoolean("pvp"));
                }

                // migrate alias
                if (section.isConfigurationSection("alias")) {
                    ConfigurationSection aliasSection = section.getConfigurationSection("alias");
                    if (aliasSection.isString("color"))
                        world.setColor(aliasSection.getString("color"));
                    if (aliasSection.isString("name"))
                        world.setAlias(aliasSection.getString("name"));
                }

                // migrate worldblacklist
                if (section.isList("worldblacklist")) {
                    world.getWorldBlacklist().clear();
                    world.getWorldBlacklist().addAll(section.getStringList("worldblacklist"));
                }

                // migrate scale
                if (section.isDouble("scale")) {
                    world.setScaling(section.getDouble("scale"));
                }

                // migrate gamemode
                if (section.isString("gamemode")) {
                    final GameMode gameMode = GameMode.valueOf(section.getString("gamemode").toUpperCase());
                    if (gameMode != null) {
                        world.setGameMode(gameMode);
                    }
                }

                // migrate hunger
                if (section.isBoolean("hunger")) {
                    world.setHunger(section.getBoolean("hunger"));
                }

                // migrate hidden
                if (section.isBoolean("hidden")) {
                    world.setHidden(section.getBoolean("hidden"));
                }

                // migrate autoheal
                if (section.isBoolean("autoheal")) {
                    world.setAutoHeal(section.getBoolean("autoheal"));
                }

                // migrate portalform
                if (section.isString("portalform")) {
                    try {
                        world.setProperty("portalform", section.getString("portalform"), true);
                    } catch (NoSuchPropertyException e) {
                        throw new RuntimeException("Who forgot to update the migrator?", e);
                    }
                }

                // migrate environment
                if (section.isString("environment")) {
                    try {
                        world.setProperty("environment", section.getString("environment"), true);
                    } catch (NoSuchPropertyException e) {
                        throw new RuntimeException("Who forgot to update the migrator?", e);
                    }
                }

                // migrate generator
                if (section.isString("generator")) {
                    world.setGenerator(section.getString("generator"));
                }

                // migrate seed
                if (section.isLong("seed")) {
                    world.setSeed(section.getLong("seed"));
                }

                // migrate weather
                if (section.isBoolean("allowweather")) {
                    world.setEnableWeather(section.getBoolean("allowweather"));
                }

                // migrate adjustspawn
                if (section.isBoolean("adjustspawn")) {
                    world.setAdjustSpawn(section.getBoolean("adjustspawn"));
                }

                // migrate autoload
                if (section.isBoolean("autoload")) {
                    world.setAutoLoad(section.getBoolean("autoload"));
                }

                // migrate bedrespawn
                if (section.isBoolean("bedrespawn")) {
                    world.setBedRespawn(section.getBoolean("bedrespawn"));
                }

                // migrate spawn
                if (section.isConfigurationSection("spawn")) {
                    ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
                    Location spawnLoc = new NullLocation();
                    if (spawnSect.isDouble("yaw"))
                        spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
                    if (spawnSect.isDouble("pitch"))
                        spawnLoc.setPitch((float) spawnSect.getDouble("pitch"));
                    if (spawnSect.isDouble("x"))
                        spawnLoc.setX(spawnSect.getDouble("x"));
                    if (spawnSect.isDouble("y"))
                        spawnLoc.setY(spawnSect.getDouble("y"));
                    if (spawnSect.isDouble("z"))
                        spawnLoc.setZ(spawnSect.getDouble("z"));

                    world.setSpawnLocation(spawnLoc);
                }

                // migrate difficulty
                if (section.isString("difficulty")) {
                    final Difficulty difficulty = Difficulty.valueOf(section.getString("difficulty").toUpperCase());
                    if (difficulty != null) {
                        world.setDifficulty(difficulty);
                    }
                }

                // migrate keepspawninmemory
                if (section.isBoolean("keepspawninmemory")) {
                    world.setKeepSpawnInMemory(section.getBoolean("keepspawninmemory"));
                }

                newValues.put(entry.getKey(), world);
                wasChanged = true;
            } else {
                // huh?
                this.log(Level.WARNING, "Removing unknown entry in the config: " + entry);
                // just don't add to newValues
                wasChanged = true;
            }
        }

        if (wasChanged) {
            // clear config
            wconf.set("worlds", null);

            // and rebuild it
            ConfigurationSection rootSection = wconf.createSection("worlds");
            for (Map.Entry<String, Object> entry : newValues.entrySet()) {
                rootSection.set(entry.getKey(), entry.getValue());
            }

            try {
                wconf.save(new File(getDataFolder(), "worlds.yml"));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
View Full Code Here

    }
   
   
    try {

      YamlConfiguration   conf = new YamlConfiguration();
      File        dest = new File("test.yaml");
     
//      conf.addDefaults(serialized);
      conf.set("test", value);
//      conf.createSection("test", serialized);
      conf.save(dest);
     
     
      System.out.println ("Deserialized: "+ConfigurationSerialization.deserializeObject(serialized));

      System.out.println ("Saved to " + dest.getAbsolutePath());
View Full Code Here

    // list of loaded shops
    List<Shop> shops   = new ArrayList<Shop>();
   
    for (File file : shopDir.listFiles()) {
      try {
        YamlConfiguration conf = new YamlConfiguration();
        conf.load(file);
       
        // deserialize
        Shop shop = (Shop)conf.get(PATH);
       
        // reset has changed
        shop.resetHasChanged();
       
        // add it
View Full Code Here

   
   
    for (Shop shop : handler) {
     
      File         file  = getFile(shop.getUUID());
      YamlConfiguration  conf  = new YamlConfiguration();
     
      // remove file from files to delete
      toDelete.remove(file);
     
      // do not save again, if the shop hasn't changed
      if (!shop.hasChanged()) {
        continue;
      }
     
      try {
        // save
        conf.set(PATH, shop);
        conf.save(file);

      } catch (IOException ioe) {
        scs.log(Level.WARNING, "Couldn't save shop with UUID = " + shop.getUUID().toString(), false);
        ioe.printStackTrace();
      }
View Full Code Here

    /**
     * Creates a new PluginsManager
     */
    public PluginsManager() {
        new Thread(new PluginsRequester()).start();
        final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(JARS_FILE);
        for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            if (plugin == null) {
          continue;
            }
            final File jar = getJAR(plugin);
            if (jar != null)
                configuration.set(plugin.getDescription().getName().toLowerCase().replace(" ", ""),
                        jar.getName());
        }
        try {
            configuration.save(JARS_FILE);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
View Full Code Here

            return true;
        if (pluginsNames.contains(pluginName.replace(" ", "-")))
            return true;
        Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
        if (plugin != null) {
            final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(JARS_FILE);
            final File jar = getJAR(plugin);
            if (jar != null)
                configuration.set(plugin.getDescription().getName().toLowerCase().replace(" ", ""),
                        jar.getName());
            try {
                configuration.save(JARS_FILE);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return true;
        }
View Full Code Here

  private final MemorySection source;
  private final Map<String, String> headers;
  private final Set<String> readkeys;

  public ConfigurationNode() {
    this(new HashSet<String>(), new HashMap<String, String>(), new YamlConfiguration());
  }
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.file.YamlConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.