Search in sources :

Example 11 with SkillTreeMobType

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

the class CommandOptionReloadSkilltrees method onCommandOption.

@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
    SkillTreeMobType.clearMobTypes();
    String[] petTypes = new String[MyPetType.values().length + 1];
    petTypes[0] = "default";
    for (int i = 1; i <= MyPetType.values().length; i++) {
        petTypes[i] = MyPetType.values()[i - 1].name();
    }
    for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
        myPet.getSkills().reset();
    }
    SkillTreeMobType.clearMobTypes();
    SkillTreeLoaderNBT.getSkilltreeLoader().loadSkillTrees(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "skilltrees", petTypes);
    Set<String> skilltreeNames = new LinkedHashSet<>();
    for (MyPetType mobType : MyPetType.values()) {
        SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(mobType);
        SkillTreeLoader.addDefault(skillTreeMobType);
        SkillTreeLoader.manageInheritance(skillTreeMobType);
        skilltreeNames.addAll(skillTreeMobType.getSkillTreeNames());
    }
    // register skilltree permissions
    for (String skilltreeName : skilltreeNames) {
        try {
            Bukkit.getPluginManager().addPermission(new Permission("MyPet.custom.skilltree." + skilltreeName));
        } catch (Exception ignored) {
        }
    }
    for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
        myPet.getSkills().reset();
        SkillTree skillTree = myPet.getSkilltree();
        if (skillTree != null) {
            String skilltreeName = skillTree.getName();
            if (SkillTreeMobType.hasMobType(myPet.getPetType())) {
                SkillTreeMobType mobType = SkillTreeMobType.byPetType(myPet.getPetType());
                if (mobType.hasSkillTree(skilltreeName)) {
                    skillTree = mobType.getSkillTree(skilltreeName);
                } else {
                    skillTree = null;
                }
            } else {
                skillTree = null;
            }
        }
        myPet.setSkilltree(skillTree);
        if (skillTree != null) {
            sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skills.Show", myPet.getOwner()), myPet.getPetName(), (myPet.getSkilltree() == null ? "-" : myPet.getSkilltree().getDisplayName())));
            for (SkillInstance skill : myPet.getSkills().getSkills()) {
                if (skill.isActive()) {
                    myPet.getOwner().sendMessage("  " + ChatColor.GREEN + skill.getName(myPet.getOwner().getLanguage()) + ChatColor.RESET + " " + skill.getFormattedValue());
                }
            }
        }
    }
    sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] skilltrees loaded!");
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) MyPet(de.Keyle.MyPet.api.entity.MyPet) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) Permission(org.bukkit.permissions.Permission) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Example 12 with SkillTreeMobType

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

the class CommandOptionSkilltree method onCommandOption.

@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
    if (args.length < 2) {
        return false;
    }
    String lang = MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender);
    Player petOwner = Bukkit.getServer().getPlayer(args[0]);
    if (petOwner == null || !petOwner.isOnline()) {
        sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.No.PlayerOnline", lang));
        return true;
    } else if (!MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
        sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.No.UserHavePet", lang), petOwner.getName()));
        return true;
    }
    MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
    SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(myPet.getPetType());
    if (skillTreeMobType.hasSkillTree(args[1])) {
        SkillTree skillTree = skillTreeMobType.getSkillTree(args[1]);
        if (myPet.setSkilltree(skillTree)) {
            sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.Skilltree.SwitchedToFor", lang), petOwner.getName(), skillTree.getName()));
        } else {
            sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.Skilltree.NotSwitched", lang));
        }
    } else {
        sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", lang), args[1]));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) MyPet(de.Keyle.MyPet.api.entity.MyPet) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Example 13 with SkillTreeMobType

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

the class InactiveMyPet method load.

@Override
public void load(TagCompound myPetNBT) {
    if (myPetNBT.getCompoundData().containsKey("UUID")) {
        uuid = UUID.fromString(myPetNBT.getAs("UUID", TagString.class).getStringData());
    }
    exp = myPetNBT.getAs("Exp", TagDouble.class).getDoubleData();
    if (myPetNBT.containsKeyAs("Health", TagInt.class)) {
        health = myPetNBT.getAs("Health", TagInt.class).getIntData();
    } else if (myPetNBT.containsKeyAs("Health", TagDouble.class)) {
        health = myPetNBT.getAs("Health", TagDouble.class).getDoubleData();
    }
    respawnTime = myPetNBT.getAs("Respawntime", TagInt.class).getIntData();
    petName = myPetNBT.getAs("Name", TagString.class).getStringData();
    if (myPetNBT.getCompoundData().containsKey("Type")) {
        petType = MyPetType.valueOf(myPetNBT.getAs("Type", TagString.class).getStringData());
    }
    if (myPetNBT.getCompoundData().containsKey("LastUsed")) {
        lastUsed = myPetNBT.getAs("LastUsed", TagLong.class).getLongData();
    }
    if (myPetNBT.getCompoundData().containsKey("Skilltree")) {
        String skillTreeName = myPetNBT.getAs("Skilltree", TagString.class).getStringData();
        if (skillTreeName != null) {
            if (SkillTreeMobType.byPetType(petType) != null) {
                SkillTreeMobType mobType = SkillTreeMobType.byPetType(petType);
                if (mobType.hasSkillTree(skillTreeName)) {
                    this.skillTree = mobType.getSkillTree(skillTreeName);
                }
            }
        }
    }
    if (myPetNBT.containsKeyAs("Hunger", TagInt.class)) {
        saturation = myPetNBT.getAs("Hunger", TagInt.class).getIntData();
    } else if (myPetNBT.containsKeyAs("Hunger", TagDouble.class)) {
        saturation = myPetNBT.getAs("Hunger", TagDouble.class).getDoubleData();
    }
    if (myPetNBT.getCompoundData().containsKey("WorldGroup")) {
        worldGroup = myPetNBT.getAs("WorldGroup", TagString.class).getStringData();
    }
    if (myPetNBT.getCompoundData().containsKey("Wants-To-Respawn")) {
        wantsToRespawn = myPetNBT.getAs("Wants-To-Respawn", TagByte.class).getBooleanData();
    }
    setSkills(myPetNBT.getAs("Skills", TagCompound.class));
    setInfo(myPetNBT.getAs("Info", TagCompound.class));
}
Also used : SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)

Aggregations

SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)13 SkillTree (de.Keyle.MyPet.api.skill.skilltree.SkillTree)8 MyPet (de.Keyle.MyPet.api.entity.MyPet)5 Player (org.bukkit.entity.Player)5 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)4 ArrayList (java.util.ArrayList)4 SkillInfo (de.Keyle.MyPet.api.skill.SkillInfo)3 SkillTreeLevel (de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel)3 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)2 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)2 File (java.io.File)2 IOException (java.io.IOException)2 Permission (org.bukkit.permissions.Permission)2 IconMenu (de.Keyle.MyPet.api.gui.IconMenu)1 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)1 SkillInstance (de.Keyle.MyPet.api.skill.SkillInstance)1 ConfigurationNBT (de.Keyle.MyPet.api.util.configuration.ConfigurationNBT)1 RepositoryMyPetConverterService (de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService)1 SqLiteRepository (de.Keyle.MyPet.repository.types.SqLiteRepository)1