mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-08 09:27:56 +01:00
Fix double count for kill-NPC objectives
This commit is contained in:
parent
6a2c5eabe2
commit
2237e58960
@ -14,8 +14,10 @@ package me.blackvein.quests.listeners;
|
|||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -37,7 +39,6 @@ import me.blackvein.quests.Quests;
|
|||||||
import me.blackvein.quests.enums.ObjectiveType;
|
import me.blackvein.quests.enums.ObjectiveType;
|
||||||
import me.blackvein.quests.util.ItemUtil;
|
import me.blackvein.quests.util.ItemUtil;
|
||||||
import me.blackvein.quests.util.Lang;
|
import me.blackvein.quests.util.Lang;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
|
||||||
import net.citizensnpcs.api.event.NPCDeathEvent;
|
import net.citizensnpcs.api.event.NPCDeathEvent;
|
||||||
import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
||||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||||
@ -282,40 +283,37 @@ public class NpcListener implements Listener {
|
|||||||
= (EntityDamageByEntityEvent) evt.getNPC().getEntity().getLastDamageCause();
|
= (EntityDamageByEntityEvent) evt.getNPC().getEntity().getLastDamageCause();
|
||||||
final Entity damager = damageEvent.getDamager();
|
final Entity damager = damageEvent.getDamager();
|
||||||
if (damager != null) {
|
if (damager != null) {
|
||||||
|
if (plugin.getDependencies().getCitizens().getNPCRegistry().isNPC(damager)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final ObjectiveType type = ObjectiveType.KILL_NPC;
|
final ObjectiveType type = ObjectiveType.KILL_NPC;
|
||||||
if (damager instanceof Projectile) {
|
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||||
if (evt.getNPC().getEntity().getLastDamageCause().getEntity() instanceof Player) {
|
Player player = null;
|
||||||
final Player player = (Player) evt.getNPC().getEntity().getLastDamageCause().getEntity();
|
if (damager instanceof Projectile
|
||||||
boolean okay = true;
|
&& evt.getNPC().getEntity().getLastDamageCause().getEntity() instanceof Player) {
|
||||||
if (plugin.getDependencies().getCitizens() != null) {
|
player = (Player) evt.getNPC().getEntity().getLastDamageCause().getEntity();
|
||||||
if (CitizensAPI.getNPCRegistry().isNPC(player)) {
|
|
||||||
okay = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (okay) {
|
|
||||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
|
||||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
|
||||||
if (quester.getCurrentStage(quest).containsObjective(type)) {
|
|
||||||
quester.killNPC(quest, evt.getNPC());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (damager instanceof Player) {
|
} else if (damager instanceof Player) {
|
||||||
boolean okay = true;
|
player = (Player) damager;
|
||||||
if (plugin.getDependencies().getCitizens() != null) {
|
}
|
||||||
if (plugin.getDependencies().getCitizens().getNPCRegistry().isNPC(damager)) {
|
if (player != null) {
|
||||||
okay = false;
|
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||||
|
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||||
|
if (!quester.meetsCondition(quest, true)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (okay) {
|
if (quester.getCurrentQuests().containsKey(quest)
|
||||||
final Player player = (Player) damager;
|
&& quester.getCurrentStage(quest).containsObjective(type)) {
|
||||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
quester.killNPC(quest, evt.getNPC());
|
||||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
}
|
||||||
if (quester.getCurrentStage(quest).containsObjective(type)) {
|
|
||||||
quester.killNPC(quest, evt.getNPC());
|
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
|
||||||
|
(final Quester q, final Quest cq) -> {
|
||||||
|
if (!dispatchedQuestIDs.contains(cq.getId())) {
|
||||||
|
q.killNPC(cq, evt.getNPC());
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -632,49 +632,29 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (damager instanceof Player) {
|
if (damager instanceof Player) {
|
||||||
final Quester quester = plugin.getQuester(damager.getUniqueId());
|
|
||||||
if (plugin.getDependencies().getCitizens() != null && CitizensAPI.getNPCRegistry().isNPC(target)) {
|
if (plugin.getDependencies().getCitizens() != null && CitizensAPI.getNPCRegistry().isNPC(target)) {
|
||||||
final ObjectiveType type = ObjectiveType.KILL_NPC;
|
return;
|
||||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
}
|
||||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
final Quester quester = plugin.getQuester(damager.getUniqueId());
|
||||||
if (!quester.meetsCondition(quest, true)) {
|
final ObjectiveType type = ObjectiveType.KILL_MOB;
|
||||||
continue;
|
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||||
}
|
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||||
|
if (!quester.meetsCondition(quest, true)) {
|
||||||
if (quester.getCurrentQuests().containsKey(quest)
|
continue;
|
||||||
&& quester.getCurrentStage(quest).containsObjective(type)) {
|
|
||||||
quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target));
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
|
|
||||||
(final Quester q, final Quest cq) -> {
|
|
||||||
if (!dispatchedQuestIDs.contains(cq.getId())) {
|
|
||||||
q.killNPC(cq, CitizensAPI.getNPCRegistry().getNPC(target));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
final ObjectiveType type = ObjectiveType.KILL_MOB;
|
if (quester.getCurrentQuests().containsKey(quest)
|
||||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
&& quester.getCurrentStage(quest).containsObjective(type)) {
|
||||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
quester.killMob(quest, target.getLocation(), target.getType());
|
||||||
if (!quester.meetsCondition(quest, true)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quester.getCurrentQuests().containsKey(quest)
|
|
||||||
&& quester.getCurrentStage(quest).containsObjective(type)) {
|
|
||||||
quester.killMob(quest, target.getLocation(), target.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
|
|
||||||
(final Quester q, final Quest cq) -> {
|
|
||||||
if (!dispatchedQuestIDs.contains(cq.getId())) {
|
|
||||||
q.killMob(cq, target.getLocation(), target.getType());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
|
||||||
|
(final Quester q, final Quest cq) -> {
|
||||||
|
if (!dispatchedQuestIDs.contains(cq.getId())) {
|
||||||
|
q.killMob(cq, target.getLocation(), target.getType());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user