From e0146970106f090a3efb17e74dfa566a5edb8381 Mon Sep 17 00:00:00 2001 From: HappyPikachu Date: Wed, 7 Feb 2018 13:10:42 -0500 Subject: [PATCH] Check whether Citizens is loaded for Kill Mobs, fixes #267 --- .../me/blackvein/quests/PlayerListener.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/blackvein/quests/PlayerListener.java b/src/main/java/me/blackvein/quests/PlayerListener.java index 95a750a8e..83c977e43 100644 --- a/src/main/java/me/blackvein/quests/PlayerListener.java +++ b/src/main/java/me/blackvein/quests/PlayerListener.java @@ -479,8 +479,8 @@ public class PlayerListener implements Listener { } /** - * Checks if damager is blacklisted - * Ensures damager is Player and not NPC + * Checks if damager is blacklisted. + * Ensures damager is Player and not NPC. * Kills target mob/NPC if objective exists * * @param damager the attacking entity @@ -491,23 +491,22 @@ public class PlayerListener implements Listener { if (plugin.checkQuester(damager.getUniqueId()) == true) { return; } - //Ensure damager is Player AND not an NPC - if (damager instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(damager)) { - //If target is an NPC... - if (CitizensAPI.getNPCRegistry().isNPC(target)) { - Quester quester = plugin.getQuester(damager.getUniqueId()); - for (Quest quest : quester.currentQuests.keySet()) { - if (quester.hasObjective(quest, "killNPC")) { - quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + if (damager instanceof Player) { + if (plugin.citizens != null) { + if (CitizensAPI.getNPCRegistry().isNPC(target)) { + Quester quester = plugin.getQuester(damager.getUniqueId()); + for (Quest quest : quester.currentQuests.keySet()) { + if (quester.hasObjective(quest, "killNPC")) { + quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + } } + return; } - //No? Must be a mob... - } else { - Quester quester = plugin.getQuester(damager.getUniqueId()); - for (Quest quest : quester.currentQuests.keySet()) { - if (quester.hasObjective(quest, "killMob")) { - quester.killMob(quest, target.getLocation(), target.getType()); - } + } + Quester quester = plugin.getQuester(damager.getUniqueId()); + for (Quest quest : quester.currentQuests.keySet()) { + if (quester.hasObjective(quest, "killMob")) { + quester.killMob(quest, target.getLocation(), target.getType()); } } }