public static boolean assignQuest(Player player, int UID, String questName) {
questName = questName.toLowerCase();
if (!isValidQuest(questName)) {
throw new IllegalArgumentException("Given quest does not exist");
}
Quest quest = quests.get(questName);
if (!canRepeat(player, quest)) {
player.sendMessage(ChatColor.GRAY + "You are not allowed to repeat this quest again.");
return false;
}
if (getProfile(player.getName()).hasCompleted(questName) && quest.getDelay() > 0) {
long delayDifference = getDelayDifference(
getProfile(player.getName()).getCompletedQuest(questName), quest);
if (delayDifference > 0) {
long hours = TimeUnit.HOURS.convert(delayDifference, TimeUnit.MINUTES);
long minutes = delayDifference - TimeUnit.MINUTES.convert(hours, TimeUnit.HOURS);
player.sendMessage(ChatColor.GRAY + "You must wait "
+ StringUtils.wrap(hours, ChatColor.GRAY) + " hours and "
+ StringUtils.wrap(minutes, ChatColor.GRAY)
+ " minutes before attempting this quest again.");
return false;
}
}
for (Requirement requirement : quest.getRequirements()) {
if (!requirement.fulfilsRequirement(player)) {
player.sendMessage(ChatColor.GRAY + "Missing requirement. "
+ requirement.getRequiredText(player));
return false;
}
if (requirement.isTake())
requirement.grant(player, UID);
}
for (Reward reward : quest.getInitialRewards()) {
reward.grant(player, UID);
}
QuestBeginEvent call = new QuestBeginEvent(quest, player);
Bukkit.getPluginManager().callEvent(call);
if (call.isCancelled()) {
return false;
}
getProfile(player.getName()).setProgress(
new QuestProgress(UID, player, questName, System.currentTimeMillis()));
Messaging.send(player, quest.getAcceptanceText());
return true;
}