Search in sources :

Example 6 with Skilltree

use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.

the class SkillTreeLoader method manageInheritance.

public static void manageInheritance(SkillTreeMobType skillTreeMobType) {
    Map<SkillTree, SkillTree> skillTreeClones = new HashMap<>();
    for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
        skillTreeClones.put(skillTree, skillTree.clone());
    }
    for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
        alreadyLoadedInheritance.clear();
        if (skillTree.hasInheritance()) {
            alreadyLoadedInheritance.add(skillTree);
            manageInheritance(skillTreeMobType, skillTree, skillTree, skillTreeClones, 0);
        }
    }
}
Also used : SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Example 7 with Skilltree

use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.

the class SkillTreeLoaderNBT method saveSkillTree.

protected boolean saveSkillTree(ConfigurationNBT nbtConfiguration, String petTypeName) {
    boolean saveMobType = false;
    SkillTreeMobType mobType;
    if (petTypeName.equalsIgnoreCase("default")) {
        mobType = SkillTreeMobType.DEFAULT;
    } else if (SkillTreeMobType.hasMobType(MyPetType.byName(petTypeName, false))) {
        mobType = SkillTreeMobType.getMobTypeByName(petTypeName);
    } else {
        return false;
    }
    if (mobType.getSkillTreeNames().size() != 0) {
        mobType.cleanupPlaces();
        List<TagCompound> skilltreeList = new ArrayList<>();
        for (SkillTree skillTree : mobType.getSkillTrees()) {
            TagCompound skilltreeCompound = new TagCompound();
            skilltreeCompound.getCompoundData().put("Name", new TagString(skillTree.getName()));
            skilltreeCompound.getCompoundData().put("Place", new TagInt(mobType.getSkillTreePlace(skillTree)));
            if (skillTree.hasInheritance()) {
                skilltreeCompound.getCompoundData().put("Inherits", new TagString(skillTree.getInheritance()));
            }
            if (skillTree.hasCustomPermissions()) {
                skilltreeCompound.getCompoundData().put("Permission", new TagString(skillTree.getPermission()));
            }
            if (skillTree.hasDisplayName()) {
                skilltreeCompound.getCompoundData().put("Display", new TagString(skillTree.getDisplayName()));
            }
            if (skillTree.getMaxLevel() > 0) {
                skilltreeCompound.getCompoundData().put("MaxLevel", new TagInt(skillTree.getMaxLevel()));
            }
            if (skillTree.getRequiredLevel() > 1) {
                skilltreeCompound.getCompoundData().put("RequiredLevel", new TagInt(skillTree.getRequiredLevel()));
            }
            if (skillTree.getDescription().size() > 0) {
                List<TagString> descriptionTagList = new ArrayList<>();
                for (String line : skillTree.getDescription()) {
                    descriptionTagList.add(new TagString(line));
                }
                skilltreeCompound.getCompoundData().put("Description", new TagList(descriptionTagList));
            }
            skilltreeCompound.getCompoundData().put("IconItem", skillTree.getIconItem());
            List<TagCompound> levelList = new ArrayList<>();
            for (SkillTreeLevel level : skillTree.getLevelList()) {
                TagCompound levelCompound = new TagCompound();
                levelCompound.getCompoundData().put("Level", new TagInt(level.getLevel()));
                if (level.hasLevelupMessage()) {
                    levelCompound.getCompoundData().put("Message", new TagString(level.getLevelupMessage()));
                }
                List<TagCompound> skillList = new ArrayList<>();
                for (SkillInfo skill : skillTree.getLevel(level.getLevel()).getSkills()) {
                    if (!skill.isAddedByInheritance()) {
                        TagCompound skillCompound = new TagCompound();
                        skillCompound.getCompoundData().put("Name", new TagString(skill.getName()));
                        skillCompound.getCompoundData().put("Properties", skill.getProperties());
                        skillList.add(skillCompound);
                    }
                }
                levelCompound.getCompoundData().put("Skills", new TagList(skillList));
                levelList.add(levelCompound);
            }
            skilltreeCompound.getCompoundData().put("Level", new TagList(levelList));
            skilltreeList.add(skilltreeCompound);
        }
        nbtConfiguration.getNBTCompound().getCompoundData().put("Skilltrees", new TagList(skilltreeList));
        if (mobType.getSkillTreeNames().size() > 0) {
            nbtConfiguration.save();
            saveMobType = true;
        }
    }
    return saveMobType;
}
Also used : SkillInfo(de.Keyle.MyPet.api.skill.SkillInfo) ArrayList(java.util.ArrayList) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree) SkillTreeLevel(de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)

Example 8 with Skilltree

