mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-25 03:55:35 +01:00
Delegate quest offering to new method
This commit is contained in:
parent
d6d781e61d
commit
62b0329025
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,6 +38,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.conversations.Conversable;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -47,8 +49,11 @@ import org.bukkit.inventory.meta.BookMeta;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import com.alessiodp.parties.api.interfaces.Party;
|
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 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.QuesterPostStartQuestEvent;
|
||||||
import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent;
|
import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent;
|
||||||
import me.blackvein.quests.timers.StageTimer;
|
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.Lang;
|
||||||
import me.blackvein.quests.util.LocaleQuery;
|
import me.blackvein.quests.util.LocaleQuery;
|
||||||
import me.blackvein.quests.util.MiscUtil;
|
import me.blackvein.quests.util.MiscUtil;
|
||||||
|
import me.blackvein.quests.util.WorldGuardAPI;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
|
||||||
public class Quester {
|
public class Quester {
|
||||||
@ -388,6 +394,12 @@ public class Quester {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
public void takeQuest(Quest q, boolean override) {
|
||||||
if (q == null) {
|
if (q == null) {
|
||||||
return;
|
return;
|
||||||
@ -2844,6 +2856,11 @@ public class Quester {
|
|||||||
return completedQuests.isEmpty() == false;
|
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) {
|
public void checkQuest(Quest quest) {
|
||||||
if (quest != null) {
|
if (quest != null) {
|
||||||
boolean exists = false;
|
boolean exists = false;
|
||||||
@ -3043,6 +3060,102 @@ public class Quester {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if quest is available and, if so, ask Quester if they would like to start it<p>
|
||||||
|
*
|
||||||
|
* @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("<number>", 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("<quest>", 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("<npc>", 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("<quest>", 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("<quest>", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW);
|
||||||
|
msg = msg.replace("<time>", ChatColor.DARK_PURPLE + Quests.getTime(getCooldownDifference(quest)) + ChatColor.YELLOW);
|
||||||
|
player.sendMessage(ChatColor.YELLOW + msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (quest.getRegion() != null) {
|
||||||
|
boolean inRegion = false;
|
||||||
|
WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi();
|
||||||
|
RegionManager rm = api.getRegionManager(player.getWorld());
|
||||||
|
Iterator<ProtectedRegion> it = rm.getApplicableRegions(player.getLocation()).iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
ProtectedRegion pr = it.next();
|
||||||
|
if (pr.getId().equalsIgnoreCase(quest.getRegion())) {
|
||||||
|
inRegion = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inRegion == false) {
|
||||||
|
if (giveReason) {
|
||||||
|
String msg = Lang.get(player, "questInvalidLocation");
|
||||||
|
msg = msg.replace("<quest>", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW);
|
||||||
|
player.sendMessage(ChatColor.YELLOW + msg);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player instanceof Conversable) {
|
||||||
|
if (((Player) player).isConversing() == false) {
|
||||||
|
setQuestToTake(quest.getName());
|
||||||
|
String s = ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + getQuestToTake() + ChatColor.GOLD + " -\n" + "\n" + ChatColor.RESET + plugin.getQuest(getQuestToTake()).getDescription() + "\n";
|
||||||
|
for (String msg : s.split("<br>")) {
|
||||||
|
player.sendMessage(msg);
|
||||||
|
}
|
||||||
|
if (!plugin.getSettings().canAskConfirmation()) {
|
||||||
|
takeQuest(plugin.getQuest(getQuestToTake()), false);
|
||||||
|
} else {
|
||||||
|
plugin.getConversationFactory().buildConversation((Conversable) player).begin();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "alreadyConversing"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// I'm not sure why these methods are here. They've been in the class for a long time but aren't used anywhere?
|
// I'm not sure why these methods are here. They've been in the class for a long time but aren't used anywhere?
|
||||||
|
|
||||||
/*public static String checkPlacement(Inventory inv, int rawSlot) {
|
/*public static String checkPlacement(Inventory inv, int rawSlot) {
|
||||||
|
@ -31,12 +31,10 @@ import me.blackvein.quests.Quests;
|
|||||||
import me.blackvein.quests.Requirements;
|
import me.blackvein.quests.Requirements;
|
||||||
import me.blackvein.quests.Stage;
|
import me.blackvein.quests.Stage;
|
||||||
import me.blackvein.quests.events.quest.QuestQuitEvent;
|
import me.blackvein.quests.events.quest.QuestQuitEvent;
|
||||||
import me.blackvein.quests.events.quest.QuestTakeEvent;
|
|
||||||
import me.blackvein.quests.exceptions.InvalidStageException;
|
import me.blackvein.quests.exceptions.InvalidStageException;
|
||||||
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 me.blackvein.quests.util.MiscUtil;
|
import me.blackvein.quests.util.MiscUtil;
|
||||||
import me.blackvein.quests.util.WorldGuardAPI;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -53,9 +51,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
||||||
|
|
||||||
public class CmdExecutor implements CommandExecutor {
|
public class CmdExecutor implements CommandExecutor {
|
||||||
private final Quests plugin;
|
private final Quests plugin;
|
||||||
public HashMap<String, Integer> commands = new HashMap<String, Integer>();
|
public HashMap<String, Integer> commands = new HashMap<String, Integer>();
|
||||||
@ -668,81 +663,7 @@ public class CmdExecutor implements CommandExecutor {
|
|||||||
Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
|
Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
|
||||||
if (questToFind != null) {
|
if (questToFind != null) {
|
||||||
final Quest q = questToFind;
|
final Quest q = questToFind;
|
||||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
plugin.getQuester(player.getUniqueId()).offerQuest(q, true);
|
||||||
QuestTakeEvent event = new QuestTakeEvent(q, quester);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (quester.getCurrentQuests().size() >= plugin.getSettings().getMaxQuests() && plugin.getSettings().getMaxQuests() > 0) {
|
|
||||||
String msg = Lang.get(player, "questMaxAllowed");
|
|
||||||
msg = msg.replace("<number>", String.valueOf(plugin.getSettings().getMaxQuests()));
|
|
||||||
player.sendMessage(ChatColor.YELLOW + msg);
|
|
||||||
} else if (quester.getCurrentQuests().containsKey(q)) {
|
|
||||||
String msg = Lang.get(player, "questAlreadyOn");
|
|
||||||
player.sendMessage(ChatColor.YELLOW + msg);
|
|
||||||
} else if (quester.getCompletedQuests().contains(q.getName()) && q.getPlanner().getCooldown() < 0) {
|
|
||||||
String msg = Lang.get(player, "questAlreadyCompleted");
|
|
||||||
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + q.getName() + ChatColor.YELLOW);
|
|
||||||
player.sendMessage(ChatColor.YELLOW + msg);
|
|
||||||
} else if (q.getNpcStart() != null && plugin.getSettings().canAllowCommandsForNpcQuests() == false) {
|
|
||||||
String msg = Lang.get(player, "mustSpeakTo");
|
|
||||||
msg = msg.replace("<npc>", ChatColor.DARK_PURPLE + q.getNpcStart().getName() + ChatColor.YELLOW);
|
|
||||||
player.sendMessage(ChatColor.YELLOW + msg);
|
|
||||||
} else if (q.getBlockStart() != null) {
|
|
||||||
String msg = Lang.get(player, "noCommandStart");
|
|
||||||
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + q.getName() + ChatColor.YELLOW);
|
|
||||||
player.sendMessage(ChatColor.YELLOW + msg);
|
|
||||||
} else {
|
|
||||||
boolean takeable = true;
|
|
||||||
if (quester.getCompletedQuests().contains(q.getName())) {
|
|
||||||
if (quester.getCooldownDifference(q) > 0) {
|
|
||||||
String early = Lang.get(player, "questTooEarly");
|
|
||||||
early = early.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
|
|
||||||
early = early.replace("<time>", ChatColor.DARK_PURPLE + Quests.getTime(quester.getCooldownDifference(q)) + ChatColor.YELLOW);
|
|
||||||
player.sendMessage(ChatColor.YELLOW + early);
|
|
||||||
takeable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (q.getRegion() != null) {
|
|
||||||
boolean inRegion = false;
|
|
||||||
Player p = quester.getPlayer();
|
|
||||||
WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi();
|
|
||||||
RegionManager rm = api.getRegionManager(p.getWorld());
|
|
||||||
Iterator<ProtectedRegion> it = rm.getApplicableRegions(p.getLocation()).iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
ProtectedRegion pr = it.next();
|
|
||||||
if (pr.getId().equalsIgnoreCase(q.getRegion())) {
|
|
||||||
inRegion = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (inRegion == false) {
|
|
||||||
String msg = Lang.get(player, "questInvalidLocation");
|
|
||||||
msg = msg.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
|
|
||||||
player.sendMessage(ChatColor.YELLOW + msg);
|
|
||||||
takeable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (takeable == true) {
|
|
||||||
if (player instanceof Conversable) {
|
|
||||||
if (((Player) player).isConversing() == false) {
|
|
||||||
quester.setQuestToTake(q.getName());
|
|
||||||
String s = ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.getQuestToTake() + ChatColor.GOLD + " -\n" + "\n" + ChatColor.RESET + plugin.getQuest(quester.getQuestToTake()).getDescription() + "\n";
|
|
||||||
for (String msg : s.split("<br>")) {
|
|
||||||
player.sendMessage(msg);
|
|
||||||
}
|
|
||||||
if (!plugin.getSettings().canAskConfirmation()) {
|
|
||||||
plugin.getQuester(player.getUniqueId()).takeQuest(plugin.getQuest(plugin.getQuester(player.getUniqueId()).getQuestToTake()), false);
|
|
||||||
} else {
|
|
||||||
plugin.getConversationFactory().buildConversation((Conversable) player).begin();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "alreadyConversing"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questNotFound"));
|
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questNotFound"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user