Improved error for null stage on block objective, fixes #1739

This commit is contained in:
PikaMug 2021-07-11 01:50:37 -04:00
parent a89da8920c
commit 95c8da0590

View File

@ -12,9 +12,15 @@
package me.blackvein.quests.listeners;
import java.util.HashSet;
import java.util.Set;
import me.blackvein.quests.Objective;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.enums.ObjectiveType;
import me.blackvein.quests.events.quester.QuesterPostUpdateObjectiveEvent;
import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -30,15 +36,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.Objective;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.enums.ObjectiveType;
import me.blackvein.quests.events.quester.QuesterPostUpdateObjectiveEvent;
import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import java.util.HashSet;
import java.util.Set;
public class BlockListener implements Listener {
@ -63,12 +62,17 @@ public class BlockListener implements Listener {
final Set<String> dispatchedPlaceQuestIDs = new HashSet<String>();
final Set<String> dispatchedCutQuestIDs = new HashSet<String>();
for (final Quest quest : plugin.getLoadedQuests()) {
if (evt.isCancelled() == false) {
if (!evt.isCancelled()) {
if (!quester.meetsCondition(quest, true)) {
continue;
}
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(breakType)) {
if (quester.getCurrentQuests().containsKey(quest)) {
if (quester.getCurrentStage(quest) == null) {
plugin.getLogger().severe("Player " + player.getName() + " (" + player.getUniqueId()
+ ") has invalid stage for quest " + quest.getName() + " (" + quest.getId() + ")");
continue;
}
if (quester.getCurrentStage(quest).containsObjective(breakType)) {
if (quest.getOptions().canIgnoreSilkTouch()
&& player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
player.sendMessage(ChatColor.RED + Lang.get(player, "optionSilkTouchFail")
@ -86,9 +90,7 @@ public class BlockListener implements Listener {
}));
}
}
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(placeType)) {
if (quester.getCurrentStage(quest).containsObjective(placeType)) {
for (final ItemStack is : quester.getQuestData(quest).blocksPlaced) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
ItemStack toPlace = new ItemStack(is.getType(), 64);
@ -146,8 +148,7 @@ public class BlockListener implements Listener {
}
return null;
}));
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(cutType)) {
if (quester.getCurrentStage(quest).containsObjective(cutType)) {
if (player.getItemInHand().getType().equals(Material.SHEARS)) {
quester.cutBlock(quest, blockItemStack);
}
@ -165,6 +166,7 @@ public class BlockListener implements Listener {
}
}
}
}
@SuppressWarnings("deprecation") // since 1.13
@EventHandler