From 67a72d31c68cee4410983daf960e4f8ab82a9b17 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Tue, 26 Jul 2022 07:32:26 -0400 Subject: [PATCH] Separate method to check punctuality, see #1991 --- .../java/me/blackvein/quests/Quester.java | 179 ++++++++++-------- 1 file changed, 99 insertions(+), 80 deletions(-) diff --git a/core/src/main/java/me/blackvein/quests/Quester.java b/core/src/main/java/me/blackvein/quests/Quester.java index c090a4883..31eaaf321 100644 --- a/core/src/main/java/me/blackvein/quests/Quester.java +++ b/core/src/main/java/me/blackvein/quests/Quester.java @@ -643,6 +643,103 @@ public class Quester implements IQuester { } return true; } + + /** + * Check if Quester is too early or late for a planned quest

+ * + * For player cooldown, use {@link #canAcceptOffer(IQuest, boolean)} instead + * + * @param quest The quest to check + * @param giveReason Whether to inform Quester of unpunctuality + * @return true if on time + */ + public boolean isOnTime(final IQuest quest, final boolean giveReason) { + final Planner pln = quest.getPlanner(); + final long currentTime = System.currentTimeMillis(); + final long start = pln.getStartInMillis(); // Start time in milliseconds since UTC epoch + final long end = pln.getEndInMillis(); // End time in milliseconds since UTC epoch + final long duration = end - start; // How long the quest can be active for + final long repeat = pln.getRepeat(); // Length to wait in-between start times + if (start != -1) { + if (currentTime < start) { + if (giveReason) { + String early = Lang.get("plnTooEarly"); + early = early.replace("", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW); + early = early.replace("