Search in sources :

Example 16 with Creature

use of org.bukkit.entity.Creature in project solinia3-core by mixxit.

the class EntityManager method doNPCSpellCast.

@Override
public void doNPCSpellCast(Plugin plugin) {
    List<Integer> completedNpcsIds = new ArrayList<Integer>();
    for (Player player : Bukkit.getOnlinePlayers()) {
        for (Entity entityThatWillCast : player.getNearbyEntities(50, 50, 50)) {
            if (entityThatWillCast instanceof Player)
                continue;
            if (!(entityThatWillCast instanceof LivingEntity))
                continue;
            LivingEntity livingEntityThatWillCast = (LivingEntity) entityThatWillCast;
            if (!(entityThatWillCast instanceof Creature))
                continue;
            if (entityThatWillCast.isDead())
                continue;
            Creature creatureThatWillCast = (Creature) entityThatWillCast;
            if (creatureThatWillCast.getTarget() == null)
                continue;
            if (!Utils.isLivingEntityNPC(livingEntityThatWillCast))
                continue;
            try {
                ISoliniaLivingEntity solLivingEntityThatWillCast = SoliniaLivingEntityAdapter.Adapt(livingEntityThatWillCast);
                if (completedNpcsIds.contains(solLivingEntityThatWillCast.getNpcid()))
                    continue;
                completedNpcsIds.add(solLivingEntityThatWillCast.getNpcid());
                if (Utils.isEntityInLineOfSight(livingEntityThatWillCast, creatureThatWillCast.getTarget()))
                    solLivingEntityThatWillCast.doSpellCast(plugin, creatureThatWillCast.getTarget());
            } catch (CoreStateInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList)

Example 17 with Creature

use of org.bukkit.entity.Creature in project solinia3-core by mixxit.

the class Solinia3CoreEntityListener method onEntityTargetEvent.

// Needs to occur before anything else
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityTargetEvent(EntityTargetEvent event) {
    if (event.isCancelled())
        return;
    if (!(event.getEntity() instanceof Creature))
        return;
    try {
        Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
        if (mzExpiry != null) {
            if (event.getEntity() instanceof Player) {
                event.getEntity().sendMessage("* You are mezzed!");
            }
            Utils.CancelEvent(event);
            ;
            return;
        }
    } catch (CoreStateInitException e) {
    }
    try {
        // Me
        ISoliniaLivingEntity solEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
        if (solEntity.isUndead() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
            if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead2)) {
                ((Creature) event.getEntity()).setTarget(null);
                Utils.CancelEvent(event);
                ;
                return;
            }
        }
        if (!solEntity.isUndead() && !(event.getEntity() instanceof Player) && !solEntity.isAnimal() && event.getTarget() instanceof LivingEntity) {
            if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility2)) {
                ((Creature) event.getEntity()).setTarget(null);
                Utils.CancelEvent(event);
                ;
                return;
            }
        }
        if (solEntity.isAnimal() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
            if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsAnimals) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.ImprovedInvisAnimals)) {
                ((Creature) event.getEntity()).setTarget(null);
                Utils.CancelEvent(event);
                ;
                return;
            }
        }
        // rogue sneak
        if (event.getTarget() instanceof Player && !(event.getEntity() instanceof Player)) {
            Player targetPlayer = (Player) event.getTarget();
            if (targetPlayer.isSneaking()) {
                ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) event.getTarget());
                if (player.getClassObj() != null) {
                    if (player.getClassObj().isSneakFromCrouch()) {
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                }
            }
        }
        if (event.getEntity() != null && event.getTarget() != null) {
            if (!(event.getEntity() instanceof Player)) {
                if (event.getEntity() instanceof LivingEntity) {
                    ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                }
                // Mez cancel target
                Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getTarget());
                if (mezExpiry != null) {
                    ((Creature) event.getEntity()).setTarget(null);
                    event.getEntity().sendMessage("The target is mezzed, you cannot hit it");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            }
        }
    } catch (CoreStateInitException e) {
        return;
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Timestamp(java.sql.Timestamp) EventHandler(org.bukkit.event.EventHandler)

Example 18 with Creature

use of org.bukkit.entity.Creature in project solinia3-core by mixxit.

the class SoliniaLivingEntity method doCheckForEnemies.

@Override
public void doCheckForEnemies() {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    if (getBukkitLivingEntity().isDead())
        return;
    if (!(getBukkitLivingEntity() instanceof Creature))
        return;
    if (((Creature) getBukkitLivingEntity()).getTarget() != null)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc.getFactionid() == 0)
            return;
        ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
        if (faction.getName().equals("NEUTRAL") || faction.getName().equals("KOS"))
            return;
        for (Entity entity : getBukkitLivingEntity().getNearbyEntities(10, 10, 10)) {
            if (!(entity instanceof Player))
                continue;
            if (entity.isDead())
                continue;
            Player player = (Player) entity;
            ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
            PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
            if (factionEntry != null) {
                switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
                    case FACTION_THREATENLY:
                    case FACTION_SCOWLS:
                        if (Utils.isEntityInLineOfSight(player, getBukkitLivingEntity())) {
                            ((Creature) getBukkitLivingEntity()).setTarget(player);
                            return;
                        } else {
                            continue;
                        }
                    default:
                        break;
                }
            }
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 19 with Creature

use of org.bukkit.entity.Creature in project solinia3-core by mixxit.

the class SoliniaItem method useItemOnEntity.

@Override
public boolean useItemOnEntity(Plugin plugin, Player player, LivingEntity targetentity, boolean isConsumable) throws CoreStateInitException {
    if (isPetControlRod()) {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player);
        if (pet != null) {
            if (pet instanceof Wolf) {
                // Mez cancel target
                Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed(targetentity);
                if (mezExpiry != null) {
                    ((Creature) pet).setTarget(null);
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(null);
                    player.sendMessage("You cannot send your pet to attack a mezzed player");
                    return false;
                }
                if (!pet.getUniqueId().equals(targetentity.getUniqueId())) {
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(targetentity);
                    player.sendMessage("You send your pet to attack!");
                    return true;
                } else {
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(null);
                    player.sendMessage("You cannot send your pet to attack itself");
                    return false;
                }
            }
        }
    }
    if (isConsumable == true && isExperienceBonus()) {
        SoliniaPlayerAdapter.Adapt(player).grantExperienceBonusFromItem();
        System.out.println("Granted " + player.getName() + " experience bonus from item [" + SoliniaPlayerAdapter.Adapt(player).getExperienceBonusExpires().toString() + "]");
        return true;
    }
    ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(getAbilityid());
    if (spell == null) {
        return false;
    }
    ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) player);
    if (solentity == null)
        return false;
    if (!isConsumable)
        if (spell.getActSpellCost(solentity) > SoliniaPlayerAdapter.Adapt(player).getMana()) {
            player.sendMessage(ChatColor.GRAY + "Insufficient Mana  [E] (Hold crouch or use /trance to meditate)");
            return false;
        }
    try {
        if (StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId()) != null) {
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp nowtimestamp = Timestamp.valueOf(datetime);
            Timestamp expiretimestamp = StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId());
            if (expiretimestamp != null)
                if (!nowtimestamp.after(expiretimestamp)) {
                    player.sendMessage("You do not have enough willpower to cast " + spell.getName() + " (Wait: " + ((expiretimestamp.getTime() - nowtimestamp.getTime()) / 1000) + "s");
                    return false;
                }
        }
    } catch (CoreStateInitException e) {
        // skip
        return false;
    }
    boolean itemUseSuccess = spell.tryApplyOnEntity(plugin, player, targetentity);
    if (itemUseSuccess) {
        if (spell.getRecastTime() > 0) {
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp expiretimestamp = Timestamp.valueOf(datetime.plus(spell.getRecastTime(), ChronoUnit.MILLIS));
            StateManager.getInstance().getEntityManager().addEntitySpellCooldown(player, spell.getId(), expiretimestamp);
        }
        if (!isConsumable)
            SoliniaPlayerAdapter.Adapt(player).reducePlayerMana(spell.getActSpellCost(solentity));
    }
    return itemUseSuccess;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) LocalDateTime(java.time.LocalDateTime) Creature(org.bukkit.entity.Creature) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) Timestamp(java.sql.Timestamp)

