Search in sources :

Example 1 with DefaultInfo

use of de.Keyle.MyPet.api.entity.DefaultInfo in project MyPet by xXKeyleXx.

the class ConfigurationLoader method loadCompatConfiguration.

public static void loadCompatConfiguration() {
    FileConfiguration config = MyPetApi.getPlugin().getConfig();
    Skilltree.Skill.CONTROL_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Skill.Control.Item", "" + Material.LEASH.getId()));
    Skilltree.Skill.Ride.RIDE_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Skill.Ride.Item", "" + Material.LEASH.getId()));
    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.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Chicken.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Cow.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Cow.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Horse.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Horse.GrowUpItem", "" + Material.BREAD.getId()));
    MyPet.Llama.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Llama.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Mooshroom.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Mooshroom.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Ocelot.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Ocelot.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Pig.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Pig.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Sheep.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Sheep.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Villager.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Villager.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Wolf.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Wolf.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Zombie.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Zombie.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.PigZombie.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.PigZombie.GrowUpItem", "" + Material.POTION.getId()));
    MyPet.Rabbit.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Rabbit.GrowUpItem", "" + Material.POTION.getId()));
    for (MyPetType petType : MyPetType.values()) {
        DefaultInfo pi = petType.getMyPetClass().getAnnotation(DefaultInfo.class);
        MyPetApi.getMyPetInfo().setStartHP(petType, config.getDouble("MyPet.Pets." + petType.name() + ".HP", pi.hp()));
        MyPetApi.getMyPetInfo().setSpeed(petType, config.getDouble("MyPet.Pets." + petType.name() + ".Speed", pi.walkSpeed()));
        if (config.get("MyPet.Pets." + petType.name() + ".Food") instanceof ArrayList) {
            List<String> foodList = config.getStringList("MyPet.Pets." + petType.name() + ".Food");
            for (String foodString : foodList) {
                ConfigItem ci = ConfigItem.createConfigItem(foodString);
                if (ci.getItem() != null && ci.getItem().getType() != Material.AIR) {
                    MyPetApi.getMyPetInfo().setFood(petType, ci);
                } else {
                    MyPetApi.getLogger().warning(foodString + " is not a valid food item!");
                }
            }
        } else {
            seperateFood(petType, config.getString("MyPet.Pets." + petType.name() + ".Food", "0"));
        }
        seperateLeashFlags(petType, config.getString("MyPet.Pets." + petType + ".LeashFlags", linkLeashFlags(pi.leashFlags())));
        MyPetApi.getMyPetInfo().setCustomRespawnTimeFactor(petType, config.getInt("MyPet.Pets." + petType.name() + ".CustomRespawnTimeFactor", 0));
        MyPetApi.getMyPetInfo().setCustomRespawnTimeFixed(petType, config.getInt("MyPet.Pets." + petType.name() + ".CustomRespawnTimeFixed", 0));
        MyPetApi.getMyPetInfo().setLeashItem(petType, ConfigItem.createConfigItem(config.getString("MyPet.Pets." + petType.name() + ".LeashItem", "" + Material.LEASH.getId())));
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) DefaultInfo(de.Keyle.MyPet.api.entity.DefaultInfo) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) ArrayList(java.util.ArrayList) ConfigItem(de.Keyle.MyPet.api.util.ConfigItem) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 2 with DefaultInfo

use of de.Keyle.MyPet.api.entity.DefaultInfo in project MyPet by xXKeyleXx.

the class ConfigurationLoader method setDefault.

