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();
}
}
Aggregations