Example 20 with Creature

use of org.bukkit.entity.Creature in project MagicPlugin by elBukkit.

the class MagicMACreature method spawn.

@Nullable
@Override
public LivingEntity spawn(Arena arena, World world, Location loc) {
    loc.setWorld(world);
    Entity entity = entityData.spawn(controller, loc);
    if (!(entity instanceof LivingEntity))
        return null;
    if (entity instanceof Creature) {
        Creature c = (Creature) entity;
        c.setTarget(WaveUtils.getClosestPlayer(arena, entity));
    }
    return (LivingEntity) entity;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MACreature(com.garbagemule.MobArena.waves.MACreature) Creature(org.bukkit.entity.Creature) Nullable(javax.annotation.Nullable)

Aggregations

Creature (org.bukkit.entity.Creature)21 LivingEntity (org.bukkit.entity.LivingEntity)16 Entity (org.bukkit.entity.Entity)15 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)10 Player (org.bukkit.entity.Player)10 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)9 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)6 Timestamp (java.sql.Timestamp)5 ArrayList (java.util.ArrayList)5 CraftCreature (org.bukkit.craftbukkit.v1_12_R1.entity.CraftCreature)4 Location (org.bukkit.Location)3 World (org.bukkit.World)3 Biome (org.bukkit.block.Biome)3 Block (org.bukkit.block.Block)3 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)3 EventHandler (org.bukkit.event.EventHandler)3 ItemStack (org.bukkit.inventory.ItemStack)3 HashMultiset (com.google.common.collect.HashMultiset)2 Multiset (com.google.common.collect.Multiset)2 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2