public static void setDefault() {
    FileConfiguration config = MyPetApi.getPlugin().getConfig();
    config.options().header("" + "########################################################\n" + "       This is the main configuration of MyPet         #\n" + "         You can find more info in the wiki:           #\n" + "       https://wiki.mypet-plugin.de/configfile         #\n" + "########################################################\n");
    config.options().copyHeader(true);
    config.addDefault("MyPet.Update.Check", Update.CHECK);
    config.addDefault("MyPet.Update.Download", Update.DOWNLOAD);
    config.addDefault("MyPet.Update.ReplaceOld", Update.REPLACE_OLD);
    config.addDefault("MyPet.Update.In-Background", Update.ASYNC);
    config.addDefault("MyPet.Leash.Consume", Misc.CONSUME_LEASH_ITEM);
    config.addDefault("MyPet.Leash.AllowRanged", Misc.ALLOW_RANGED_LEASHING);
    config.addDefault("MyPet.OwnerCanAttackPet", Misc.OWNER_CAN_ATTACK_PET);
    config.addDefault("MyPet.DisablePetVersusPlayer", Misc.DISABLE_PET_VS_PLAYER);
    config.addDefault("MyPet.RemovePetsAfterRelease", Misc.REMOVE_PETS_AFTER_RELEASE);
    config.addDefault("MyPet.FollowStartDistance", Misc.MYPET_FOLLOW_START_DISTANCE);
    config.addDefault("MyPet.ReleasePetsOnDeath", Misc.RELEASE_PETS_ON_DEATH);
    config.addDefault("MyPet.RetainEquipmentOnTame", Misc.RETAIN_EQUIPMENT_ON_TAME);
    config.addDefault("MyPet.Make-Pet-Invisible-When-Owner-Is-Invisible", Misc.INVISIBLE_LIKE_OWNER);
    config.addDefault("MyPet.Log.Level", Log.LEVEL);
    config.addDefault("MyPet.Max-Stored-Pet-Count", Misc.MAX_STORED_PET_COUNT);
    config.addDefault("MyPet.Throw-PlayerMoveEvent-While-Riding", Misc.THROW_PLAYER_MOVE_EVENT_WHILE_RIDING);
    config.addDefault("MyPet.Disable-All-Actionbar-Messages", Misc.DISABLE_ALL_ACTIONBAR_MESSAGES);
    config.addDefault("MyPet.OverwriteLanguages", Misc.OVERWRITE_LANGUAGE);
    config.addDefault("MyPet.Respawn.Time.Default.Factor", Respawn.TIME_FACTOR);
    config.addDefault("MyPet.Respawn.Time.Player.Factor", Respawn.TIME_PLAYER_FACTOR);
    config.addDefault("MyPet.Respawn.Time.Default.Fixed", Respawn.TIME_FIXED);
    config.addDefault("MyPet.Respawn.Time.Player.Fixed", Respawn.TIME_PLAYER_FIXED);
    config.addDefault("MyPet.Respawn.EconomyCost.Fixed", Respawn.COSTS_FIXED);
    config.addDefault("MyPet.Respawn.EconomyCost.Factor", Respawn.COSTS_FACTOR);
    config.addDefault("MyPet.Permissions.Enabled", Permissions.ENABLED);
    config.addDefault("MyPet.Permissions.Extended", Permissions.EXTENDED);
    config.addDefault("MyPet.Permissions.Legacy", Permissions.LEGACY);
    config.addDefault("MyPet.LevelSystem.CalculationMode", LevelSystem.CALCULATION_MODE);
    config.addDefault("MyPet.HungerSystem.Active", HungerSystem.USE_HUNGER_SYSTEM);
    config.addDefault("MyPet.HungerSystem.Time", HungerSystem.HUNGER_SYSTEM_TIME);
    config.addDefault("MyPet.HungerSystem.SaturationPerFeed", HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED);
    config.addDefault("MyPet.HungerSystem.Affect-Ride-Speed", HungerSystem.AFFECT_RIDE_SPEED);
    config.addDefault("MyPet.HungerSystem.Affect-Beacon-Range", HungerSystem.AFFECT_BEACON_RANGE);
    config.addDefault("MyPet.Skilltree.AutomaticAssignment", Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT);
    config.addDefault("MyPet.Skilltree.RandomAssignment", Skilltree.RANDOM_SKILLTREE_ASSIGNMENT);
    config.addDefault("MyPet.Skilltree.InheritAlreadyInheritedSkills", Skilltree.INHERIT_ALREADY_INHERITED_SKILLS);
    config.addDefault("MyPet.Skilltree.ChooseOnce", Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE);
    config.addDefault("MyPet.Skilltree.PreventLevellingWithout", Skilltree.PREVENT_LEVELLING_WITHOUT_SKILLTREE);
    config.addDefault("MyPet.Skilltree.SwitchFee.Fixed", Skilltree.SWITCH_FEE_FIXED);
    config.addDefault("MyPet.Skilltree.SwitchFee.Percent", Skilltree.SWITCH_FEE_PERCENT);
    config.addDefault("MyPet.Skilltree.SwitchFee.Admin", Skilltree.SWITCH_FEE_ADMIN);
    config.addDefault("MyPet.Hooks.Kingdoms", Hooks.USE_Kingdoms);
    config.addDefault("MyPet.Hooks.Towny", Hooks.USE_Towny);
    config.addDefault("MyPet.Hooks.Heroes", Hooks.USE_Heroes);
    config.addDefault("MyPet.Hooks.Factions", Hooks.USE_Factions);
    config.addDefault("MyPet.Hooks.WorldGuard", Hooks.USE_WorldGuard);
    config.addDefault("MyPet.Hooks.Citizens", Hooks.USE_Citizens);
    config.addDefault("MyPet.Hooks.mcMMO", Hooks.USE_McMMO);
    config.addDefault("MyPet.Hooks.SimpleClans", Hooks.USE_SimpleClans);
    config.addDefault("MyPet.Hooks.RedProtect", Hooks.USE_RedProtect);
    config.addDefault("MyPet.Hooks.MobArena.Enabled", Hooks.MobArena.ENABLED);
    config.addDefault("MyPet.Hooks.MobArena.AllowPets", Hooks.MobArena.ALLOW_PETS);
    config.addDefault("MyPet.Hooks.MobArena.RespectPvPRule", Hooks.MobArena.RESPECT_PVP_RULE);
    config.addDefault("MyPet.Hooks.Residence", Hooks.USE_Residence);
    config.addDefault("MyPet.Hooks.AncientRPG", Hooks.USE_AncientRPG);
    config.addDefault("MyPet.Hooks.GriefPrevention", Hooks.USE_GriefPrevention);
    config.addDefault("MyPet.Hooks.PvPManager", Hooks.USE_PvPManager);
    config.addDefault("MyPet.Hooks.PvPDiffTimer", Hooks.USE_PvPDiffTimer);
    config.addDefault("MyPet.Hooks.Minigames.DisablePetsInGames", Hooks.DISABLE_PETS_IN_MINIGAMES);
    config.addDefault("MyPet.Hooks.PvPArena.DisablePetsInArena", Hooks.DISABLE_PETS_IN_ARENA);
    config.addDefault("MyPet.Hooks.PlotSquared", Hooks.USE_PlotSquared);
    config.addDefault("MyPet.Hooks.PvPArena.PvP", Hooks.USE_PvPArena);
    config.addDefault("MyPet.Hooks.SurvivalGames.PvP", Hooks.USE_SurvivalGame);
    config.addDefault("MyPet.Hooks.SurvivalGames.DisablePetsInGames", Hooks.DISABLE_PETS_IN_SURVIVAL_GAMES);
    config.addDefault("MyPet.Hooks.MyHungerGames.DisablePetsInGames", Hooks.DISABLE_PETS_IN_HUNGER_GAMES);
    config.addDefault("MyPet.Hooks.BattleArena.DisablePetsInArena", Hooks.DISABLE_PETS_IN_ARENA);
    config.addDefault("MyPet.Hooks.Vault.Economy", Hooks.USE_ECONOMY);
    config.addDefault("MyPet.Hooks.SkillAPI.GrantExp", Hooks.SkillAPI.GRANT_EXP);
    config.addDefault("MyPet.Hooks.SkillAPI.Disable-Vanilla-Exp", Hooks.SkillAPI.DISABLE_VANILLA_EXP);
    config.addDefault("MyPet.Hooks.MythicMobs.Disable-Leashing", Hooks.DISABLE_MYTHIC_MOB_LEASHING);
    config.addDefault("MyPet.Name.Filter", Lists.newArrayList("whore", "fuck"));
    config.addDefault("MyPet.Name.MaxLength", Name.MAX_LENGTH);
    config.addDefault("MyPet.Name.Tag.Show", Name.Tag.SHOW);
    config.addDefault("MyPet.Name.Tag.Prefix", Name.Tag.PREFIX);
    config.addDefault("MyPet.Name.Tag.Suffix", Name.Tag.SUFFIX);
    config.addDefault("MyPet.Exp.DamageWeightedExperienceDistribution", LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION);
    config.addDefault("MyPet.Exp.Passive.Always-Grant-Passive-XP", LevelSystem.Experience.ALWAYS_GRANT_PASSIVE_XP);
    config.addDefault("MyPet.Exp.Passive.PercentPerMonster", LevelSystem.Experience.PASSIVE_PERCENT_PER_MONSTER);
    config.addDefault("MyPet.Exp.Loss.Percent", LevelSystem.Experience.LOSS_PERCENT);
    config.addDefault("MyPet.Exp.Loss.Fixed", LevelSystem.Experience.LOSS_FIXED);
    config.addDefault("MyPet.Exp.Loss.Drop", LevelSystem.Experience.DROP_LOST_EXP);
    config.addDefault("MyPet.Exp.Gain.PreventFromSpawnReason", new ArrayList<>());
    config.addDefault("MyPet.Exp.LevelCap", LevelSystem.Experience.LEVEL_CAP);
    config.addDefault("MyPet.Exp.Disabled-Worlds", new String[0]);
    config.addDefault("MyPet.Skill.Control.Item", Material.LEASH.getId());
    config.addDefault("MyPet.Skill.Inventory.Creative", Skilltree.Skill.Inventory.OPEN_IN_CREATIVE);
    config.addDefault("MyPet.Skill.Inventory.DropWhenOwnerDies", Skilltree.Skill.Inventory.DROP_WHEN_OWNER_DIES);
    config.addDefault("MyPet.Skill.Beacon.HungerDecreaseTime", Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME);
    config.addDefault("MyPet.Skill.Beacon.Party-Support", Skilltree.Skill.Beacon.PARTY_SUPPORT);
    config.addDefault("MyPet.Skill.Ride.Item", Material.LEASH.getId());
    config.addDefault("MyPet.Skill.Ride.HungerPerMeter", Skilltree.Skill.Ride.HUNGER_PER_METER);
    config.addDefault("MyPet.Info.Wiki-URL", Misc.WIKI_URL);
    for (EntityType entityType : EntityType.values()) {
        if (MonsterExperience.mobExp.containsKey(entityType.name())) {
            config.addDefault("MyPet.Exp.Active." + entityType.name() + ".Min", MonsterExperience.getMonsterExperience(entityType).getMin());
            config.addDefault("MyPet.Exp.Active." + entityType.name() + ".Max", MonsterExperience.getMonsterExperience(entityType).getMax());
        }
    }
    config.options().copyDefaults(true);
    MyPetApi.getPlugin().saveConfig();
    File petConfigFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "pet-config.yml");
    config = new YamlConfiguration();
    if (petConfigFile.exists()) {
        try {
            config.load(petConfigFile);
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }
    config.options().header("" + "#######################################################\n" + "       This is the pet configuration of MyPet         #\n" + "         You can find more info in the wiki:          #\n" + "       https://wiki.mypet-plugin.de/petconfig         #\n" + "#######################################################\n");
    config.options().copyHeader(true);
    for (MyPetType petType : MyPetType.values()) {
        DefaultInfo pi = petType.getMyPetClass().getAnnotation(DefaultInfo.class);
        if (pi == null) {
            continue;
        }
        config.addDefault("MyPet.Pets." + petType.name() + ".HP", pi.hp());
        config.addDefault("MyPet.Pets." + petType.name() + ".Speed", pi.walkSpeed());
        config.addDefault("MyPet.Pets." + petType.name() + ".Food", linkFood(pi.food()));
        config.addDefault("MyPet.Pets." + petType.name() + ".LeashFlags", linkLeashFlags(pi.leashFlags()));
        config.addDefault("MyPet.Pets." + petType.name() + ".CustomRespawnTimeFactor", 0);
        config.addDefault("MyPet.Pets." + petType.name() + ".CustomRespawnTimeFixed", 0);
        config.addDefault("MyPet.Pets." + petType.name() + ".LeashItem", Material.LEASH.getId());
    }
    config.addDefault("MyPet.Pets.Chicken.CanLayEggs", MyPet.Chicken.CAN_LAY_EGGS);
    config.addDefault("MyPet.Pets.Cow.CanGiveMilk", MyPet.Cow.CAN_GIVE_MILK);
    config.addDefault("MyPet.Pets.Sheep.CanBeSheared", MyPet.Sheep.CAN_BE_SHEARED);
    config.addDefault("MyPet.Pets.Sheep.CanRegrowWool", MyPet.Sheep.CAN_REGROW_WOOL);
    config.addDefault("MyPet.Pets.IronGolem.CanThrowUp", MyPet.IronGolem.CAN_THROW_UP);
    config.addDefault("MyPet.Pets.Snowman.FixSnowTrack", MyPet.Snowman.FIX_SNOW_TRACK);
    config.addDefault("MyPet.Pets.Chicken.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Cow.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Horse.GrowUpItem", Material.BREAD.getId());
    config.addDefault("MyPet.Pets.Llama.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Mooshroom.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Mooshroom.CanGiveStew", MyPet.Mooshroom.CAN_GIVE_SOUP);
    config.addDefault("MyPet.Pets.Ocelot.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Pig.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Sheep.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Villager.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Wolf.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Zombie.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.PigZombie.GrowUpItem", Material.POTION.getId());
    config.addDefault("MyPet.Pets.Rabbit.GrowUpItem", Material.POTION.getId());
    config.options().copyDefaults(true);
    try {
        config.save(petConfigFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) EntityType(org.bukkit.entity.EntityType) DefaultInfo(de.Keyle.MyPet.api.entity.DefaultInfo) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Aggregations

DefaultInfo (de.Keyle.MyPet.api.entity.DefaultInfo)2 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 File (java.io.File)2 IOException (java.io.IOException)2 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)1 ArrayList (java.util.ArrayList)1 EntityType (org.bukkit.entity.EntityType)1