Search in sources :

Example 11 with Skilltree

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

the class SqLiteRepository method getAllMyPets.

@Override
public List<StoredMyPet> getAllMyPets() {
    try {
        List<MyPetPlayer> playerList = getAllMyPetPlayers();
        Map<UUID, MyPetPlayer> owners = new HashMap<>();
        for (MyPetPlayer player : playerList) {
            owners.put(player.getInternalUUID(), player);
        }
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM pets;");
        List<StoredMyPet> pets = new ArrayList<>();
        while (resultSet.next()) {
            if (!owners.containsKey(UUID.fromString(resultSet.getString("owner_uuid")))) {
                continue;
            }
            MyPetPlayer owner = owners.get(UUID.fromString(resultSet.getString("owner_uuid")));
            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(resultSet.getString("name"));
            pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
            pet.setLastUsed(resultSet.getLong("last_used"));
            pet.setSaturation(resultSet.getInt("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);
                }
            }
            pet.setSkills(TagStream.readTag(resultSet.getBytes("skills"), true));
            pet.setInfo(TagStream.readTag(resultSet.getBytes("info"), true));
            pets.add(pet);
        }
        return pets;
    } catch (SQLException | IOException e) {
        e.printStackTrace();
    }
    return new ArrayList<>();
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) IOException(java.io.IOException) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 12 with Skilltree

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

the class LevelListener method on.

@EventHandler
public void on(MyPetLevelEvent event) {
    if (event instanceof MyPetLevelUpEvent || event instanceof MyPetLevelDownEvent) {
        return;
    }
    MyPet myPet = event.getPet();
    int lvl = event.getLevel();
    myPet.getSkills().all().forEach(Skill::reset);
    Skilltree skilltree = myPet.getSkilltree();
    if (skilltree != null) {
        for (int i = 1; i <= lvl; i++) {
            List<Upgrade> upgrades = skilltree.getUpgrades(i);
            for (Upgrade upgrade : upgrades) {
                SkillName sn = Util.getClassAnnotation(upgrade.getClass(), SkillName.class);
                if (sn != null) {
                    Skill skill = myPet.getSkills().get(sn.value());
                    if (skill != null) {
                        upgrade.apply(skill);
                    }
                }
            }
        }
    }
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent) Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) SkillName(de.Keyle.MyPet.api.skill.SkillName) MyPetLevelDownEvent(de.Keyle.MyPet.api.event.MyPetLevelDownEvent) MyPet(de.Keyle.MyPet.api.entity.MyPet) Upgrade(de.Keyle.MyPet.api.skill.Upgrade) EventHandler(org.bukkit.event.EventHandler)

Example 13 with Skilltree

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

the class LevelListener method on.

@EventHandler
public void on(MyPetLevelDownEvent event) {
    MyPet myPet = event.getPet();
    int lvl = event.getLevel();
    int fromLvl = event.fromLevel();
    if (!event.isQuiet()) {
        myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.LevelDown", event.getOwner()), myPet.getPetName(), event.getLevel()));
    }
    Skilltree skilltree = myPet.getSkilltree();
    if (skilltree != null) {
        for (int i = fromLvl; i > lvl; i--) {
            List<Upgrade> upgrades = skilltree.getUpgrades(i);
            for (Upgrade upgrade : upgrades) {
                SkillName sn = Util.getClassAnnotation(upgrade.getClass(), SkillName.class);
                if (sn != null) {
                    Skill skill = myPet.getSkills().get(sn.value());
                    if (skill != null) {
                        upgrade.invert(skill);
                    }
                }
            }
        }
    }
    if (myPet.getStatus() == MyPet.PetState.Here) {
        myPet.getEntity().ifPresent(entity -> {
            entity.getHandle().updateNameTag();
            if (!event.isQuiet()) {
                myPet.setHealth(myPet.getMaxHealth());
                myPet.setSaturation(100);
                new FixedCircleAnimation(1, entity.getEyeHeight() + 0.5, 10, new EntityLocationHolder(entity)) {

                    @Override
                    protected void playParticleEffect(Location location) {
                        MyPetApi.getPlatformHelper().playParticleEffect(location, ParticleCompat.BLOCK_CRACK.get(), 0, 0, 0, 0, 1, 32, ParticleCompat.REDSTONE_BLOCK_DATA);
                    }
                }.once();
                entity.getWorld().playSound(entity.getLocation(), Sound.valueOf(SoundCompat.LEVEL_DOWN.get()), 1F, 0.7F);
            }
        });
    }
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) SkillName(de.Keyle.MyPet.api.skill.SkillName) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) MyPet(de.Keyle.MyPet.api.entity.MyPet) FixedCircleAnimation(de.Keyle.MyPet.api.util.animation.particle.FixedCircleAnimation) EntityLocationHolder(de.Keyle.MyPet.api.util.location.EntityLocationHolder) Upgrade(de.Keyle.MyPet.api.skill.Upgrade) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 14 with Skilltree

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

the class MongoDbRepository method documentToMyPet.

