add PowerplayPage
This commit is contained in:
parent
c8a1bed01c
commit
5e5762d6e7
@ -0,0 +1,110 @@
|
|||||||
|
package mineplex.staffServer.ui.ppc;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.YearMonth;
|
||||||
|
import java.time.format.TextStyle;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
|
import mineplex.core.powerplayclub.PowerPlayClubRewards;
|
||||||
|
import mineplex.core.powerplayclub.PowerPlayData;
|
||||||
|
import mineplex.core.shop.page.MultiPageManager;
|
||||||
|
import mineplex.staffServer.customerSupport.CustomerSupport;
|
||||||
|
import mineplex.staffServer.ui.SupportPage;
|
||||||
|
import mineplex.staffServer.ui.SupportShop;
|
||||||
|
|
||||||
|
public class SupportPowerplayPage extends SupportPage
|
||||||
|
{
|
||||||
|
private MultiPageManager<PowerPlayData.Subscription> _multiPageManager;
|
||||||
|
|
||||||
|
public SupportPowerplayPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage)
|
||||||
|
{
|
||||||
|
super(plugin, shop, player, target, previousPage, "PPC");
|
||||||
|
|
||||||
|
_multiPageManager = new MultiPageManager<>(this, this::getSubscriptions, this::buildPowerPlayItem);
|
||||||
|
|
||||||
|
buildPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getMilliseconds(YearMonth yearMonth)
|
||||||
|
{
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
|
||||||
|
cal.set(Calendar.YEAR, yearMonth.getYear());
|
||||||
|
cal.set(Calendar.MONTH, yearMonth.getMonthValue());
|
||||||
|
|
||||||
|
return cal.getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildPowerPlayItem(PowerPlayData.Subscription subscription, int slot)
|
||||||
|
{
|
||||||
|
PowerPlayData subData = PowerPlayData.fromSubsAndClaims(Collections.singletonList(subscription), Collections.emptyList());
|
||||||
|
|
||||||
|
LocalDate endDate = subscription._startDate.plusMonths(subscription._duration.getLength());
|
||||||
|
|
||||||
|
ItemBuilder builder = new ItemBuilder(subData.isSubscribed() ? Material.GOLD_BLOCK : Material.IRON_BLOCK)
|
||||||
|
.setTitle(C.cGreenB + subscription._duration.getName() + "ly Subscription")
|
||||||
|
.addLore("")
|
||||||
|
.addLore(C.cGray + "Start Date: " + C.cYellow + subscription._startDate.getMonth().getDisplayName(TextStyle.FULL, Locale.US) + " " + subscription._startDate.getDayOfMonth() + " " + subscription._startDate.getYear())
|
||||||
|
.addLore(C.cGray + "End Date: " + C.cYellow + endDate.getMonth().getDisplayName(TextStyle.FULL, Locale.US) + " " + endDate.getDayOfMonth() + " " + endDate.getYear())
|
||||||
|
.addLore(C.cGray + "Duration: " + C.cYellow + subscription._duration.getName())
|
||||||
|
.addLore("")
|
||||||
|
.addLore(C.cGreenB + "Subscription Cosmetics");
|
||||||
|
|
||||||
|
PowerPlayClubRewards.rewards().entrySet().stream()
|
||||||
|
.filter(entry -> subData.getUsableCosmeticMonths().contains(entry.getKey()))
|
||||||
|
.sorted(Comparator.comparingLong(a -> getMilliseconds(a.getKey())))
|
||||||
|
.forEach(entry ->
|
||||||
|
{
|
||||||
|
YearMonth yearMonth = entry.getKey();
|
||||||
|
builder.addLore(C.cWhite + " " + entry.getValue().getPrizeName() + " " + C.cGold + yearMonth.getMonth().getDisplayName(TextStyle.FULL, Locale.US) + " " + yearMonth.getYear());
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addLore("");
|
||||||
|
|
||||||
|
if (subData.getUnclaimedMonths().isEmpty())
|
||||||
|
{
|
||||||
|
builder.addLore(C.cAqua + "All current rewards claimed");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.addLore(C.cRedB + "Unclaimed rewards");
|
||||||
|
builder.addLore(" " + C.cWhite + (PowerPlayClubRewards.AMPLIFIERS_PER_MONTH * subData.getUnclaimedMonths().size()) + " Game Amplifier");
|
||||||
|
builder.addLore(" " + C.cWhite + (PowerPlayClubRewards.CHESTS_PER_MONTH * subData.getUnclaimedMonths().size()) + " Omega Chest");
|
||||||
|
}
|
||||||
|
|
||||||
|
addItem(slot, builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public PowerPlayData getPowerPlayData()
|
||||||
|
{
|
||||||
|
return getShop().getPowerPlayData().get(_target.getAccountId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PowerPlayData.Subscription> getSubscriptions()
|
||||||
|
{
|
||||||
|
List<PowerPlayData.Subscription> subscriptions = getPowerPlayData().getSubscriptions();
|
||||||
|
|
||||||
|
subscriptions.sort((a, b) -> Long.compare(b._startDate.toEpochDay(), a._startDate.toEpochDay()));
|
||||||
|
|
||||||
|
return subscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildPage()
|
||||||
|
{
|
||||||
|
super.buildPage();
|
||||||
|
|
||||||
|
_multiPageManager.buildPage();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user