diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index bc264fcd2..819e6314a 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -37,6 +38,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.conversations.Conversable; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -47,8 +49,11 @@ import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.ItemMeta; import com.alessiodp.parties.api.interfaces.Party; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; import de.erethon.dungeonsxl.player.DGroup; +import me.blackvein.quests.events.quest.QuestTakeEvent; import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent; import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent; import me.blackvein.quests.timers.StageTimer; @@ -56,6 +61,7 @@ import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.LocaleQuery; import me.blackvein.quests.util.MiscUtil; +import me.blackvein.quests.util.WorldGuardAPI; import net.citizensnpcs.api.npc.NPC; public class Quester { @@ -387,7 +393,13 @@ public class Quester { inv.setItem(index, stack); } } - + + /** + * Start a quest for this Quester + * + * @param q The quest to start + * @param override Whether to ignore Requirements + */ public void takeQuest(Quest q, boolean override) { if (q == null) { return; @@ -2843,7 +2855,12 @@ public class Quester { } return completedQuests.isEmpty() == false; } - + + /** + * Check whether the provided quest is valid and, if not, inform the Quester + * + * @param quest The quest to check + */ public void checkQuest(Quest quest) { if (quest != null) { boolean exists = false; @@ -3043,6 +3060,102 @@ public class Quester { return null; } + /** + * Check if quest is available and, if so, ask Quester if they would like to start it

+ * + * @param quest The quest to check an then offer + * @param giveReason Whether to inform player of unavailability + * @return true if successful + */ + public boolean offerQuest(Quest quest, boolean giveReason) { + if (quest == null) { + return false; + } + Player player = this.getPlayer(); + QuestTakeEvent event = new QuestTakeEvent(quest, this); + plugin.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } + if (getCurrentQuests().size() >= plugin.getSettings().getMaxQuests() && plugin.getSettings().getMaxQuests() > 0) { + if (giveReason) { + String msg = Lang.get(player, "questMaxAllowed"); + msg = msg.replace("", String.valueOf(plugin.getSettings().getMaxQuests())); + player.sendMessage(ChatColor.YELLOW + msg); + } + } else if (getCurrentQuests().containsKey(quest)) { + if (giveReason) { + String msg = Lang.get(player, "questAlreadyOn"); + player.sendMessage(ChatColor.YELLOW + msg); + } + } else if (getCompletedQuests().contains(quest.getName()) && quest.getPlanner().getCooldown() < 0) { + if (giveReason) { + String msg = Lang.get(player, "questAlreadyCompleted"); + msg = msg.replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW); + player.sendMessage(ChatColor.YELLOW + msg); + } + } else if (quest.getNpcStart() != null && plugin.getSettings().canAllowCommandsForNpcQuests() == false) { + if (giveReason) { + String msg = Lang.get(player, "mustSpeakTo"); + msg = msg.replace("", ChatColor.DARK_PURPLE + quest.getNpcStart().getName() + ChatColor.YELLOW); + player.sendMessage(ChatColor.YELLOW + msg); + } + } else if (quest.getBlockStart() != null) { + if (giveReason) { + String msg = Lang.get(player, "noCommandStart"); + msg = msg.replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW); + player.sendMessage(ChatColor.YELLOW + msg); + } + } else if (getCompletedQuests().contains(quest.getName()) && getCooldownDifference(quest) > 0) { + if (giveReason) { + String msg = Lang.get(player, "questTooEarly"); + msg = msg.replace("", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW); + msg = msg.replace("