Search in sources :

Example 1 with InfernalMobSpawnEvent

use of com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent in project InfernalMobs by NyaaCat.

the class MobManager method morphInfernalMob.

// preserve health and lives
public LivingEntity morphInfernalMob(LivingEntity mobEntity, Mob mob) {
    EntityType type = Helper.randomItem(ConfigReader.getEnabledEntityTypes());
    Location loc = mobEntity.getLocation();
    Entity spawnedEntity = loc.getWorld().spawnEntity(loc, type);
    UUID id = spawnedEntity.getUniqueId();
    mob.entityId = id;
    unnaturallySpawned.put(id, true);
    InfernalMobSpawnEvent spwanEvent = new InfernalMobSpawnEvent((LivingEntity) spawnedEntity, mob, mobEntity.getUniqueId(), InfernalSpawnReason.MORPH);
    for (EnumAbilities ability : mob.abilityList) ability.onMobSpawn(spwanEvent);
    ((LivingEntity) spawnedEntity).getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(mobEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue());
    ((LivingEntity) spawnedEntity).setHealth(mobEntity.getHealth());
    setInfernalMobName(spwanEvent);
    mobMap.put(id, mob);
    mobMap.remove(mobEntity.getUniqueId());
    mobEntity.remove();
    Bukkit.getPluginManager().callEvent(spwanEvent);
    return (LivingEntity) spawnedEntity;
}
Also used : InfernalMobSpawnEvent(com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities) Location(org.bukkit.Location)

Example 2 with InfernalMobSpawnEvent

use of com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent in project InfernalMobs by NyaaCat.

the class MobManager method spawnMob.

public Mob spawnMob(EntityType type, Location loc, List<EnumAbilities> abilities, UUID parentId, InfernalSpawnReason reason) {
    if (!type.isAlive())
        throw new IllegalArgumentException(type.name() + " is not a living entity");
    Entity spawnedEntity = loc.getWorld().spawnEntity(loc, type);
    UUID id = spawnedEntity.getUniqueId();
    int lives = abilities.contains(EnumAbilities.ONEUP) ? 2 : 1;
    Mob mob = new Mob(id, lives, ConfigReader.getRandomParticleEffect(), abilities);
    mobMap.put(id, mob);
    unnaturallySpawned.put(id, true);
    InfernalMobSpawnEvent spwanEvent = new InfernalMobSpawnEvent((LivingEntity) spawnedEntity, mob, parentId, reason);
    for (EnumAbilities ability : abilities) ability.onMobSpawn(spwanEvent);
    setInfernalHealth(spwanEvent);
    setInfernalMobName(spwanEvent);
    Bukkit.getServer().getPluginManager().callEvent(spwanEvent);
    return mob;
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) InfernalMobSpawnEvent(com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)

Example 3 with InfernalMobSpawnEvent

use of com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent in project InfernalMobs by NyaaCat.

the class MobManager method infernalNaturalSpawn.

/**
 * Change the given entity into infernal mob
 * may need to be called delayed
 *
 * @param mobEntity     the entity
 */
public void infernalNaturalSpawn(LivingEntity mobEntity) {
    if (mobEntity.isDead() || !mobEntity.isValid() || mobEntity.getCustomName() != null)
        return;
    if (mobEntity.hasMetadata("NPC") || mobEntity.hasMetadata("shopkeeper"))
        return;
    if (!isAcceptableBaby(mobEntity))
        return;
    final UUID id = mobEntity.getUniqueId();
    UUID parentId = mamaSpawned.getIfPresent(id);
    if (unnaturallySpawned.getIfPresent(id) != null)
        return;
    if (!Helper.possibility(ConfigReader.getInfernalNaturalSpawningPercentage()))
        return;
    List<EnumAbilities> abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), getInfernalLevelForLocation(mobEntity.getLocation()));
    if (abilities == null || abilities.size() <= 0)
        return;
    if (parentId != null) {
        if (!mobMap.containsKey(parentId) || mobMap.get(parentId).maxMamaInfernal <= 0) {
            return;
        }
        mobMap.get(parentId).maxMamaInfernal--;
        if (abilities.contains(EnumAbilities.MAMA)) {
            abilities.remove(EnumAbilities.MAMA);
            if (abilities.size() <= 0) {
                return;
            }
        }
    }
    // setup infernal mob
    int lives = abilities.contains(EnumAbilities.ONEUP) ? 2 : 1;
    Mob mob = new Mob(id, lives, ConfigReader.getRandomParticleEffect(), abilities);
    InfernalMobSpawnEvent spwanEvent;
    if (parentId != null) {
        spwanEvent = new InfernalMobSpawnEvent(mobEntity, mob, parentId, InfernalSpawnReason.MAMA);
    } else {
        spwanEvent = new InfernalMobSpawnEvent(mobEntity, mob, null, InfernalSpawnReason.NATURAL);
    }
    for (EnumAbilities ability : abilities) ability.onMobSpawn(spwanEvent);
    setInfernalHealth(spwanEvent);
    setInfernalMobName(spwanEvent);
    mobMap.put(id, mob);
    Bukkit.getPluginManager().callEvent(spwanEvent);
    // Show message
    if (ConfigReader.isSpwanMessageEnabled()) {
        String msg = Helper.randomItem(ConfigReader.getSpwanMessages());
        msg = msg.replace("{mob}", mobEntity.getCustomName() == null ? mobEntity.getType().name().toLowerCase() : mobEntity.getCustomName());
        msg = ChatColor.translateAlternateColorCodes('&', msg);
        if (ConfigReader.isBroadcastSpawnMessageServer()) {
            Bukkit.broadcastMessage(msg);
        } else if (ConfigReader.isBroadcastSpawnMessageWorld()) {
            for (Player p : mobEntity.getWorld().getPlayers()) {
                p.sendMessage(msg);
            }
        } else {
            int r = ConfigReader.getSpawnMessageBroadcaseRadius();
            for (Entity e : mobEntity.getNearbyEntities(r, r, r)) {
                if (e instanceof Player) {
                    e.sendMessage(msg);
                }
            }
        }
    }
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) InfernalMobSpawnEvent(com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)

Aggregations

EnumAbilities (com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)3 InfernalMobSpawnEvent (com.jacob_vejvoda.infernal_mobs.api.InfernalMobSpawnEvent)3 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)2 Location (org.bukkit.Location)1