Search in sources :

Example 31 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project MyPet by xXKeyleXx.

the class ConfigurationLoader method loadConfiguration.

public static void loadConfiguration() {
    MyPetApi.getPlugin().reloadConfig();
    FileConfiguration config = MyPetApi.getPlugin().getConfig();
    Misc.CONSUME_LEASH_ITEM = config.getBoolean("MyPet.Leash.Consume", false);
    Misc.ALLOW_RANGED_LEASHING = config.getBoolean("MyPet.Leash.AllowRanged", true);
    Misc.MAX_STORED_PET_COUNT = config.getInt("MyPet.Max-Stored-Pet-Count", Misc.MAX_STORED_PET_COUNT);
    Update.ASYNC = config.getBoolean("MyPet.Update.In-Background", Update.ASYNC);
    Update.CHECK = config.getBoolean("MyPet.Update.Check", Update.CHECK);
    Update.DOWNLOAD = config.getBoolean("MyPet.Update.Download", Update.DOWNLOAD);
    Update.REPLACE_OLD = config.getBoolean("MyPet.Update.ReplaceOld", Update.REPLACE_OLD);
    Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME = config.getInt("MyPet.Skill.Beacon.HungerDecreaseTime", 100);
    Skilltree.Skill.Beacon.PARTY_SUPPORT = config.getBoolean("MyPet.Skill.Beacon.Party-Support", true);
    Skilltree.Skill.Inventory.OPEN_IN_CREATIVE = config.getBoolean("MyPet.Skill.Inventory.Creative", true);
    Skilltree.Skill.Inventory.DROP_WHEN_OWNER_DIES = config.getBoolean("MyPet.Skill.Inventory.DropWhenOwnerDies", false);
    Skilltree.Skill.Ride.HUNGER_PER_METER = config.getDouble("MyPet.Skill.Ride.HungerPerMeter", 0.01);
    Skilltree.SWITCH_PENALTY_FIXED = config.getDouble("MyPet.Skilltree.SwitchFee.Fixed", 0.0);
    Skilltree.SWITCH_PENALTY_PERCENT = config.getInt("MyPet.Skilltree.SwitchFee.Percent", 5);
    Skilltree.SWITCH_PENALTY_ADMIN = config.getBoolean("MyPet.Skilltree.SwitchFee.Admin", false);
    Skilltree.SWITCH_FEE_FIXED = config.getDouble("MyPet.Skilltree.SwitchFee.Fixed", 0.0);
    Skilltree.SWITCH_FEE_PERCENT = config.getInt("MyPet.Skilltree.SwitchFee.Percent", 5);
    Skilltree.SWITCH_FEE_ADMIN = config.getBoolean("MyPet.Skilltree.SwitchFee.Admin", false);
    Skilltree.INHERIT_ALREADY_INHERITED_SKILLS = config.getBoolean("MyPet.Skilltree.InheritAlreadyInheritedSkills", false);
    Respawn.TIME_FACTOR = config.getInt("MyPet.Respawn.Time.Default.Factor", 5);
    Respawn.TIME_PLAYER_FACTOR = config.getInt("MyPet.Respawn.Time.Player.Factor", 5);
    Respawn.TIME_FIXED = config.getInt("MyPet.Respawn.Time.Default.Fixed", 0);
    Respawn.TIME_PLAYER_FIXED = config.getInt("MyPet.Respawn.Time.Player.Fixed", 0);
    Respawn.COSTS_FACTOR = config.getDouble("MyPet.Respawn.EconomyCost.Factor", 1.0);
    Respawn.COSTS_FIXED = config.getDouble("MyPet.Respawn.EconomyCost.Fixed", 0.0);
    Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT = config.getBoolean("MyPet.Skilltree.AutomaticAssignment", false);
    Skilltree.RANDOM_SKILLTREE_ASSIGNMENT = config.getBoolean("MyPet.Skilltree.RandomAssignment", false);
    Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE = config.getBoolean("MyPet.Skilltree.ChooseOnce", false);
    Skilltree.PREVENT_LEVELLING_WITHOUT_SKILLTREE = config.getBoolean("MyPet.Skilltree.PreventLevellingWithout", true);
    Misc.OWNER_CAN_ATTACK_PET = config.getBoolean("MyPet.OwnerCanAttackPet", false);
    Misc.DISABLE_PET_VS_PLAYER = config.getBoolean("MyPet.DisablePetVersusPlayer", false);
    HungerSystem.USE_HUNGER_SYSTEM = config.getBoolean("MyPet.HungerSystem.Active", true);
    HungerSystem.HUNGER_SYSTEM_TIME = config.getInt("MyPet.HungerSystem.Time", 60);
    HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED = config.getDouble("MyPet.HungerSystem.SaturationPerFeed", 6.0);
    HungerSystem.AFFECT_RIDE_SPEED = config.getBoolean("MyPet.HungerSystem.Affect-Ride-Speed", true);
    HungerSystem.AFFECT_BEACON_RANGE = config.getBoolean("MyPet.HungerSystem.Affect-Beacon-Range", true);
    Misc.RELEASE_PETS_ON_DEATH = config.getBoolean("MyPet.ReleasePetsOnDeath", false);
    Misc.REMOVE_PETS_AFTER_RELEASE = config.getBoolean("MyPet.RemovePetsAfterRelease", false);
    Misc.RETAIN_EQUIPMENT_ON_TAME = config.getBoolean("MyPet.RetainEquipmentOnTame", true);
    Misc.INVISIBLE_LIKE_OWNER = config.getBoolean("MyPet.Make-Pet-Invisible-When-Owner-Is-Invisible", true);
    Misc.MYPET_FOLLOW_START_DISTANCE = config.getDouble("MyPet.FollowStartDistance", 7.0D);
    Misc.THROW_PLAYER_MOVE_EVENT_WHILE_RIDING = config.getBoolean("MyPet.Throw-PlayerMoveEvent-While-Riding", true);
    Misc.DISABLE_ALL_ACTIONBAR_MESSAGES = config.getBoolean("MyPet.Disable-All-Actionbar-Messages", false);
    Misc.OVERWRITE_LANGUAGE = config.getString("MyPet.OverwriteLanguages", "");
    LevelSystem.CALCULATION_MODE = config.getString("MyPet.LevelSystem.CalculationMode", "Default");
    Log.LEVEL = config.getString("MyPet.Log.Level", Log.LEVEL);
    NameFilter.NAME_FILTER = new ArrayList<>();
    for (Object o : config.getList("MyPet.Name.Filter", Lists.newArrayList("whore", "fuck"))) {
        NameFilter.NAME_FILTER.add(o.toString());
    }
    Name.MAX_LENGTH = config.getInt("MyPet.Name.MaxLength", Name.MAX_LENGTH);
    Name.Tag.SHOW = config.getBoolean("MyPet.Name.Tag.Show", Name.Tag.SHOW);
    Name.Tag.PREFIX = Colorizer.setColors(config.getString("MyPet.Name.Tag.Prefix", Name.Tag.PREFIX));
    Name.Tag.SUFFIX = Colorizer.setColors(config.getString("MyPet.Name.Tag.Suffix", Name.Tag.SUFFIX));
    Misc.WIKI_URL = config.getString("MyPet.Info.Wiki-URL", Misc.WIKI_URL);
    Permissions.EXTENDED = config.getBoolean("MyPet.Permissions.Extended", false);
    Permissions.ENABLED = config.getBoolean("MyPet.Permissions.Enabled", true);
    Permissions.LEGACY = config.getBoolean("MyPet.Permissions.Legacy", Permissions.LEGACY);
    Hooks.USE_ECONOMY = config.getBoolean("MyPet.Hooks.Vault.Economy", true);
    Hooks.DISABLE_PETS_IN_MINIGAMES = config.getBoolean("MyPet.Hooks.Minigames.DisablePetsInGames", true);
    Hooks.DISABLE_PETS_IN_ARENA = config.getBoolean("MyPet.Hooks.PvPArena.DisablePetsInArena", true);
    Hooks.DISABLE_PETS_IN_SURVIVAL_GAMES = config.getBoolean("MyPet.Hooks.SurvivalGames.DisablePetsInGames", true);
    Hooks.DISABLE_PETS_IN_HUNGER_GAMES = config.getBoolean("MyPet.Hooks.MyHungerGames.DisablePetsInGames", true);
    Hooks.SkillAPI.GRANT_EXP = config.getBoolean("MyPet.Hooks.SkillAPI.GrantExp", true);
    Hooks.SkillAPI.DISABLE_VANILLA_EXP = config.getBoolean("MyPet.Hooks.SkillAPI.Disable-Vanilla-Exp", false);
    Hooks.SkillAPI.EXP_PERCENT = config.getInt("MyPet.Hooks.SkillAPI.ExpPercent", 100);
    Hooks.USE_PvPArena = config.getBoolean("MyPet.Hooks.PvPArena.PvP", true);
    Hooks.USE_Towny = config.getBoolean("MyPet.Hooks.Towny", true);
    Hooks.USE_Factions = config.getBoolean("MyPet.Hooks.Factions", true);
    Hooks.USE_WorldGuard = config.getBoolean("MyPet.Hooks.WorldGuard", true);
    Hooks.USE_Citizens = config.getBoolean("MyPet.Hooks.Citizens", true);
    Hooks.USE_Heroes = config.getBoolean("MyPet.Hooks.Heroes", true);
    Hooks.USE_McMMO = config.getBoolean("MyPet.Hooks.mcMMO", true);
    Hooks.USE_SimpleClans = config.getBoolean("MyPet.Hooks.SimpleClans", true);
    Hooks.USE_RedProtect = config.getBoolean("MyPet.Hooks.RedProtect", true);
    Hooks.MobArena.ENABLED = config.getBoolean("MyPet.Hooks.MobArena.Enabled", true);
    Hooks.MobArena.ALLOW_PETS = config.getBoolean("MyPet.Hooks.MobArena.AllowPets", true);
    Hooks.MobArena.RESPECT_PVP_RULE = config.getBoolean("MyPet.Hooks.MobArena.RespectPvPRule", true);
    Hooks.USE_SurvivalGame = config.getBoolean("MyPet.Hooks.SurvivalGames.PvP", true);
    Hooks.USE_Residence = config.getBoolean("MyPet.Hooks.Residence", true);
    Hooks.USE_AncientRPG = config.getBoolean("MyPet.Hooks.AncientRPG", true);
    Hooks.USE_GriefPrevention = config.getBoolean("MyPet.Hooks.GriefPrevention", true);
    Hooks.USE_PvPManager = config.getBoolean("MyPet.Hooks.PvPManager", true);
    Hooks.USE_PlotSquared = config.getBoolean("MyPet.Hooks.PlotSquared", true);
    Hooks.USE_PvPDiffTimer = config.getBoolean("MyPet.Hooks.PvPDiffTimer", true);
    Hooks.USE_Kingdoms = config.getBoolean("MyPet.Hooks.Kingdoms", true);
    Hooks.DISABLE_MYTHIC_MOB_LEASHING = config.getBoolean("MyPet.Hooks.MythicMobs.Disable-Leashing", true);
    LevelSystem.Experience.LEVEL_CAP = config.getInt("MyPet.Exp.LevelCap", LevelSystem.Experience.LEVEL_CAP);
    LevelSystem.Experience.LOSS_PERCENT = config.getInt("MyPet.Exp.Loss.Percent", 0);
    LevelSystem.Experience.LOSS_FIXED = config.getDouble("MyPet.Exp.Loss.Fixed", 0.0);
    LevelSystem.Experience.DROP_LOST_EXP = config.getBoolean("MyPet.Exp.Loss.Drop", true);
    LevelSystem.Experience.PASSIVE_PERCENT_PER_MONSTER = config.getInt("MyPet.Exp.Passive.PercentPerMonster", 25);
    LevelSystem.Experience.ALWAYS_GRANT_PASSIVE_XP = config.getBoolean("MyPet.Exp.Passive.Always-Grant-Passive-XP", true);
    LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION = config.getBoolean("MyPet.Exp.DamageWeightedExperienceDistribution", true);
    LevelSystem.Experience.DISABLED_WORLDS.clear();
    LevelSystem.Experience.DISABLED_WORLDS.addAll(config.getStringList("MyPet.Exp.Disabled-Worlds"));
    if (config.contains("MyPet.Exp.Gain.PreventFromSpawnReason")) {
        LevelSystem.Experience.PREVENT_FROM_SPAWN_REASON.clear();
        if (config.isList("MyPet.Exp.Gain.PreventFromSpawnReason")) {
            for (String reason : config.getStringList("MyPet.Exp.Gain.PreventFromSpawnReason")) {
                reason = reason.toUpperCase();
                try {
                    CreatureSpawnEvent.SpawnReason.valueOf(reason);
                    LevelSystem.Experience.PREVENT_FROM_SPAWN_REASON.add(reason);
                } catch (Exception ignored) {
                }
            }
        }
    }
    for (EntityType entityType : EntityType.values()) {
        if (MonsterExperience.mobExp.containsKey(entityType.name())) {
            double max = config.getDouble("MyPet.Exp.Active." + entityType.name() + ".Max", 0.);
            double min = config.getDouble("MyPet.Exp.Active." + entityType.name() + ".Min", 0.);
            if (min == max) {
                MonsterExperience.getMonsterExperience(entityType).setExp(max);
            } else {
                MonsterExperience.getMonsterExperience(entityType).setMin(min);
                MonsterExperience.getMonsterExperience(entityType).setMax(max);
            }
        }
    }
    File petConfigFile = new File(MyPetApi.getPlugin().getDataFolder().getPath(), "pet-config.yml");
    if (petConfigFile.exists()) {
        YamlConfiguration ymlcnf = new YamlConfiguration();
        try {
            ymlcnf.load(petConfigFile);
            config = ymlcnf;
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }
    MyPet.Chicken.CAN_LAY_EGGS = config.getBoolean("MyPet.Pets.Chicken.CanLayEggs", true);
    MyPet.Cow.CAN_GIVE_MILK = config.getBoolean("MyPet.Pets.Cow.CanGiveMilk", true);
    MyPet.Sheep.CAN_BE_SHEARED = config.getBoolean("MyPet.Pets.Sheep.CanBeSheared", true);
    MyPet.Sheep.CAN_REGROW_WOOL = config.getBoolean("MyPet.Pets.Sheep.CanRegrowWool", true);
    MyPet.IronGolem.CAN_THROW_UP = config.getBoolean("MyPet.Pets.IronGolem.CanThrowUp", true);
    MyPet.Snowman.FIX_SNOW_TRACK = config.getBoolean("MyPet.Pets.Snowman.FixSnowTrack", true);
    MyPet.Mooshroom.CAN_GIVE_SOUP = config.getBoolean("MyPet.Pets.Mooshroom.CanGiveStew", false);
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) EntityType(org.bukkit.entity.EntityType) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 32 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project acidisland by tastybento.

the class GridManager method convert.

/**
 * Converts from the old version where islands were stored in an island
 * folder.
 * Did not work for large installations.
 */
private void convert() {
    // Read spawn file if it exists
    final File spawnFile = new File(plugin.getDataFolder(), "spawn.yml");
    if (spawnFile.exists()) {
        YamlConfiguration spawn = new YamlConfiguration();
        try {
            spawn.load(spawnFile);
            int range = spawn.getInt("spawn.range");
            // plugin.getLogger().info("DEBUG:" + range + " " +
            // spawn.getString("spawn.bedrock",""));
            Location spawnLoc = Util.getLocationString(spawn.getString("spawn.bedrock", ""));
            if (spawnLoc != null && onGrid(spawnLoc)) {
                Island newIsland = addIsland(spawnLoc.getBlockX(), spawnLoc.getBlockZ());
                setSpawn(newIsland);
                newIsland.setProtectionSize(range);
            } else {
                plugin.getLogger().severe("Spawn could not be imported! Location " + spawnLoc);
                plugin.getLogger().severe("Go to the spawn island and set it manually");
            }
        } catch (Exception e) {
            plugin.getLogger().severe("Spawn could not be imported! File could not load.");
        }
    }
    // Go through player folder
    final File playerFolder = new File(plugin.getDataFolder() + File.separator + "players");
    final File quarantineFolder = new File(plugin.getDataFolder() + File.separator + "quarantine");
    YamlConfiguration playerFile = new YamlConfiguration();
    int noisland = 0;
    int inTeam = 0;
    int count = 0;
    if (playerFolder.exists() && playerFolder.listFiles().length > 0) {
        plugin.getLogger().warning("Reading player folder...");
        if (playerFolder.listFiles().length > 5000) {
            plugin.getLogger().warning("This could take some time with a large number of islands...");
        }
        for (File f : playerFolder.listFiles()) {
            // Need to remove the .yml suffix
            String fileName = f.getName();
            if (fileName.endsWith(".yml")) {
                try {
                    playerFile.load(f);
                    boolean hasIsland = playerFile.getBoolean("hasIsland", false);
                    if (hasIsland) {
                        String islandLocation = playerFile.getString("islandLocation");
                        if (islandLocation.isEmpty()) {
                            plugin.getLogger().severe("Problem with " + fileName);
                            plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
                            plugin.getLogger().severe("Player file says they have an island, but there is no location.");
                            // Move to quarantine
                            if (!quarantineFolder.exists()) {
                                quarantineFolder.mkdir();
                            }
                            // Move the file
                            plugin.getLogger().severe("Moving " + f.getName() + " to " + quarantineFolder.getName());
                            File rename = new File(quarantineFolder, f.getName());
                            f.renameTo(rename);
                        } else {
                            // Location exists
                            Location islandLoc = Util.getLocationString(islandLocation);
                            if (islandLoc != null) {
                                // Check to see if this island is already loaded
                                Island island = getIslandAt(islandLoc);
                                if (island != null) {
                                    // PlayerIsland exists, compare creation dates
                                    plugin.getLogger().severe("Problem with " + fileName);
                                    plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
                                    plugin.getLogger().severe("This island location already exists and is already imported");
                                    if (island.getUpdatedDate() > f.lastModified()) {
                                        plugin.getLogger().severe("Previous file is more recent so keeping it.");
                                        // Move to quarantine
                                        if (!quarantineFolder.exists()) {
                                            quarantineFolder.mkdir();
                                        }
                                        plugin.getLogger().severe("Moving " + (playerFile.getString("playerName", "Unknown")) + "'s file (" + f.getName() + ") to " + quarantineFolder.getName());
                                        File rename = new File(quarantineFolder, f.getName());
                                        f.renameTo(rename);
                                    } else {
                                        // New file is more recent
                                        plugin.getLogger().severe(playerFile.getString("playerName", "Unknown") + "'s file is more recent");
                                        File oldFile = new File(playerFolder, island.getOwner().toString() + ".yml");
                                        File rename = new File(quarantineFolder, oldFile.getName());
                                        // Move to quarantine
                                        if (!quarantineFolder.exists()) {
                                            quarantineFolder.mkdir();
                                        }
                                        plugin.getLogger().severe("Moving previous file (" + oldFile.getName() + ") to " + quarantineFolder.getName());
                                        oldFile.renameTo(rename);
                                        deleteIsland(islandLoc);
                                        island = null;
                                    }
                                }
                                if (island == null) {
                                    if (!onGrid(islandLoc)) {
                                        plugin.getLogger().severe("Problem with " + fileName);
                                        plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
                                        plugin.getLogger().severe("Island is not on grid lines! " + islandLoc);
                                    }
                                    String ownerString = fileName.substring(0, fileName.length() - 4);
                                    // Add the island
                                    UUID owner = UUID.fromString(ownerString);
                                    Island newIsland = addIsland(islandLoc.getBlockX(), islandLoc.getBlockZ(), owner);
                                    ownershipMap.put(owner, newIsland);
                                    // Grab when this was last updated
                                    newIsland.setUpdatedDate(f.lastModified());
                                    if ((count) % 1000 == 0) {
                                        plugin.getLogger().info("Converted " + count + " islands");
                                    }
                                    count++;
                                    // plugin.getLogger().info("Converted island at "
                                    // + islandLoc);
                                    // Top ten
                                    int islandLevel = playerFile.getInt("islandLevel", 0);
                                    String teamLeaderUUID = playerFile.getString("teamLeader", "");
                                    if (islandLevel > 0) {
                                        if (!playerFile.getBoolean("hasTeam")) {
                                            TopTen.topTenAddEntry(owner, islandLevel);
                                        } else if (!teamLeaderUUID.isEmpty()) {
                                            if (teamLeaderUUID.equals(ownerString)) {
                                                TopTen.topTenAddEntry(owner, islandLevel);
                                            }
                                        }
                                    }
                                    // Check if there is an island info string and see if it jibes
                                    String islandInfo = playerFile.getString("islandInfo", "");
                                    if (!islandInfo.isEmpty()) {
                                        String[] split = islandInfo.split(":");
                                        try {
                                            // int protectionRange = Integer.parseInt(split[3]);
                                            // int islandDistance = Integer.parseInt(split[4]);
                                            newIsland.setLocked(false);
                                            if (split.length > 6) {
                                                // Get locked status
                                                if (split[6].equalsIgnoreCase("true")) {
                                                    newIsland.setLocked(true);
                                                }
                                            }
                                            // Check if deletable
                                            newIsland.setPurgeProtected(false);
                                            if (split.length > 7) {
                                                if (split[7].equalsIgnoreCase("true")) {
                                                    newIsland.setPurgeProtected(true);
                                                }
                                            }
                                            if (!split[5].equals("null")) {
                                                if (split[5].equals("spawn")) {
                                                    newIsland.setSpawn(true);
                                                    // Try to get the spawn point
                                                    if (split.length > 8) {
                                                        // plugin.getLogger().info("DEBUG: " + serial.substring(serial.indexOf(":SP:") + 4));
                                                        Location spawnPoint = Util.getLocationString(islandInfo.substring(islandInfo.indexOf(":SP:") + 4));
                                                        newIsland.setSpawnPoint(spawnPoint);
                                                    }
                                                }
                                            }
                                            // Check if protection options there
                                            if (!newIsland.isSpawn()) {
                                                // plugin.getLogger().info("DEBUG: NOT SPAWN owner is " + owner + " location " + center);
                                                if (split.length > 8 && split[8].length() == 29) {
                                                    // Parse the 8th string into island guard protection settings
                                                    int index = 0;
                                                    // Run through the enum and set
                                                    for (SettingsFlag flag : SettingsFlag.values()) {
                                                        if (index < split[8].length()) {
                                                            newIsland.setIgsFlag(flag, split[8].charAt(index++) == '1' ? true : false);
                                                        }
                                                    }
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            } else {
                                plugin.getLogger().severe("Problem with " + fileName);
                                plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
                                plugin.getLogger().severe("The world for this file does not exist!");
                            }
                        }
                    } else {
                        noisland++;
                        if (playerFile.getBoolean("hasTeam", false)) {
                            inTeam++;
                        }
                    }
                } catch (Exception e) {
                    plugin.getLogger().severe("Problem with " + fileName);
                // e.printStackTrace();
                }
            }
        }
        plugin.getLogger().info("Converted " + count + " islands from player's folder");
        plugin.getLogger().info(noisland + " have no island, of which " + inTeam + " are in a team.");
        plugin.getLogger().info((noisland - inTeam) + " are in the system, but have no island or team");
    }
    TopTen.topTenSave();
    int count2 = 0;
    // Check island folder
    final File islandFolder = new File(plugin.getDataFolder() + File.separator + "islands");
    if (islandFolder.exists() && islandFolder.listFiles().length > 0) {
        plugin.getLogger().warning("Reading island folder...");
        if (islandFolder.listFiles().length > 5000) {
            plugin.getLogger().warning("This could take some time with a large number of islands...");
        }
        for (File f : islandFolder.listFiles()) {
            // Need to remove the .yml suffix
            String fileName = f.getName();
            int comma = fileName.indexOf(",");
            if (fileName.endsWith(".yml") && comma != -1) {
                try {
                    // Parse to an island value
                    int x = Integer.parseInt(fileName.substring(0, comma));
                    int z = Integer.parseInt(fileName.substring(comma + 1, fileName.indexOf(".")));
                    if (!onGrid(x, z)) {
                        plugin.getLogger().severe("Island is not on grid lines! " + x + "," + z + " skipping...");
                    } else {
                        // Note that this is the CENTER of the island
                        if (getIslandAt(x, z) == null) {
                            addIsland(x, z);
                            if (count2 % 1000 == 0) {
                                plugin.getLogger().info("Converted " + count + " islands");
                            }
                            count2++;
                        // plugin.getLogger().info("Added island from island folder: "
                        // + x + "," +z);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        plugin.getLogger().info("Converted " + count2 + " islands from island folder");
        plugin.getLogger().info("Total " + (count + count2) + " islands converted.");
    }
    // Now save the islandGrid
    saveGrid();
}
Also used : SettingsFlag(com.wasteofplastic.acidisland.Island.SettingsFlag) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) UUID(java.util.UUID) File(java.io.File) IOException(java.io.IOException) Location(org.bukkit.Location)

Example 33 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project acidisland by tastybento.

the class GridManager method loadGrid.

private void loadGrid() {
    plugin.getLogger().info("Loading island grid...");
    islandGrid.clear();
    // protectionGrid.clear();
    islandNameFile = new File(plugin.getDataFolder(), ISLANDNAMES_FILENAME);
    if (!islandNameFile.exists()) {
        try {
            islandNameFile.createNewFile();
        } catch (IOException e) {
            plugin.getLogger().severe("Could not create " + ISLANDNAMES_FILENAME + "!");
        }
    }
    try {
        islandNames.load(islandNameFile);
    } catch (Exception e) {
        // e.printStackTrace();
        plugin.getLogger().severe("Could not load " + ISLANDNAMES_FILENAME);
    }
    islandFile = new File(plugin.getDataFolder(), ISLANDS_FILENAME);
    if (!islandFile.exists()) {
        // check if island folder exists
        plugin.getLogger().info(ISLANDS_FILENAME + " does not exist. Creating...");
        convert();
        plugin.getLogger().info(ISLANDS_FILENAME + " created.");
    } else {
        plugin.getLogger().info("Loading " + ISLANDS_FILENAME);
        YamlConfiguration islandYaml = new YamlConfiguration();
        try {
            islandYaml.load(islandFile);
            List<String> islandList = new ArrayList<String>();
            if (islandYaml.contains(Settings.worldName)) {
                // Load the island settings key
                List<String> settingsKey = islandYaml.getStringList(SETTINGS_KEY);
                // Load spawn, if it exists - V3.0.6 onwards
                if (islandYaml.contains("spawn")) {
                    Location spawnLoc = Util.getLocationString(islandYaml.getString("spawn.location"));
                    // Validate entries
                    if (spawnLoc != null && spawnLoc.getWorld() != null && spawnLoc.getWorld().equals(ASkyBlock.getIslandWorld())) {
                        Location spawnPoint = Util.getLocationString(islandYaml.getString("spawn.spawnpoint"));
                        int range = islandYaml.getInt("spawn.range", Settings.islandProtectionRange);
                        if (range < 0) {
                            range = Settings.islandProtectionRange;
                        }
                        String spawnSettings = islandYaml.getString("spawn.settings");
                        // Make the spawn
                        Island newSpawn = new Island(plugin, spawnLoc.getBlockX(), spawnLoc.getBlockZ());
                        newSpawn.setSpawn(true);
                        if (spawnPoint != null)
                            newSpawn.setSpawnPoint(spawnPoint);
                        newSpawn.setProtectionSize(range);
                        newSpawn.setSettings(spawnSettings, settingsKey);
                        spawn = newSpawn;
                    }
                }
                // Load the islands
                islandList = islandYaml.getStringList(Settings.worldName);
                for (String island : islandList) {
                    Island newIsland = addIsland(island, settingsKey);
                    if (newIsland.getOwner() != null) {
                        ownershipMap.put(newIsland.getOwner(), newIsland);
                    }
                    if (newIsland.isSpawn()) {
                        spawn = newIsland;
                    }
                }
            } else {
                plugin.getLogger().severe("Could not find any islands for this world. World name in config.yml is probably wrong.");
                plugin.getLogger().severe("Making backup of " + ISLANDS_FILENAME + ". Correct world name and then replace " + ISLANDS_FILENAME);
                File rename = new File(plugin.getDataFolder(), "islands_backup.yml");
                islandFile.renameTo(rename);
            }
        } catch (Exception e) {
            // e.printStackTrace();
            plugin.getLogger().severe("Could not load " + ISLANDS_FILENAME);
        }
    }
// for (int x : protectionGrid.)
// plugin.getLogger().info("Debug: protection grid is size " +
// protectionGrid.size());
// plugin.getLogger().info("Debug: Island grid is sized = " +
// islandGrid.size());
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) IOException(java.io.IOException) Location(org.bukkit.Location)

Example 34 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project acidisland by tastybento.

the class TopTen method topTenLoad.

/**
 * Loads the top ten from the file system topten.yml. If it does not exist
 * then the top ten is created
 */
public static void topTenLoad() {
    topTenList.clear();
    // Check to see if the top ten list exists
    File topTenFile = new File(plugin.getDataFolder(), "topten.yml");
    if (!topTenFile.exists()) {
        plugin.getLogger().warning("Top ten file does not exist - creating it. This could take some time with a large number of players");
        topTenCreate();
    } else {
        // Load the top ten
        YamlConfiguration topTenConfig = Util.loadYamlFile("topten.yml");
        // Load the values
        if (topTenConfig.isSet("topten")) {
            for (String playerUUID : topTenConfig.getConfigurationSection("topten").getKeys(false)) {
                // getLogger().info(playerUUID);
                try {
                    UUID uuid = UUID.fromString(playerUUID);
                    // getLogger().info(uuid.toString());
                    int level = topTenConfig.getInt("topten." + playerUUID);
                    // getLogger().info("Level = " + level);
                    TopTen.topTenAddEntry(uuid, level);
                } catch (Exception e) {
                    e.printStackTrace();
                    plugin.getLogger().severe("Problem loading top ten list - recreating - this may take some time");
                    topTenCreate();
                }
            }
        }
    }
}
Also used : YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) UUID(java.util.UUID) File(java.io.File)

Example 35 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project acidisland by tastybento.

the class CoopPlay method loadCoops.

public void loadCoops() {
    File coopFile = new File(plugin.getDataFolder(), "coops.yml");
    if (!coopFile.exists()) {
        return;
    }
    YamlConfiguration coopConfig = new YamlConfiguration();
    try {
        coopConfig.load(coopFile);
    } catch (IOException | InvalidConfigurationException e) {
        plugin.getLogger().severe("Could not load coop.yml file!");
    }
    // Run through players
    for (String playerUUID : coopConfig.getValues(false).keySet()) {
        try {
            setMyCoops(UUID.fromString(playerUUID), coopConfig.getStringList(playerUUID));
        } catch (Exception e) {
            plugin.getLogger().severe("Could not load coops for player UUID " + playerUUID + " skipping...");
        }
    }
}
Also used : IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Aggregations

YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)36 File (java.io.File)24 IOException (java.io.IOException)21 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)13 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)6 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 Location (org.bukkit.Location)4 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)4 EntityType (org.bukkit.entity.EntityType)4 SettingsFlag (com.wasteofplastic.acidisland.Island.SettingsFlag)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 DefaultInfo (de.Keyle.MyPet.api.entity.DefaultInfo)2 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 InputStreamReader (java.io.InputStreamReader)2 TreeMap (java.util.TreeMap)2 Material (org.bukkit.Material)2