// Pets ------------------------------------------------------------------------------------------------------------
private StoredMyPet documentToMyPet(MyPetPlayer owner, Document document) {
    try {
        InactiveMyPet pet = new InactiveMyPet(owner);
        pet.setUUID(UUID.fromString(document.getString("uuid")));
        pet.setWorldGroup(document.getString("world_group"));
        pet.setExp(document.getDouble("exp"));
        pet.setHealth(document.getDouble("health"));
        pet.setRespawnTime(document.getInteger("respawn_time"));
        pet.setPetName(document.getString("name"));
        pet.setPetType(MyPetType.valueOf(document.getString("type")));
        pet.setLastUsed(document.getLong("last_used"));
        pet.setSaturation(((Number) document.get("hunger")).doubleValue());
        pet.wantsToRespawn = document.getBoolean("wants_to_spawn");
        String skillTreeName = document.getString("skilltree");
        if (skillTreeName != null) {
            Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
            if (skilltree != null) {
                pet.setSkilltree(skilltree);
            }
        }
        try {
            pet.setSkills(TagStream.readTag(((Binary) document.get("skills")).getData(), 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(((Binary) document.get("info")).getData(), 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);
        }
        return pet;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
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) Binary(org.bson.types.Binary) IOException(java.io.IOException)

Example 15 with Skilltree

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

the class SkillTreeLoaderNBT method loadSkillTree.

protected void loadSkillTree(ConfigurationNBT nbtConfiguration, SkillTreeMobType skillTreeMobType) {
    TagList skilltreeList = nbtConfiguration.getNBTCompound().getAs("Skilltrees", TagList.class);
    for (int i_skilltree = 0; i_skilltree < skilltreeList.size(); i_skilltree++) {
        TagCompound skilltreeCompound = skilltreeList.getTagAs(i_skilltree, TagCompound.class);
        SkillTree skillTree = new SkillTree(skilltreeCompound.getAs("Name", TagString.class).getStringData());
        int place = skilltreeCompound.getAs("Place", TagInt.class).getIntData();
        if (skilltreeCompound.getCompoundData().containsKey("Inherits")) {
            skillTree.setInheritance(skilltreeCompound.getAs("Inherits", TagString.class).getStringData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("Permission")) {
            skillTree.setPermission(skilltreeCompound.getAs("Permission", TagString.class).getStringData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("Display")) {
            skillTree.setDisplayName(skilltreeCompound.getAs("Display", TagString.class).getStringData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("MaxLevel")) {
            skillTree.setMaxLevel(skilltreeCompound.getAs("MaxLevel", TagInt.class).getIntData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("RequiredLevel")) {
            skillTree.setRequiredLevel(skilltreeCompound.getAs("RequiredLevel", TagInt.class).getIntData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("IconItem")) {
            skillTree.setIconItem(skilltreeCompound.getAs("IconItem", TagCompound.class));
        }
        if (skilltreeCompound.getCompoundData().containsKey("Description")) {
            TagList descriptionTagList = skilltreeCompound.getAs("Description", TagList.class);
            for (int i = 0; i < descriptionTagList.size(); i++) {
                skillTree.addDescriptionLine(descriptionTagList.getTagAs(i, TagString.class).getStringData());
            }
        }
        if (skilltreeCompound.getCompoundData().containsKey("Level")) {
            TagList levelList = skilltreeCompound.getAs("Level", TagList.class);
            for (int i_level = 0; i_level < levelList.size(); i_level++) {
                TagCompound levelCompound = levelList.getTag(i_level);
                int thisLevel;
                if (levelCompound.containsKeyAs("Level", TagInt.class)) {
                    thisLevel = levelCompound.getAs("Level", TagInt.class).getIntData();
                } else {
                    thisLevel = levelCompound.getAs("Level", TagShort.class).getShortData();
                }
                SkillTreeLevel newLevel = skillTree.addLevel(thisLevel);
                if (levelCompound.getCompoundData().containsKey("Message")) {
                    String message = levelCompound.getAs("Message", TagString.class).getStringData();
                    newLevel.setLevelupMessage(message);
                }
                TagList skillList = levelCompound.get("Skills");
                for (int i_skill = 0; i_skill < skillList.size(); i_skill++) {
                    TagCompound skillCompound = skillList.getTag(i_skill);
                    String skillName = skillCompound.getAs("Name", TagString.class).getStringData();
                    if (SkillsInfo.getSkillInfoClass(skillName) != null) {
                        TagCompound skillPropertyCompound = skillCompound.get("Properties");
                        SkillInfo skill = SkillsInfo.getNewSkillInfoInstance(skillName);
                        if (skill != null) {
                            skill.setProperties(skillPropertyCompound);
                            skill.setDefaultProperties();
                            skillTree.addSkillToLevel(thisLevel, skill);
                        }
                    }
                }
            }
        }
        skillTreeMobType.addSkillTree(skillTree, place);
    }
}
Also used : SkillTreeLevel(de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel) SkillInfo(de.Keyle.MyPet.api.skill.SkillInfo) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

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