Search in sources :

Example 6 with MyPetType

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

the class CommandPetType method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (args.length < 1) {
        return false;
    }
    String lang = "en";
    if (commandSender instanceof Player) {
        lang = MyPetApi.getPlatformHelper().getPlayerLanguage((Player) commandSender);
    }
    try {
        MyPetType myPetType = MyPetType.byName(args[0]);
        String leashFlagString = "";
        for (LeashFlag leashFlag : MyPetApi.getMyPetInfo().getLeashFlags(myPetType)) {
            leashFlagString += leashFlag.name() + ", ";
        }
        leashFlagString = leashFlagString.substring(0, leashFlagString.lastIndexOf(","));
        commandSender.sendMessage(Translation.getString("Name.LeashFlag", lang) + ": " + leashFlagString);
        String foodString = "";
        for (ConfigItem material : MyPetApi.getMyPetInfo().getFood(myPetType)) {
            foodString += WordUtils.capitalizeFully(MyPetApi.getPlatformHelper().getMaterialName(material.getItem().getTypeId()).replace("_", " ")) + ", ";
        }
        foodString = foodString.substring(0, foodString.lastIndexOf(","));
        commandSender.sendMessage(Translation.getString("Name.Food", lang) + ": " + foodString);
        commandSender.sendMessage(Translation.getString("Name.HP", lang) + ": " + MyPetApi.getMyPetInfo().getStartHP(myPetType));
    } catch (MyPetTypeNotFoundException e) {
        commandSender.sendMessage(Translation.getString("Message.Command.PetType.Unknown", lang));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) LeashFlag(de.Keyle.MyPet.api.entity.LeashFlag) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) ConfigItem(de.Keyle.MyPet.api.util.ConfigItem) MyPetTypeNotFoundException(de.Keyle.MyPet.api.exceptions.MyPetTypeNotFoundException)

Example 7 with MyPetType

use of de.Keyle.MyPet.api.entity.MyPetType 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 8 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_12_R1.RegistryMaterials) MyPetType(de.Keyle.MyPet.api.entity.MyPetType)

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