Fix killing NPCs with bow/arrow. Issue was combination of NPCs counting

as Players, and Quests treating them as mobs. Fixes #102
This commit is contained in:
HappyPikachu 2015-05-20 19:27:26 -04:00
parent a518accd74
commit 36a530f3cf

View File

@ -598,7 +598,17 @@ public class PlayerListener implements Listener, ColorUtil {
@EventHandler
public void onEntityDeath(EntityDeathEvent evt) {
if (evt.getEntity() instanceof Player == false) {
//NPCs count as a Player so we check for them through Citizens
boolean isTargetNPC = false;
if (plugin.citizens != null) {
if (CitizensAPI.getNPCRegistry().isNPC(evt.getEntity())) {
isTargetNPC = true;
}
}
if (evt.getEntity() instanceof Player == false || isTargetNPC) {
if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause();
@ -607,10 +617,10 @@ public class PlayerListener implements Listener, ColorUtil {
if (damager instanceof Projectile) {
Projectile projectile = (Projectile)damager;
@SuppressWarnings("deprecation")
ProjectileSource source = projectile.getShooter();
if (source instanceof Player) {
Player player = (Player) source;
boolean okay = true;
@ -622,6 +632,18 @@ public class PlayerListener implements Listener, ColorUtil {
if (okay) {
if (isTargetNPC) {
Quester quester = plugin.getQuester(player.getUniqueId());
for (Quest quest : quester.currentQuests.keySet()) {
if (quester.hasObjective(quest, "killNPC")) {
quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(evt.getEntity()));
}
}
} else {
Quester quester = plugin.getQuester(player.getUniqueId());
for (Quest quest : quester.currentQuests.keySet()) {
@ -633,6 +655,9 @@ public class PlayerListener implements Listener, ColorUtil {
}
}
}
}
} else if (damager instanceof TNTPrimed) {