Search in sources :

Example 96 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Village_Defense by Plajer.

the class PlayerBuster method damageEntity.

@Override
public boolean damageEntity(DamageSource damagesource, float f) {
    if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER) {
        ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
        Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
        getBukkitEntity().getWorld().spawnEntity(getBukkitEntity().getLocation(), EntityType.PRIMED_TNT);
        this.die();
        return true;
    } else {
        super.damageEntity(damagesource, f);
        return false;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 97 with LivingEntity

use of org.bukkit.entity.LivingEntity in project askyblock by tastybento.

the class Schematic method spawnCompanion.

/**
 * Spawns a random companion for the player with a random name at the location given
 * @param player
 * @param location
 */
protected void spawnCompanion(Player player, Location location) {
    // Bukkit.getLogger().info("DEBUG: spawning compantion at " + location);
    if (!islandCompanion.isEmpty() && location != null) {
        Random rand = new Random();
        int randomNum = rand.nextInt(islandCompanion.size());
        EntityType type = islandCompanion.get(randomNum);
        if (type != null) {
            LivingEntity companion = (LivingEntity) location.getWorld().spawnEntity(location, type);
            if (!companionNames.isEmpty()) {
                randomNum = rand.nextInt(companionNames.size());
                String name = companionNames.get(randomNum).replace("[player]", player.getName());
                // plugin.getLogger().info("DEBUG: name is " + name);
                companion.setCustomName(name);
                companion.setCustomNameVisible(true);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) Random(java.util.Random)

Example 98 with LivingEntity

use of org.bukkit.entity.LivingEntity in project askyblock by tastybento.

the class IslandGuard method onSplashPotionSplash.

/**
 * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them.
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("splash entity = " + e.getEntity());
        plugin.getLogger().info("splash entity type = " + e.getEntityType());
        plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities());
    // plugin.getLogger().info("splash hit entity = " + e.getHitEntity());
    }
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    // Try to get the shooter
    Projectile projectile = (Projectile) e.getEntity();
    if (DEBUG)
        plugin.getLogger().info("splash shooter = " + projectile.getShooter());
    if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
        Player attacker = (Player) projectile.getShooter();
        // Run through all the affected entities
        for (LivingEntity entity : e.getAffectedEntities()) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: affected splash entity = " + entity);
            // Self damage
            if (attacker.equals(entity)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Self damage from splash potion!");
                continue;
            }
            Island island = plugin.getGrid().getIslandAt(entity.getLocation());
            boolean inNether = false;
            if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) {
                inNether = true;
            }
            // Monsters being hurt
            if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
                // Normal island check
                if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
                    // Members always allowed
                    continue;
                }
                if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) {
                    continue;
                }
                // Not allowed
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }
            // Mobs being hurt
            if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) {
                if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
                    continue;
                }
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }
            // Establish whether PVP is allowed or not.
            boolean pvp = false;
            if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: PVP allowed");
                pvp = true;
            }
            // Players being hurt PvP
            if (entity instanceof Player) {
                if (pvp) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: PVP allowed");
                    continue;
                } else {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: PVP not allowed");
                    Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Squid(org.bukkit.entity.Squid) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Snowman(org.bukkit.entity.Snowman) IronGolem(org.bukkit.entity.IronGolem) Slime(org.bukkit.entity.Slime) Island(com.wasteofplastic.askyblock.Island) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 99 with LivingEntity

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

the class Solinia3CoreEntityListener method onEntityDamage.

@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if (event.isCancelled())
        return;
    if (!(event instanceof EntityDamageByEntityEvent)) {
        return;
    }
    EntityDamageByEntityEvent damagecause = (EntityDamageByEntityEvent) event;
    // If the event is being blocked by a shield negate 85% of it unless its thorns then always allow it through
    if (damagecause.getDamage(DamageModifier.BLOCKING) < 0) {
        if (event.getCause().equals(DamageCause.THORNS)) {
            damagecause.setDamage(DamageModifier.BLOCKING, 0);
        } else {
            // Only give them 15% blocking
            double newarmour = (damagecause.getDamage(DamageModifier.BLOCKING) / 100) * 15;
            damagecause.setDamage(DamageModifier.BLOCKING, newarmour);
        }
    }
    // and check they are not mezzed
    try {
        if (damagecause.getDamager() instanceof LivingEntity) {
            LivingEntity attacker = (LivingEntity) damagecause.getDamager();
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) attacker;
                if (arr.getShooter() instanceof LivingEntity) {
                    attacker = (LivingEntity) arr.getShooter();
                } else {
                }
            }
            // cancel attacks on mobs mezzed
            if (attacker instanceof Creature && attacker instanceof LivingEntity && event.getEntity() instanceof LivingEntity) {
                ISoliniaLivingEntity solCreatureEntity = SoliniaLivingEntityAdapter.Adapt(attacker);
                if (solCreatureEntity.isPet() || !solCreatureEntity.isPlayer()) {
                    Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
                    if (mezExpiry != null) {
                        ((Creature) attacker).setTarget(null);
                        if (solCreatureEntity.isPet()) {
                            Wolf wolf = (Wolf) attacker;
                            wolf.setTarget(null);
                            solCreatureEntity.say("Stopping attacking master, the target is mesmerized");
                        }
                        event.setCancelled(true);
                        return;
                    }
                }
            }
            try {
                Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) attacker);
                if (mzExpiry != null) {
                    if (attacker instanceof Player) {
                        attacker.sendMessage("* You are mezzed!");
                    }
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            } catch (CoreStateInitException e) {
            }
            List<Integer> removeSpells = new ArrayList<Integer>();
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) attacker).getActiveSpells()) {
                if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
                    if (!removeSpells.contains(spell.getSpell().getId()))
                        removeSpells.add(spell.getSpell().getId());
                }
            }
            for (Integer spellId : removeSpells) {
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) attacker).getUniqueId(), spellId);
            }
        }
    } catch (CoreStateInitException e) {
    // skip
    }
    // Remove buffs on recipient (invis should drop)
    try {
        if (event.getEntity() instanceof LivingEntity) {
            List<Integer> removeSpells = new ArrayList<Integer>();
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) event.getEntity()).getActiveSpells()) {
                if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
                    if (!removeSpells.contains(spell.getSpell().getId()))
                        removeSpells.add(spell.getSpell().getId());
                }
            }
            for (Integer spellId : removeSpells) {
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) event.getEntity()).getUniqueId(), spellId);
            }
        }
        // Check for rune damage
        if (event.getEntity() instanceof LivingEntity) {
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            if (soldefender.isInvulnerable()) {
                event.setDamage(0);
                Utils.CancelEvent(event);
                ;
                if (damagecause.getDamager() instanceof Player) {
                    ((Player) damagecause.getDamager()).sendMessage("* Your attack was prevented as the target is Invulnerable!");
                }
                if (event.getEntity() instanceof Player) {
                    ((Player) event.getEntity()).sendMessage("* Your invulnerability prevented the targets attack!");
                }
            }
        }
        // see if any runes want to reduce this damage
        if (event.getEntity() instanceof LivingEntity) {
            if (!event.getCause().equals(DamageCause.THORNS)) {
                ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                event.setDamage(Utils.reduceDamage(soldefender, event.getDamage()));
            }
        }
        // Check for rune damage
        if (event.getEntity() instanceof LivingEntity) {
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            if (soldefender.getRune() > 0) {
                event.setDamage(soldefender.reduceAndRemoveRunesAndReturnLeftover(plugin, (int) event.getDamage()));
                if (event.getDamage() <= 0) {
                    Utils.CancelEvent(event);
                    ;
                    if (damagecause.getDamager() instanceof Player) {
                        ((Player) damagecause.getDamager()).sendMessage("* Your attack was absorbed by the targets Rune");
                    }
                    if (event.getEntity() instanceof Player) {
                        ((Player) event.getEntity()).sendMessage("* Your rune spell absorbed the targets attack!");
                    }
                    return;
                }
            }
        }
    } catch (CoreStateInitException e) {
    // skip
    }
    if ((damagecause.getDamager() instanceof LivingEntity || damagecause.getDamager() instanceof Arrow) && event.getEntity() instanceof LivingEntity) {
        // code
        if (event.getCause().equals(DamageCause.THORNS)) {
            if (damagecause.getDamager() instanceof Player) {
                LivingEntity recipient = (LivingEntity) event.getEntity();
                DecimalFormat df = new DecimalFormat();
                df.setMaximumFractionDigits(2);
                String name = recipient.getName();
                if (recipient.getCustomName() != null)
                    name = recipient.getCustomName();
                ((Player) damagecause.getDamager()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You SPELLDMG'd " + name + " for " + df.format(event.getDamage()) + " [" + df.format(recipient.getHealth() - event.getDamage()) + "/" + df.format(recipient.getMaxHealth()) + "]"));
            }
            if (event.getEntity() instanceof LivingEntity) {
                ISoliniaLivingEntity solentity;
                try {
                    solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                    if (event.getDamage() > solentity.getBukkitLivingEntity().getHealth() && solentity.hasDeathSave() > 0) {
                        Utils.CancelEvent(event);
                        solentity.removeDeathSaves(plugin);
                        solentity.getBukkitLivingEntity().sendMessage("* Your death/divine save boon has saved you from death!");
                        return;
                    }
                    solentity.damageHook(event.getDamage(), damagecause.getDamager());
                } catch (CoreStateInitException e) {
                // skip
                }
            }
            return;
        }
        try {
            Entity damager = damagecause.getDamager();
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) damagecause.getDamager();
                if (arr.getShooter() instanceof LivingEntity) {
                    damager = (LivingEntity) arr.getShooter();
                    // Modify Player Bow Damage
                    if (arr.getShooter() instanceof Player) {
                        Player shooter = (Player) arr.getShooter();
                        ItemStack mainitem = shooter.getInventory().getItemInMainHand();
                        if (mainitem != null) {
                            if (mainitem.getType() == Material.BOW) {
                                int dmgmodifier = 0;
                                if (Utils.IsSoliniaItem(mainitem)) {
                                    try {
                                        ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
                                        if (item.getDamage() > 0 && item.getBasename().equals("BOW")) {
                                            dmgmodifier = item.getDamage();
                                        }
                                    } catch (SoliniaItemException e) {
                                    // sok just skip
                                    }
                                }
                                event.setDamage(event.getDamage() + dmgmodifier);
                            }
                        }
                    }
                } else {
                }
            }
            if (!(damager instanceof LivingEntity))
                return;
            LivingEntity attacker = (LivingEntity) damager;
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) damagecause.getDamager();
                if (arr.getShooter() instanceof LivingEntity) {
                    attacker = (LivingEntity) arr.getShooter();
                } else {
                }
            }
            if (attacker == null)
                return;
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            ISoliniaLivingEntity solattacker = SoliniaLivingEntityAdapter.Adapt((LivingEntity) attacker);
            if (attacker instanceof Player && event.getEntity() instanceof Wolf) {
                if (soldefender.isPet()) {
                    Wolf wolf = (Wolf) event.getEntity();
                    if (wolf != null) {
                        if (wolf.getTarget() == null || !wolf.getTarget().equals(attacker)) {
                            Utils.CancelEvent(event);
                            ;
                            return;
                        }
                    } else {
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                }
            }
            if (!(event instanceof EntityDamageByEntityEvent)) {
                soldefender.damageHook(event.getDamage(), damagecause.getDamager());
                return;
            }
            solattacker.Attack(soldefender, event, damagecause.getDamager() instanceof Arrow, plugin);
        } catch (CoreStateInitException e) {
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ItemStack(org.bukkit.inventory.ItemStack) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell) EventHandler(org.bukkit.event.EventHandler)

Example 100 with LivingEntity

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

the class Solinia3CoreEntityListener method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    if ((event.getEntity() instanceof ArmorStand)) {
        return;
    }
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    if (event.getEntity() instanceof Player)
        return;
    if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
        return;
    if (event.getEntity() instanceof Animals && !Utils.isLivingEntityNPC((LivingEntity) event.getEntity()))
        return;
    EntityDamageByEntityEvent entitykiller = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
    Entity damager = entitykiller.getDamager();
    if (damager instanceof Projectile) {
        Projectile projectile = (Projectile) damager;
        damager = (Entity) projectile.getShooter();
    }
    if (!(damager instanceof LivingEntity))
        return;
    ISoliniaLivingEntity soldamagerentity = null;
    try {
        soldamagerentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) damager);
    } catch (CoreStateInitException e) {
    }
    // something
    if ((!(damager instanceof Player)) && Utils.isLivingEntityNPC((LivingEntity) damager)) {
        soldamagerentity.doSlayChat();
    }
    if (!(damager instanceof Player) && !soldamagerentity.isPet())
        return;
    try {
        ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt(event.getEntity());
        ISoliniaPlayer player = null;
        if (damager instanceof Player) {
            player = SoliniaPlayerAdapter.Adapt((Player) damager);
        }
        if (soldamagerentity.isPet()) {
            if (damager instanceof Wolf) {
                Wolf w = (Wolf) damager;
                player = SoliniaPlayerAdapter.Adapt((Player) w.getOwner());
            }
        }
        if (player == null) {
            return;
        }
        Double experience = Utils.getExperienceRewardAverageForLevel(livingEntity.getLevel());
        // try to share with group
        ISoliniaGroup group = StateManager.getInstance().getGroupByMember(player.getUUID());
        if (group != null) {
            Integer dhighestlevel = 0;
            List<Integer> levelranges = new ArrayList<Integer>();
            for (UUID member : group.getMembers()) {
                ISoliniaPlayer playerchecked = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(member));
                int checkedlevel = playerchecked.getLevel();
                levelranges.add(checkedlevel);
            }
            Collections.sort(levelranges);
            // get the highest person in the group
            dhighestlevel = levelranges.get(levelranges.size() - 1);
            int ihighlvl = (int) Math.floor(dhighestlevel);
            int ilowlvl = ihighlvl - 7;
            if (ilowlvl < 1) {
                ilowlvl = 1;
            }
            if (player.getLevel() < ilowlvl) {
                // as they are out of range of the group
                if (livingEntity.getLevel() >= player.getLevel() - 7) {
                    player.increasePlayerExperience(experience);
                    // Grant title for killing mob
                    if (livingEntity.getNpcid() > 0) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                        if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                            player.grantTitle(npc.getDeathGrantsTitle());
                        }
                        if (npc.isBoss() || npc.isRaidboss()) {
                            player.grantTitle("the Vanquisher");
                        }
                    }
                } else {
                    player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                }
            } else {
                for (UUID member : group.getMembers()) {
                    Player tgtplayer = Bukkit.getPlayer(member);
                    if (tgtplayer != null) {
                        ISoliniaPlayer tgtsolplayer = SoliniaPlayerAdapter.Adapt(tgtplayer);
                        int tgtlevel = tgtsolplayer.getLevel();
                        if (tgtlevel < ilowlvl) {
                            tgtplayer.sendMessage("You were out of level range to gain experience in this group (Min: " + ilowlvl + " Max: " + ihighlvl + ")");
                            continue;
                        }
                        if (!tgtplayer.getWorld().equals(player.getBukkitPlayer().getWorld())) {
                            tgtplayer.sendMessage("You were out of range for shared group xp (world)");
                            continue;
                        }
                        if (tgtplayer.getLocation().distance(player.getBukkitPlayer().getLocation()) <= 100) {
                            if (livingEntity.getLevel() >= (tgtsolplayer.getLevel() - 7)) {
                                tgtsolplayer.increasePlayerExperience(experience);
                                // Grant title for killing mob
                                if (livingEntity.getNpcid() > 0) {
                                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                                        tgtsolplayer.grantTitle(npc.getDeathGrantsTitle());
                                    }
                                    if (npc.isBoss() || npc.isRaidboss()) {
                                        tgtsolplayer.grantTitle("the Vanquisher");
                                    }
                                }
                            } else {
                                tgtplayer.sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                            }
                        } else {
                            tgtplayer.sendMessage("You were out of range for shared group xp (distance)");
                            continue;
                        }
                    }
                }
            }
        } else {
            if (livingEntity.getLevel() >= (player.getLevel() - 7)) {
                player.increasePlayerExperience(experience);
                // Grant title for killing mob
                if (livingEntity.getNpcid() > 0) {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                        player.grantTitle(npc.getDeathGrantsTitle());
                    }
                    if (npc.isBoss() || npc.isRaidboss()) {
                        player.grantTitle("the Vanquisher");
                    }
                }
            } else {
                player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc.getFactionid() > 0) {
                ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
                player.decreaseFactionStanding(npc.getFactionid(), 50);
                for (FactionStandingEntry factionEntry : faction.getFactionEntries()) {
                    if (factionEntry.getValue() >= 1500) {
                        // If this is an ally of the faction, grant negative faction
                        player.decreaseFactionStanding(factionEntry.getFactionId(), 10);
                    }
                    if (factionEntry.getValue() <= -1500) {
                        // If this is an enemy of the faction, grant positive faction
                        player.increaseFactionStanding(factionEntry.getFactionId(), 1);
                    }
                }
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                player.grantTitle(npc.getDeathGrantsTitle());
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                player.grantTitle("the Vanquisher");
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                Bukkit.broadcastMessage(ChatColor.RED + "[VICTORY] The foundations of the earth shake following the destruction of " + npc.getName() + " at the hands of " + player.getFullNameWithTitle() + "!" + ChatColor.RESET);
            }
        }
        player.giveMoney(1);
        livingEntity.dropLoot();
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) FactionStandingEntry(com.solinia.solinia.Models.FactionStandingEntry) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ArrayList(java.util.ArrayList) Projectile(org.bukkit.entity.Projectile) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Animals(org.bukkit.entity.Animals) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Wolf(org.bukkit.entity.Wolf) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)322 Entity (org.bukkit.entity.Entity)169 Player (org.bukkit.entity.Player)121 Location (org.bukkit.Location)71 EventHandler (org.bukkit.event.EventHandler)63 Vector (org.bukkit.util.Vector)60 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)41 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)37 PotionEffect (org.bukkit.potion.PotionEffect)34 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)30 Block (org.bukkit.block.Block)24 Mage (com.elmakers.mine.bukkit.api.magic.Mage)22 Projectile (org.bukkit.entity.Projectile)20 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)17 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)16 Target (com.elmakers.mine.bukkit.utility.Target)15 World (org.bukkit.World)14 Creature (org.bukkit.entity.Creature)14