From cc9a22d828b6ddd36a1886d1cdae60a2d917d2e0 Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 28 Jul 2020 19:06:36 +0200 Subject: [PATCH] Trigger delays fixed --- .../net/Indyuce/mmocore/api/quest/PlayerQuests.java | 2 +- .../net/Indyuce/mmocore/api/quest/QuestProgress.java | 8 ++------ .../Indyuce/mmocore/api/quest/trigger/Trigger.java | 12 ++++++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/PlayerQuests.java b/src/main/java/net/Indyuce/mmocore/api/quest/PlayerQuests.java index 6459dc99..30c44d60 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/PlayerQuests.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/PlayerQuests.java @@ -150,7 +150,7 @@ public class PlayerQuests { // close current objective progress if quest is active if (hasCurrent()) - current.closeObjectiveProgress(); + current.getProgress().close(); // apply newer quest current = quest == null ? null : quest.generateNewProgress(playerData); diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/QuestProgress.java b/src/main/java/net/Indyuce/mmocore/api/quest/QuestProgress.java index 3589a490..e5bb6953 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/QuestProgress.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/QuestProgress.java @@ -43,16 +43,12 @@ public class QuestProgress { return quest.getObjectives().get(objective); } - public void closeObjectiveProgress() { - objectiveProgress.close(); - } - public void completeObjective() { objective++; - closeObjectiveProgress(); + objectiveProgress.close(); // apply triggers - objectiveProgress.getObjective().getTriggers().forEach(trigger -> trigger.apply(getPlayer())); + objectiveProgress.getObjective().getTriggers().forEach(trigger -> trigger.schedule(getPlayer())); // end quest if (objective >= quest.getObjectives().size()) diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java index ae4a61e2..fb95975c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java @@ -10,7 +10,7 @@ public abstract class Trigger { private final long delay; public Trigger(MMOLineConfig config) { - delay = config.contains("delay") ? (long) (config.getDouble("delay") * 20) : 0; + delay = config.contains("delay") ? (long) (config.getDouble("delay") * 20.) : 0; } public boolean hasDelay() { @@ -22,8 +22,16 @@ public abstract class Trigger { } public void schedule(PlayerData player) { - Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, () -> apply(player), delay); + if (delay <= 0) + apply(player); + else + Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, () -> apply(player), delay); } + /* + * this method must not be used directly when executing triggers after quest + * objectives for example, because this method does NOT take into account + * trigger delay + */ public abstract void apply(PlayerData player); }