Check for Citizens prior to player death, fixes #886

This commit is contained in:
PikaMug 2019-07-31 12:46:31 -04:00
parent b1a42e4426
commit 1e29ad1436
2 changed files with 22 additions and 10 deletions

View File

@ -3280,11 +3280,22 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return false; return false;
} }
/**
* Checks if player can use Quests
*
* @param uuid the entity UUID to be checked
* @return {@code true} if entity is a Player that has permission
*/
public boolean canUseQuests(UUID uuid) {
return !checkQuester(uuid);
}
/** /**
* Checks if player CANNOT use Quests * Checks if player CANNOT use Quests
* *
* @param uuid the entity UUID to be checked * @param uuid the entity UUID to be checked
* @return {@code true} if entity has no permission or is not a player * @return {@code true} if entity has no permission or is not a player
* @deprecated Use #canUseQuests
*/ */
public boolean checkQuester(UUID uuid) { public boolean checkQuester(UUID uuid) {
if (!(Bukkit.getPlayer(uuid) instanceof Player)) { if (!(Bukkit.getPlayer(uuid) instanceof Player)) {

View File

@ -703,7 +703,7 @@ public class PlayerListener implements Listener {
} }
/** /**
* Checks if damager is blacklisted. Ensures damager is Player and not NPC. Kills target Player if objective exists * Checks if damager is blacklisted. Ensures damager and target are Player and not NPC. Kills target Player if objective exists
* *
* @param damager the attacking entity * @param damager the attacking entity
* @param target the entity being attacked * @param target the entity being attacked
@ -713,10 +713,12 @@ public class PlayerListener implements Listener {
if (plugin.checkQuester(damager.getUniqueId()) == true) { if (plugin.checkQuester(damager.getUniqueId()) == true) {
return; return;
} }
//Ensure damager is player AND not an NPC if (damager instanceof Player && target instanceof Player) {
if (damager instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(damager)) { if (plugin.getDependencies().getCitizens() != null) {
//If target is player AND not an NPC... if (CitizensAPI.getNPCRegistry().isNPC(damager) && CitizensAPI.getNPCRegistry().isNPC(target)) {
if (target instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(target)) { return;
}
}
Quester quester = plugin.getQuester(damager.getUniqueId()); Quester quester = plugin.getQuester(damager.getUniqueId());
for (Quest quest : quester.getCurrentQuests().keySet()) { for (Quest quest : quester.getCurrentQuests().keySet()) {
if (quester.containsObjective(quest, "killPlayer")) { if (quester.containsObjective(quest, "killPlayer")) {
@ -725,7 +727,6 @@ public class PlayerListener implements Listener {
} }
} }
} }
}
@EventHandler @EventHandler
public void onPlayerFish(PlayerFishEvent evt) { public void onPlayerFish(PlayerFishEvent evt) {