private void handleNpeDeath(Entity subject) { EntityDamageEvent cause = subject.getLastDamageCause(); // Increment the NPE's total death stat NpeData npeData = this.plugin.getNpeDataByClass(subject.getClass()); npeData.incTotalDeaths(); // Increment the ServerData statistics plugin.serverData.incNpesKilled(); if (cause instanceof EntityDamageByEntityEvent) { Entity predicate = ((EntityDamageByEntityEvent) cause).getDamager(); if (predicate instanceof Player) { // The NPE was killed by a player, reward them for their accomplishments PlayerData killerData = this.plugin.getPlayerData(((Player) predicate).getName(), ""); String mobName = this.plugin.getSimpleClassName(subject.getClass()).toLowerCase(); if (mobName.startsWith("craft")) { // it looks like a lot of the class names follow the format "CraftX", such as "CraftWolf" // or "CraftCreeper" mobName = mobName.substring(5); } if (killerData.getMobsKilled().containsKey(mobName)) { killerData.incMobsKilled(mobName); } else { plugin.log.info("MineJMX: A player killed an unknown mob type (\"" + mobName + "\")"); } // and increment the NPE's specific death stat npeData.incDeathsByPlayer(); } else { // The NPE was killed by another mob, increment NpeData statistics again NpeData killerData = this.plugin.getNpeDataByClass(predicate.getClass()); killerData.incNpesKilled(); // and increment the original NPE's specific death stat npeData.incDeathsByNpe(); } } else if (cause instanceof EntityDamageByBlockEvent) { // killed by environment, increment the specific death counter npeData.incDeathsByEnvironment(); } else { // drowned, burned, fell, etc...increment the environmental death counter switch (cause.getCause()) { case CONTACT: case DROWNING: case FALL: case FIRE: case FIRE_TICK: case LAVA: case LIGHTNING: npeData.incDeathsByEnvironment(); break; } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { // TODO: use get getLastDamageCause rather than checking on each // getdamage? Log.logInfo( "*** OnEntityDeath, before checks (victim: " + event.getEntity().toString() + ")", HIGHEST); Entity entity = event.getEntity(); // If there's no damage record, ignore if (entity.getLastDamageCause() == null) { Log.logWarning( "OnEntityDeath: entity " + entity.toString() + " has no 'lastDamageCause'.", HIGH); return; } OccurredEvent drop = new OccurredEvent(event); Log.logInfo("EntityDeath drop occurance created. (" + drop.toString() + ")", HIGHEST); parent.sectionManager.performDrop(drop); }
public MCEntityDamageEvent getLastDamageCause() { return new BukkitEntityEvents.BukkitMCEntityDamageEvent(e.getLastDamageCause()); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { Entity victimEntity = event.getEntity(); EntityDamageEvent lastDamageEvent = victimEntity.getLastDamageCause(); if (lastDamageEvent == null) return; if (victimEntity instanceof Player) { Player victim = (Player) victimEntity; if (Util.isExempt(victim)) return; if (lastDamageEvent instanceof EntityDamageByEntityEvent) { // + Player killed by entity Entity killerEntity = ((EntityDamageByEntityEvent) lastDamageEvent).getDamager(); if (killerEntity instanceof Arrow) { // | + Victim was shot Arrow arrow = (Arrow) killerEntity; if (arrow.getShooter() instanceof Player) { // | | + Player shot Player Player killer = (Player) arrow.getShooter(); if (Util.isExempt(killer)) return; VaultHook.transfer(victim, killer, Util.getPVPAmount(victim)); Message.send( killer, Settings.Message.KilledPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", victim.getPlayerListName())); Message.send( victim, Settings.Message.KilledByPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", killer.getPlayerListName())); } else if (arrow.getShooter() instanceof Creature) { // | | + Creature shot Player VaultHook.withdraw(victim, Util.getPVELoss(victim)); } } else if (killerEntity instanceof Player) { // | + Player killed Player Player killer = (Player) killerEntity; if (Util.isExempt(killer)) return; VaultHook.transfer(victim, killer, Util.getPVPAmount(victim)); Message.send( killer, Settings.Message.KilledPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", victim.getPlayerListName())); Message.send( victim, Settings.Message.KilledByPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", killer.getPlayerListName())); } else if (killerEntity instanceof Explosive) { // | + Player exploded VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } else if (killerEntity instanceof Creature) { // | + Creature killed Player VaultHook.withdraw(victim, Util.getPVELoss(victim)); Message.send( victim, Settings.Message.KilledByMob.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else if (killerEntity instanceof Slime) { // | + Slime killed player VaultHook.withdraw(victim, Util.getPVELoss(victim)); Message.send( victim, Settings.Message.KilledByMob.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else { // | + Player died VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } } else if (lastDamageEvent instanceof EntityDamageByBlockEvent) { // + Player killed by blocks VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } else { // + Player died VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } } else { if (!(lastDamageEvent instanceof EntityDamageByEntityEvent)) return; Entity killerEntity = ((EntityDamageByEntityEvent) lastDamageEvent).getDamager(); if (killerEntity instanceof Arrow) { // + Player shot an entity Arrow arrow = (Arrow) killerEntity; if (!(arrow.getShooter() instanceof Player)) return; Player killer = (Player) arrow.getShooter(); if (victimEntity instanceof Creature) { // | + Player shot Creature Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else if (victimEntity instanceof Slime) { // | + Player shot Slime Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } } else if (killerEntity instanceof Player) { // + Player killed an entity Player killer = (Player) killerEntity; if (victimEntity instanceof Creature) { // | + Player killed Creature Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else if (victimEntity instanceof Slime) { // | + Player killed Slime Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } } } }