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;
}
/**
* 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
*
* @param uuid the entity UUID to be checked
* @return {@code true} if entity has no permission or is not a player
* @deprecated Use #canUseQuests
*/
public boolean checkQuester(UUID uuid) {
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 target the entity being attacked
@ -713,15 +713,16 @@ 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 player AND not an NPC...
if (target instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(target)) {
Quester quester = plugin.getQuester(damager.getUniqueId());
for (Quest quest : quester.getCurrentQuests().keySet()) {
if (quester.containsObjective(quest, "killPlayer")) {
quester.killPlayer(quest, (Player)target);
}
if (damager instanceof Player && target instanceof Player) {
if (plugin.getDependencies().getCitizens() != null) {
if (CitizensAPI.getNPCRegistry().isNPC(damager) && CitizensAPI.getNPCRegistry().isNPC(target)) {
return;
}
}
Quester quester = plugin.getQuester(damager.getUniqueId());
for (Quest quest : quester.getCurrentQuests().keySet()) {
if (quester.containsObjective(quest, "killPlayer")) {
quester.killPlayer(quest, (Player)target);
}
}
}