Search in sources :

Example 1 with FactionStandingEntry

use of com.solinia.solinia.Models.FactionStandingEntry 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

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)1 ISoliniaGroup (com.solinia.solinia.Interfaces.ISoliniaGroup)1 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 FactionStandingEntry (com.solinia.solinia.Models.FactionStandingEntry)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Animals (org.bukkit.entity.Animals)1 ArmorStand (org.bukkit.entity.ArmorStand)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1 Projectile (org.bukkit.entity.Projectile)1 Wolf (org.bukkit.entity.Wolf)1 EventHandler (org.bukkit.event.EventHandler)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1