use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.

the class CommandOptionSkilltree method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender commandSender, String[] strings) {
    if (strings.length == 2) {
        return null;
    }
    if (strings.length == 3) {
        Player player = Bukkit.getServer().getPlayer(strings[1]);
        if (player == null || !player.isOnline()) {
            return Collections.emptyList();
        }
        if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
            MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
            List<String> skilltreeList = new ArrayList<>();
            for (Skilltree skilltree : MyPetApi.getSkilltreeManager().getSkilltrees()) {
                if (skilltree.getMobTypes().contains(myPet.getPetType())) {
                    skilltreeList.add(skilltree.getName());
                }
            }
            return filterTabCompletionResults(skilltreeList, strings[2]);
        }
    }
    return Collections.emptyList();
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) Player(org.bukkit.entity.Player) MyPet(de.Keyle.MyPet.api.entity.MyPet) ArrayList(java.util.ArrayList)

Example 9 with Skilltree

use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.

the class CommandChooseSkilltree method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String s, String[] strings) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (Permissions.has(player, "MyPet.admin", false)) {
            if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
                MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
                List<String> skilltreeList = new ArrayList<>();
                for (Skilltree skilltree : MyPetApi.getSkilltreeManager().getOrderedSkilltrees()) {
                    if (skilltree.getMobTypes().contains(myPet.getPetType()) && skilltree.checkRequirements(myPet)) {
                        skilltreeList.add(skilltree.getName());
                    }
                }
                return filterTabCompletionResults(skilltreeList, strings[0]);
            }
        }
    }
    return Collections.emptyList();
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPet(de.Keyle.MyPet.api.entity.MyPet)

Example 10 with Skilltree

use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.

the class MySqlRepository method resultSetToMyPet.

// Pets ------------------------------------------------------------------------------------------------------------
private List<StoredMyPet> resultSetToMyPet(MyPetPlayer owner, ResultSet resultSet) {
    List<StoredMyPet> pets = new ArrayList<>();
    try {
        while (resultSet.next()) {
            InactiveMyPet pet = new InactiveMyPet(owner);
            pet.setUUID(UUID.fromString(resultSet.getString("uuid")));
            pet.setWorldGroup(resultSet.getString("world_group"));
            pet.setExp(resultSet.getDouble("exp"));
            pet.setHealth(resultSet.getDouble("health"));
            pet.setRespawnTime(resultSet.getInt("respawn_time"));
            pet.setPetName(Util.toString(resultSet.getBinaryStream("name"), StandardCharsets.UTF_8));
            pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
            pet.setLastUsed(resultSet.getLong("last_used"));
            pet.setSaturation(resultSet.getDouble("hunger"));
            pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
            String skillTreeName = resultSet.getString("skilltree");
            if (skillTreeName != null) {
                Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
                if (skilltree != null) {
                    pet.setSkilltree(skilltree);
                }
            }
            try {
                pet.setSkills(TagStream.readTag(resultSet.getBlob("skills").getBinaryStream(), true));
            } catch (ZipException exception) {
                MyPetApi.getMyPetLogger().warning("Pet skills of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
            }
            try {
                pet.setInfo(TagStream.readTag(resultSet.getBlob("info").getBinaryStream(), true));
            } catch (ZipException exception) {
                MyPetApi.getMyPetLogger().warning("Pet info of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
            }
            List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
            for (RepositoryMyPetConverterService converter : converters) {
                converter.convert(pet);
            }
            pets.add(pet);
        }
    } catch (SQLException | IOException e) {
        e.printStackTrace();
    }
    return pets;
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) ZipException(java.util.zip.ZipException) TagString(de.keyle.knbt.TagString) IOException(java.io.IOException) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Aggregations

Skilltree (de.Keyle.MyPet.api.skill.skilltree.Skilltree)16 MyPet (de.Keyle.MyPet.api.entity.MyPet)10 SkillTree (de.Keyle.MyPet.api.skill.skilltree.SkillTree)9 SkillInfo (de.Keyle.MyPet.api.skill.SkillInfo)6 SkillTreeLevel (de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel)6 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)5 IOException (java.io.IOException)5 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)4 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)4 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 SkillName (de.Keyle.MyPet.api.skill.SkillName)3 Upgrade (de.Keyle.MyPet.api.skill.Upgrade)3 Skill (de.Keyle.MyPet.api.skill.skilltree.Skill)3 EntityLocationHolder (de.Keyle.MyPet.api.util.location.EntityLocationHolder)3 RepositoryMyPetConverterService (de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService)3 TagString (de.keyle.knbt.TagString)3 Location (org.bukkit.Location)3 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2