Search in sources :

Example 1 with MyPetType

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

the class EntityRegistry method registerEntityTypes.

@Override
@SuppressWarnings("unchecked")
public void registerEntityTypes() {
    RegistryMaterials registry = getRegistry();
    Object[] backup = backupRegistryID(registry);
    for (MyPetType type : entityClasses.keySet()) {
        try {
            registry.a(type.getTypeID(), null, entityClasses.get(type));
        } catch (NullPointerException ignored) {
        // NPE means that the entity was registered successfully but the key was not
        }
    }
    restoreRegistryID(registry, backup);
}
Also used : RegistryMaterials(net.minecraft.server.v1_11_R1.RegistryMaterials) MyPetType(de.Keyle.MyPet.api.entity.MyPetType)

Example 2 with MyPetType

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

the class CommandShowSkillTree method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        SkillTreeMobType mobType;
        if (args.length >= 1) {
            if (args[0].equalsIgnoreCase("default")) {
                mobType = SkillTreeMobType.DEFAULT;
            } else {
                MyPetType type = MyPetType.byName(args[0]);
                if (type != null) {
                    mobType = SkillTreeMobType.byPetType(type);
                } else {
                    MyPetApi.getLogger().info("There is " + ChatColor.RED + "no" + ChatColor.RESET + " mobtype with the name: " + ChatColor.AQUA + args[0]);
                    return true;
                }
            }
            if (args.length >= 2) {
                if (mobType.hasSkillTree(args[1])) {
                    SkillTree skillTree = mobType.getSkillTree(args[1]);
                    MyPetApi.getLogger().info("----- MyPet Skilltree: " + ChatColor.AQUA + skillTree.getName() + ChatColor.RESET + " - Inherits: " + (skillTree.getInheritance() != null ? ChatColor.AQUA + skillTree.getInheritance() + ChatColor.RESET : ChatColor.DARK_GRAY + "none" + ChatColor.RESET) + " -----");
                    for (SkillTreeLevel lvl : skillTree.getLevelList()) {
                        MyPetApi.getLogger().info(ChatColor.YELLOW + " " + lvl.getLevel() + ChatColor.RESET + ": (" + (lvl.hasLevelupMessage() ? Colorizer.setColors(lvl.getLevelupMessage()) + ChatColor.RESET : "-") + ")");
                        for (SkillInfo skill : lvl.getSkills()) {
                            if (skill.isAddedByInheritance()) {
                                MyPetApi.getLogger().info("   " + ChatColor.DARK_GRAY + skill.getName());
                            } else {
                                MyPetApi.getLogger().info("   " + skill.getName());
                            }
                        }
                    }
                    MyPetApi.getLogger().info("----- MyPet Skilltree " + ChatColor.AQUA + skillTree.getName() + ChatColor.RESET + " end -----");
                } else {
                    MyPetApi.getLogger().info("There is " + ChatColor.RED + "no" + ChatColor.RESET + " skilltree with the name: " + ChatColor.AQUA + args[1]);
                }
            } else {
                MyPetApi.getLogger().info("----- MyPet Skilltrees for: " + ChatColor.GREEN + args[0]);
                for (String skillTreeName : mobType.getSkillTreeNames()) {
                    MyPetApi.getLogger().info("   " + skillTreeName);
                }
            }
        } else {
            return false;
        }
    } else {
        sender.sendMessage("Can only be used in server console");
    }
    return true;
}
Also used : SkillTreeLevel(de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel) SkillInfo(de.Keyle.MyPet.api.skill.SkillInfo) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Example 3 with MyPetType

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

the class CommandOptionCreate method onCommandOption.

