Add 'come back on $DATE' message to carl for Power Play
This commit is contained in:
parent
876d35b482
commit
8793be56ed
@ -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<LocalDate> maybeNextClaimDate = cached.getNextClaimDate();
|
||||
List<YearMonth> 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
|
||||
{
|
||||
|
@ -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<LocalDate> _nextClaimDate;
|
||||
private final List<YearMonth> _unclaimedMonths;
|
||||
|
||||
static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> 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<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
|
||||
Optional<YearMonth> 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<LocalDate> buildMonths(Subscription subscription)
|
||||
@ -92,12 +109,17 @@ public class PowerPlayData
|
||||
MONTH, YEAR
|
||||
}
|
||||
|
||||
private PowerPlayData(boolean subscribed, List<YearMonth> unclaimedMonths)
|
||||
private PowerPlayData(Optional<LocalDate> nextClaimDate, List<YearMonth> unclaimedMonths)
|
||||
{
|
||||
_subscribed = subscribed;
|
||||
_nextClaimDate = nextClaimDate;
|
||||
_unclaimedMonths = unclaimedMonths;
|
||||
}
|
||||
|
||||
public Optional<LocalDate> getNextClaimDate()
|
||||
{
|
||||
return _nextClaimDate;
|
||||
}
|
||||
|
||||
public List<YearMonth> 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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user