Add 'come back on $DATE' message to carl for Power Play

This commit is contained in:
cnr 2016-10-01 10:38:08 -07:00 committed by Shaun Bennett
parent 876d35b482
commit 8793be56ed
2 changed files with 40 additions and 19 deletions

View File

@ -2,10 +2,8 @@ package mineplex.core.bonuses.gui.buttons;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.YearMonth; import java.time.YearMonth;
import java.util.ArrayList; import java.time.format.TextStyle;
import java.util.Arrays; import java.util.*;
import java.util.Collections;
import java.util.List;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
@ -92,6 +90,7 @@ public class PowerPlayClubButton implements GuiItem
PowerPlayData cached = _powerPlayClubRepository.getCachedData(_player); PowerPlayData cached = _powerPlayClubRepository.getCachedData(_player);
Optional<LocalDate> maybeNextClaimDate = cached.getNextClaimDate();
List<YearMonth> unclaimed = cached.getUnclaimedMonths(); List<YearMonth> unclaimed = cached.getUnclaimedMonths();
if (!unclaimed.isEmpty()) if (!unclaimed.isEmpty())
@ -104,16 +103,16 @@ public class PowerPlayClubButton implements GuiItem
lore.add(" "); lore.add(" ");
lore.add(C.cGold + "Click to claim!"); 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; material = Material.REDSTONE_BLOCK;
itemName = C.cRedB + "Power Play Club"; itemName = C.cRedB + "Power Play Club";
lore = new ArrayList<>(); lore = new ArrayList<>();
lore.add(C.cRed + "Already claimed!"); 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!");
// TODO: 'come back later!'
} else } else
{ {

View File

@ -9,14 +9,17 @@ import java.util.stream.Collectors;
public class PowerPlayData 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<LocalDate> _nextClaimDate;
private final List<YearMonth> _unclaimedMonths; private final List<YearMonth> _unclaimedMonths;
static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> claimedMonths) static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> claimedMonths)
{ {
if (subscriptions.isEmpty()) 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 // Build the list of potential claim dates from subscriptions
@ -25,9 +28,23 @@ public class PowerPlayData
.sorted() .sorted()
.collect(Collectors.toCollection(LinkedList::new)); .collect(Collectors.toCollection(LinkedList::new));
// Determine if player is subscribed // Determine the player's next claim date (which will tell us whether
LocalDate latestSub = claimDates.get(claimDates.size() - 1); // they're subscribed as well
final boolean subscribed = latestSub.plusMonths(1).isAfter(LocalDate.now()); final Optional<LocalDate> nextClaimDate;
// In the case of a yearly subscription, they'll already have a claim date scheduled
Optional<LocalDate> 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 // Remove already-claimed months
Optional<YearMonth> latestClaimed = claimedMonths.stream().collect(Collectors.maxBy(YearMonth::compareTo)); Optional<YearMonth> latestClaimed = claimedMonths.stream().collect(Collectors.maxBy(YearMonth::compareTo));
@ -54,7 +71,7 @@ public class PowerPlayData
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
return new PowerPlayData(subscribed, unclaimedMonths); return new PowerPlayData(nextClaimDate, unclaimedMonths);
} }
private static List<LocalDate> buildMonths(Subscription subscription) private static List<LocalDate> buildMonths(Subscription subscription)
@ -92,12 +109,17 @@ public class PowerPlayData
MONTH, YEAR MONTH, YEAR
} }
private PowerPlayData(boolean subscribed, List<YearMonth> unclaimedMonths) private PowerPlayData(Optional<LocalDate> nextClaimDate, List<YearMonth> unclaimedMonths)
{ {
_subscribed = subscribed; _nextClaimDate = nextClaimDate;
_unclaimedMonths = unclaimedMonths; _unclaimedMonths = unclaimedMonths;
} }
public Optional<LocalDate> getNextClaimDate()
{
return _nextClaimDate;
}
public List<YearMonth> getUnclaimedMonths() public List<YearMonth> getUnclaimedMonths()
{ {
return _unclaimedMonths; return _unclaimedMonths;
@ -105,12 +127,12 @@ public class PowerPlayData
public boolean isSubscribed() public boolean isSubscribed()
{ {
return _subscribed; return _nextClaimDate.isPresent();
} }
@Override @Override
public String toString() 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();
} }
} }