Search in sources :

Example 1 with InvalidMobTypeException

use of io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException in project solinia3-core by mixxit.

the class EntityManager method SpawnPet.

@Override
public LivingEntity SpawnPet(Player owner, ISoliniaSpell spell) {
    if (owner.isDead())
        return null;
    try {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(owner.getUniqueId());
        if (pet != null) {
            // insta kill old pet
            pet.damage(10000000);
        // ISoliniaLivingEntity solLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
        // solLivingEntity.get
        // StateManager.getInstance().getEntityManager().removePet(owner.getUniqueId(), !solLivingEntity.isCharmed());
        }
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(spell.getTeleportZone());
        if (npc == null)
            return null;
        if (npc.isCorePet() == false)
            return null;
        // 
        // PET FOCUS ITEM
        // If owner is wearing a focus item at this point, and it is valid then we should record the mob is now
        // part of this focus
        LivingEntity spawnedMob = (LivingEntity) MythicMobs.inst().getAPIHelper().spawnMythicMob("NPCID_" + npc.getId(), owner.getLocation());
        spawnedMob.setCollidable(false);
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(owner);
        int petFocus = solplayer.getPetFocus(npc);
        if (petFocus > 0) {
            StateManager.getInstance().getEntityManager().setPetFocus(spawnedMob.getUniqueId(), petFocus);
            solplayer.getBukkitPlayer().sendMessage("Your pet focus shimmers with a bright light");
        }
        ISoliniaLivingEntity solPet = SoliniaLivingEntityAdapter.Adapt((LivingEntity) spawnedMob);
        StateManager.getInstance().getEntityManager().setPet(owner.getUniqueId(), spawnedMob);
        spawnedMob.setCustomName(solplayer.getForename() + "s_Pet");
        spawnedMob.setCustomNameVisible(true);
        spawnedMob.setCanPickupItems(false);
        spawnedMob.setRemoveWhenFarAway(false);
        double maxHp = solPet.getMaxHP();
        if (npc.getForcedMaxHp() > 0) {
            maxHp = (double) npc.getForcedMaxHp();
        }
        AttributeInstance healthAttribute = spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH);
        healthAttribute.setBaseValue(maxHp);
        if (!spawnedMob.isDead())
            spawnedMob.setHealth(maxHp);
        net.minecraft.server.v1_15_R1.EntityInsentient entityhandle = (net.minecraft.server.v1_15_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) spawnedMob).getHandle();
        entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue((double) npc.getBaseDamage());
        entityhandle.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((double) 0.4D);
        owner.sendMessage("New Pet spawned with HP: " + spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() + " and " + npc.getBaseDamage() + " dmg");
        Disguise disg = new MobDisguise(DisguiseType.WOLF);
        if (npc.getDisguiseId() > 0 && npc.getDisguise() != null)
            disg = npc.getDisguise().getLibsDisguise(0);
        if (npc.isRacialPet() && solplayer.getRace() != null && solplayer.getRace().getRacePetDisguiseId() > 0 && solplayer.getRace().getRacePetDisguise() != null)
            disg = solplayer.getRace().getRacePetDisguise().getLibsDisguise(0);
        DisguiseAPI.disguiseEntity(spawnedMob, disg);
        return spawnedMob;
    } catch (CoreStateInitException e) {
        return null;
    } catch (InvalidMobTypeException e) {
        return null;
    }
}
Also used : MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) Disguise(me.libraryaddict.disguise.disguisetypes.Disguise) InvalidMobTypeException(io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException) MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) AttributeInstance(org.bukkit.attribute.AttributeInstance) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 SoliniaLivingEntity (com.solinia.solinia.Models.SoliniaLivingEntity)1 InvalidMobTypeException (io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException)1 Disguise (me.libraryaddict.disguise.disguisetypes.Disguise)1 MobDisguise (me.libraryaddict.disguise.disguisetypes.MobDisguise)1 AttributeInstance (org.bukkit.attribute.AttributeInstance)1 LivingEntity (org.bukkit.entity.LivingEntity)1