@Override
public boolean onCommandOption(final CommandSender sender, String[] args) {
    if (args.length < 2) {
        return false;
    }
    String lang = MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender);
    int forceOffset = 0;
    if (args[0].equalsIgnoreCase("-f")) {
        forceOffset = 1;
        if (args.length < 3) {
            return false;
        }
    }
    try {
        MyPetType myPetType = MyPetType.byName(args[1 + forceOffset]);
        if (MyPetApi.getMyPetInfo().isLeashableEntityType(EntityType.valueOf(myPetType.getBukkitName()))) {
            Player owner = Bukkit.getPlayer(args[forceOffset]);
            if (owner == null || !owner.isOnline()) {
                sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.No.PlayerOnline", lang));
                return true;
            }
            final MyPetPlayer newOwner;
            if (MyPetApi.getPlayerManager().isMyPetPlayer(owner)) {
                newOwner = MyPetApi.getPlayerManager().getMyPetPlayer(owner);
                if (newOwner.hasMyPet() && forceOffset == 1) {
                    MyPetApi.getMyPetManager().deactivateMyPet(newOwner, true);
                }
            } else {
                newOwner = MyPetApi.getPlayerManager().registerMyPetPlayer(owner);
            }
            final InactiveMyPet inactiveMyPet = new InactiveMyPet(newOwner);
            inactiveMyPet.setPetType(myPetType);
            inactiveMyPet.setPetName(Translation.getString("Name." + inactiveMyPet.getPetType().name(), inactiveMyPet.getOwner().getLanguage()));
            TagCompound compound = inactiveMyPet.getInfo();
            createInfo(myPetType, Arrays.copyOfRange(args, 2 + forceOffset, args.length), compound);
            final WorldGroup wg = WorldGroup.getGroupByWorld(owner.getWorld().getName());
            inactiveMyPet.setWorldGroup(wg.getName());
            Optional<RepositoryMyPetConverterService> converter = MyPetApi.getServiceManager().getService(RepositoryMyPetConverterService.class);
            if (converter.isPresent()) {
                converter.get().convert(inactiveMyPet);
            }
            MyPetCreateEvent createEvent = new MyPetCreateEvent(inactiveMyPet, MyPetCreateEvent.Source.AdminCommand);
            Bukkit.getServer().getPluginManager().callEvent(createEvent);
            MyPetSaveEvent saveEvent = new MyPetSaveEvent(inactiveMyPet);
            Bukkit.getServer().getPluginManager().callEvent(saveEvent);
            MyPetApi.getRepository().addMyPet(inactiveMyPet, new RepositoryCallback<Boolean>() {

                @Override
                public void callback(Boolean added) {
                    if (added) {
                        if (!newOwner.hasMyPet()) {
                            inactiveMyPet.getOwner().setMyPetForWorldGroup(wg, inactiveMyPet.getUUID());
                            MyPetApi.getRepository().updateMyPetPlayer(inactiveMyPet.getOwner(), null);
                            Optional<MyPet> myPet = MyPetApi.getMyPetManager().activateMyPet(inactiveMyPet);
                            if (myPet.isPresent()) {
                                myPet.get().createEntity();
                                sender.sendMessage(Translation.getString("Message.Command.Success", sender));
                            } else {
                                sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] Can't create MyPet for " + newOwner.getName() + ". Is this player online?");
                            }
                        } else {
                            sender.sendMessage(Translation.getString("Message.Command.Success", sender));
                        }
                    }
                }
            });
        }
    } catch (MyPetTypeNotFoundException e) {
        sender.sendMessage(Translation.getString("Message.Command.PetType.Unknown", lang));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) Optional(com.google.common.base.Optional) WorldGroup(de.Keyle.MyPet.api.WorldGroup) TagCompound(de.keyle.knbt.TagCompound) MyPetSaveEvent(de.Keyle.MyPet.api.event.MyPetSaveEvent) MyPetCreateEvent(de.Keyle.MyPet.api.event.MyPetCreateEvent) RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) MyPetTypeNotFoundException(de.Keyle.MyPet.api.exceptions.MyPetTypeNotFoundException)

Example 4 with MyPetType

use of de.Keyle.MyPet.api.entity.MyPetType 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 5 with MyPetType

use of de.Keyle.MyPet.api.entity.MyPetType 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

MyPetType (de.Keyle.MyPet.api.entity.MyPetType)8 DefaultInfo (de.Keyle.MyPet.api.entity.DefaultInfo)2 MyPetTypeNotFoundException (de.Keyle.MyPet.api.exceptions.MyPetTypeNotFoundException)2 SkillTree (de.Keyle.MyPet.api.skill.skilltree.SkillTree)2 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)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 Player (org.bukkit.entity.Player)2 Optional (com.google.common.base.Optional)1 WorldGroup (de.Keyle.MyPet.api.WorldGroup)1 LeashFlag (de.Keyle.MyPet.api.entity.LeashFlag)1 MyPet (de.Keyle.MyPet.api.entity.MyPet)1 MyPetCreateEvent (de.Keyle.MyPet.api.event.MyPetCreateEvent)1 MyPetSaveEvent (de.Keyle.MyPet.api.event.MyPetSaveEvent)1 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)1 SkillInfo (de.Keyle.MyPet.api.skill.SkillInfo)1