getMultiplayerQuesters(final IQuest quest);
- boolean offerQuest(final IQuest quest, final boolean giveReason);
-
- boolean canAcceptOffer(final IQuest quest, final boolean giveReason);
-
boolean meetsCondition(final IQuest quest, final boolean giveReason);
boolean isSelectingBlock();
diff --git a/core/src/main/java/me/blackvein/quests/Quester.java b/core/src/main/java/me/blackvein/quests/Quester.java
index 960d40668..ec5778a1b 100644
--- a/core/src/main/java/me/blackvein/quests/Quester.java
+++ b/core/src/main/java/me/blackvein/quests/Quester.java
@@ -17,7 +17,10 @@ import com.alessiodp.parties.api.interfaces.PartyPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager;
import me.blackvein.quests.conditions.ICondition;
+import me.blackvein.quests.config.ISettings;
+import me.blackvein.quests.convo.misc.QuestAbandonPrompt;
import me.blackvein.quests.dependencies.IDependencies;
+import me.blackvein.quests.events.quest.QuestQuitEvent;
import me.blackvein.quests.module.ICustomObjective;
import me.blackvein.quests.enums.ObjectiveType;
import me.blackvein.quests.events.quest.QuestTakeEvent;
@@ -55,6 +58,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.conversations.ConversationFactory;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@@ -91,6 +95,7 @@ public class Quester implements IQuester {
private final Quests plugin;
private UUID id;
protected String questIdToTake;
+ protected String questIdToQuit;
private String lastKnownName;
protected int questPoints = 0;
private String compassTargetQuestId;
@@ -269,6 +274,16 @@ public class Quester implements IQuester {
this.questIdToTake = questIdToTake;
}
+ @Override
+ public String getQuestIdToQuit() {
+ return questIdToQuit;
+ }
+
+ @Override
+ public void setQuestIdToQuit(final String questIdToQuit) {
+ this.questIdToQuit = questIdToQuit;
+ }
+
@Override
public String getLastKnownName() {
return lastKnownName;
@@ -462,6 +477,120 @@ public class Quester implements IQuester {
getPlayer().getInventory().setItem(index, journal.toItemStack());
}
}
+
+ /**
+ * Check if quest is available and, if so, ask Quester if they would like to start it
+ *
+ * @param quest The quest to check and then offer
+ * @param giveReason Whether to inform Quester of unavailability
+ * @return true if successful
+ */
+ public boolean offerQuest(final IQuest quest, final boolean giveReason) {
+ if (quest == null) {
+ return false;
+ }
+ final QuestTakeEvent event = new QuestTakeEvent(quest, this);
+ plugin.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;
+ }
+ if (canAcceptOffer(quest, giveReason)) {
+ if (getPlayer() != null) {
+ if (!getPlayer().isConversing()) {
+ setQuestIdToTake(quest.getId());
+ final String s = ChatColor.GOLD + Lang.get("questObjectivesTitle")
+ .replace("", quest.getName()) + "\n" + ChatColor.RESET + quest.getDescription();
+ for (final String msg : s.split("
")) {
+ sendMessage(msg);
+ }
+ if (!plugin.getSettings().canAskConfirmation()) {
+ takeQuest(quest, false);
+ } else {
+ plugin.getConversationFactory().buildConversation(getPlayer()).begin();
+ }
+ return true;
+ } else {
+ sendMessage(ChatColor.YELLOW + Lang.get(getPlayer(), "alreadyConversing"));
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check if quest is available to this Quester
+ *
+ * @param quest The quest to check
+ * @param giveReason Whether to inform Quester of unavailability
+ * @return true if available
+ */
+ public boolean canAcceptOffer(final IQuest quest, final boolean giveReason) {
+ if (quest == null) {
+ return false;
+ }
+ if (getCurrentQuests().size() >= plugin.getSettings().getMaxQuests() && plugin.getSettings().getMaxQuests()
+ > 0) {
+ if (giveReason) {
+ final String msg = Lang.get(getPlayer(), "questMaxAllowed").replace("",
+ String.valueOf(plugin.getSettings().getMaxQuests()));
+ sendMessage(ChatColor.YELLOW + msg);
+ }
+ return false;
+ } else if (getCurrentQuests().containsKey(quest)) {
+ if (giveReason) {
+ final String msg = Lang.get(getPlayer(), "questAlreadyOn");
+ sendMessage(ChatColor.YELLOW + msg);
+ }
+ return false;
+ } else if (getCompletedQuests().contains(quest) && quest.getPlanner().getCooldown() < 0) {
+ if (giveReason) {
+ final String msg = Lang.get(getPlayer(), "questAlreadyCompleted")
+ .replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW);
+ sendMessage(ChatColor.YELLOW + msg);
+ }
+ return false;
+ } else if (plugin.getDependencies().getCitizens() != null
+ && !plugin.getSettings().canAllowCommandsForNpcQuests()
+ && quest.getNpcStart() != null && quest.getNpcStart().getEntity() != null
+ && quest.getNpcStart().getEntity().getLocation().getWorld() != null
+ && getPlayer().getLocation().getWorld() != null
+ && quest.getNpcStart().getEntity().getLocation().getWorld().getName().equals(
+ getPlayer().getLocation().getWorld().getName())
+ && quest.getNpcStart().getEntity().getLocation().distance(getPlayer().getLocation()) > 6.0) {
+ if (giveReason) {
+ final String msg = Lang.get(getPlayer(), "mustSpeakTo").replace("", ChatColor.DARK_PURPLE
+ + quest.getNpcStart().getName() + ChatColor.YELLOW);
+ sendMessage(ChatColor.YELLOW + msg);
+ }
+ return false;
+ } else if (quest.getBlockStart() != null) {
+ if (giveReason) {
+ final String msg = Lang.get(getPlayer(), "noCommandStart").replace("", ChatColor.DARK_PURPLE
+ + quest.getName() + ChatColor.YELLOW);
+ sendMessage(ChatColor.YELLOW + msg);
+ }
+ return false;
+ } else if (getCompletedQuests().contains(quest) && getRemainingCooldown(quest) > 0
+ && !quest.getPlanner().getOverride()) {
+ if (giveReason) {
+ final String msg = Lang.get(getPlayer(), "questTooEarly").replace("", ChatColor.AQUA
+ + quest.getName()+ ChatColor.YELLOW).replace("