diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java index b96e421ff..c7aa97f79 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java @@ -2,10 +2,8 @@ package mineplex.core.bonuses.gui.buttons; import java.time.LocalDate; import java.time.YearMonth; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.time.format.TextStyle; +import java.util.*; import mineplex.core.bonuses.BonusManager; import mineplex.core.common.util.C; @@ -92,6 +90,7 @@ public class PowerPlayClubButton implements GuiItem PowerPlayData cached = _powerPlayClubRepository.getCachedData(_player); + Optional maybeNextClaimDate = cached.getNextClaimDate(); List unclaimed = cached.getUnclaimedMonths(); if (!unclaimed.isEmpty()) @@ -104,16 +103,16 @@ public class PowerPlayClubButton implements GuiItem lore.add(" "); lore.add(C.cGold + "Click to claim!"); - } else if (cached.isSubscribed()) + } else if (maybeNextClaimDate.isPresent()) // Player is still subscribed, and has claimed everything so far { - // Player is subscribed and has claimed all of his/her rewards + LocalDate nextClaimDate = maybeNextClaimDate.get(); + material = Material.REDSTONE_BLOCK; itemName = C.cRedB + "Power Play Club"; lore = new ArrayList<>(); - lore.add(C.cRed + "Already claimed!"); - - // TODO: 'come back later!' + lore.add(C.cWhite + "Come back on " + C.cGreen + nextClaimDate.getMonth().getDisplayName(TextStyle.FULL, Locale.US) + " " + nextClaimDate.getDayOfMonth()); + lore.add(C.cWhite + "for your next reward!"); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayData.java b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayData.java index 620dac03f..79d976146 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayData.java @@ -9,14 +9,17 @@ import java.util.stream.Collectors; public class PowerPlayData { - private final boolean _subscribed; + // If this is set, the player's subscription is set up to recur next month + // In the case of a yearly subscription, this is just the next month's date. + // Corollary: If this isn't Optional.empty(), the player is subscribed. + private final Optional _nextClaimDate; private final List _unclaimedMonths; static PowerPlayData fromSubsAndClaims(List subscriptions, List claimedMonths) { if (subscriptions.isEmpty()) { - return new PowerPlayData(false, Collections.emptyList()); + return new PowerPlayData(Optional.empty(), Collections.emptyList()); } // Build the list of potential claim dates from subscriptions @@ -25,9 +28,23 @@ public class PowerPlayData .sorted() .collect(Collectors.toCollection(LinkedList::new)); - // Determine if player is subscribed - LocalDate latestSub = claimDates.get(claimDates.size() - 1); - final boolean subscribed = latestSub.plusMonths(1).isAfter(LocalDate.now()); + // Determine the player's next claim date (which will tell us whether + // they're subscribed as well + final Optional nextClaimDate; + + // In the case of a yearly subscription, they'll already have a claim date scheduled + Optional nextSubClaim = claimDates.stream().filter(date -> date.isAfter(LocalDate.now())).findFirst(); + if (nextSubClaim.isPresent()) + { + nextClaimDate = nextSubClaim; + + } else + { + // In the case of a monthly subscription, we need to extrapolate the next claim date + nextClaimDate = Optional.of(claimDates.get(claimDates.size() - 1)) + .map(date -> date.plusMonths(1)) + .filter(date -> date.isAfter(LocalDate.now())); // and make sure it's after today + } // Remove already-claimed months Optional latestClaimed = claimedMonths.stream().collect(Collectors.maxBy(YearMonth::compareTo)); @@ -54,7 +71,7 @@ public class PowerPlayData .distinct() .collect(Collectors.toList()); - return new PowerPlayData(subscribed, unclaimedMonths); + return new PowerPlayData(nextClaimDate, unclaimedMonths); } private static List buildMonths(Subscription subscription) @@ -92,12 +109,17 @@ public class PowerPlayData MONTH, YEAR } - private PowerPlayData(boolean subscribed, List unclaimedMonths) + private PowerPlayData(Optional nextClaimDate, List unclaimedMonths) { - _subscribed = subscribed; + _nextClaimDate = nextClaimDate; _unclaimedMonths = unclaimedMonths; } + public Optional getNextClaimDate() + { + return _nextClaimDate; + } + public List getUnclaimedMonths() { return _unclaimedMonths; @@ -105,12 +127,12 @@ public class PowerPlayData public boolean isSubscribed() { - return _subscribed; + return _nextClaimDate.isPresent(); } @Override public String toString() { - return Objects.toStringHelper(this).add("subscribed", _subscribed).add("unclaimed", _unclaimedMonths).toString(); + return Objects.toStringHelper(this).add("_nextClaimDate", _nextClaimDate).add("_unclaimedMonths", _unclaimedMonths).toString(); } }