From 1b01995546a2472ae81db9e8b2f19bc21e438769 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 24 Sep 2021 13:08:33 +0300 Subject: [PATCH] Add timeout for repeatable challenges. Relates #71 --- .../challenges/database/object/Challenge.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenge.java b/src/main/java/world/bentobox/challenges/database/object/Challenge.java index 83a8ce1..594e35d 100644 --- a/src/main/java/world/bentobox/challenges/database/object/Challenge.java +++ b/src/main/java/world/bentobox/challenges/database/object/Challenge.java @@ -190,6 +190,12 @@ public class Challenge implements DataObject @Expose private boolean repeatable; + /** + * Timeout for repeatable challenge before it can be completed again. + */ + @Expose + private long timeout; + /** * Description of the repeat rewards. If blank, it will be autogenerated */ @@ -442,6 +448,17 @@ public class Challenge implements DataObject } + /** + * Gets timeout. + * + * @return the timeout + */ + public long getTimeout() + { + return timeout; + } + + // --------------------------------------------------------------------- // Section: Setters // --------------------------------------------------------------------- @@ -698,6 +715,17 @@ public class Challenge implements DataObject } + /** + * Sets timeout. + * + * @param timeout the timeout + */ + public void setTimeout(long timeout) + { + this.timeout = timeout; + } + + // --------------------------------------------------------------------- // Section: Other methods // --------------------------------------------------------------------- @@ -715,7 +743,7 @@ public class Challenge implements DataObject public boolean matchGameMode(String gameMode) { return gameMode != null && - this.uniqueId.regionMatches(true, 0, gameMode, 0, gameMode.length()); + this.uniqueId.regionMatches(true, 0, gameMode, 0, gameMode.length()); } @@ -746,13 +774,11 @@ public class Challenge implements DataObject return true; } - if (!(obj instanceof Challenge)) + if (!(obj instanceof Challenge other)) { return false; } - Challenge other = (Challenge) obj; - if (uniqueId == null) { return other.uniqueId == null; @@ -831,6 +857,7 @@ public class Challenge implements DataObject collect(Collectors.toCollection(() -> new ArrayList<>(this.repeatItemReward.size())))); clone.setRepeatMoneyReward(this.repeatMoneyReward); clone.setRepeatRewardCommands(new ArrayList<>(this.repeatRewardCommands)); + clone.setTimeout(this.timeout); } catch (Exception e) {