Implement Power Play reward month calculations
This commit is contained in:
parent
4fe5eb8b45
commit
64802769d6
@ -5,11 +5,13 @@ import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.powerplayclub.PowerPlayData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
|
||||
public class PowerPlayCommand extends CommandBase<BonusManager>
|
||||
{
|
||||
@ -37,7 +39,8 @@ public class PowerPlayCommand extends CommandBase<BonusManager>
|
||||
return;
|
||||
}
|
||||
|
||||
_bonusManager.getPowerPlayClubRepository().Get(player).setSubscribed(true);
|
||||
PowerPlayData cached = _bonusManager.getPowerPlayClubRepository().getCachedData(player);
|
||||
cached.getUnclaimedMonths().add(YearMonth.now());
|
||||
_bonusManager.getPowerPlayClubRepository().addSubscription(_bonusManager.getClientManager().Get(player).getAccountId(), LocalDate.now(), "month");
|
||||
|
||||
caller.sendMessage(ChatColor.GREEN + "Gave a month's subscription to " + player.getName());
|
||||
|
@ -102,7 +102,7 @@ public class PowerPlayClubButton implements GuiItem
|
||||
|
||||
lore = buildLore(unclaimed);
|
||||
lore.add("");
|
||||
lore.add(C.Reset + "Click to claim!");
|
||||
lore.add(C.cGold + "Click to claim!");
|
||||
|
||||
} else if (cached.isSubscribed())
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
package mineplex.core.powerplayclub;
|
||||
|
||||
import java.time.Month;
|
||||
import java.time.Year;
|
||||
import java.time.YearMonth;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -30,7 +29,7 @@ public class PowerPlayClubRewards
|
||||
.put(YearMonth.of(2016, Month.OCTOBER), new PowerPlayClubItem("Witch Morph", SkinData.WITCH.getSkull()))
|
||||
.build();
|
||||
|
||||
private static class PowerPlayClubItem
|
||||
public static class PowerPlayClubItem
|
||||
{
|
||||
private final String _prize;
|
||||
private final ItemStack _display;
|
||||
|
@ -1,18 +1,80 @@
|
||||
package mineplex.core.powerplayclub;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PowerPlayData
|
||||
{
|
||||
private final boolean _subscribed;
|
||||
private final List<YearMonth> _unclaimedMonths;
|
||||
|
||||
static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> claimMonths)
|
||||
static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> claimedMonths)
|
||||
{
|
||||
// TODO
|
||||
return null;
|
||||
if (subscriptions.isEmpty())
|
||||
{
|
||||
return new PowerPlayData(false, Collections.emptyList());
|
||||
}
|
||||
|
||||
// Build the list of potential claim dates from subscriptions
|
||||
List<LocalDate> claimDates = subscriptions.stream()
|
||||
.flatMap(sub -> buildMonths(sub).stream())
|
||||
.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());
|
||||
|
||||
// Remove already-claimed months
|
||||
Optional<YearMonth> latestClaimed = claimedMonths.stream().collect(Collectors.maxBy(YearMonth::compareTo));
|
||||
latestClaimed.ifPresent(latest ->
|
||||
{
|
||||
while (!claimDates.isEmpty())
|
||||
{
|
||||
LocalDate claimDate = claimDates.get(0);
|
||||
YearMonth claimMonth = YearMonth.from(claimDate);
|
||||
if (latest.equals(claimMonth) || latest.isAfter(claimMonth))
|
||||
{
|
||||
claimDates.remove(0);
|
||||
|
||||
} else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
List<YearMonth> unclaimedMonths = claimDates.stream()
|
||||
.filter(date -> date.isBefore(LocalDate.now()) || date.equals(LocalDate.now())) // Filter dates yet to come
|
||||
.map(YearMonth::from)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new PowerPlayData(subscribed, unclaimedMonths);
|
||||
}
|
||||
|
||||
private static List<LocalDate> buildMonths(Subscription subscription)
|
||||
{
|
||||
switch (subscription._duration)
|
||||
{
|
||||
case MONTH:
|
||||
return Collections.singletonList(subscription._startDate);
|
||||
|
||||
case YEAR:
|
||||
List<LocalDate> months = new ArrayList<>();
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
months.add(subscription._startDate.plusMonths(i));
|
||||
}
|
||||
return months;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("Invalid duration");
|
||||
}
|
||||
}
|
||||
|
||||
static class Subscription {
|
||||
@ -45,4 +107,10 @@ public class PowerPlayData
|
||||
{
|
||||
return _subscribed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return Objects.toStringHelper(this).add("subscribed", _subscribed).add("unclaimed", _unclaimedMonths).toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user