Add /checkppc to CUST for detailed subscription data
This commit is contained in:
parent
3d8998ee13
commit
c533b170fe
@ -104,8 +104,6 @@ public class PowerPlayClubRepository implements Listener {
|
||||
|
||||
PowerPlayData cached = getCachedData(player);
|
||||
|
||||
List<PowerPlayClubRewards.PowerPlayClubItem> list = PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths());
|
||||
|
||||
PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths()).forEach(item -> item.reward(player));
|
||||
|
||||
// Gives Metal Man for anyone subscribed
|
||||
|
@ -113,7 +113,7 @@ public class PowerPlayClubRewards
|
||||
|
||||
public static List<PowerPlayClubItem> rewardsForMonths(Set<YearMonth> months)
|
||||
{
|
||||
return months.stream().sorted().map(rewards::get).collect(Collectors.toList());
|
||||
return months.stream().sorted().map(PowerPlayClubRewards::getReward).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Map<YearMonth, PowerPlayClubItem> rewards()
|
||||
|
@ -1,12 +1,18 @@
|
||||
package mineplex.core.powerplayclub;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
public class PowerPlayData
|
||||
{
|
||||
/* If this is set, the player's subscription is planned to recur.
|
||||
@ -19,6 +25,9 @@ public class PowerPlayData
|
||||
*/
|
||||
private final Optional<LocalDate> _nextClaimDate;
|
||||
|
||||
// The source set of subscriptions from which this was built
|
||||
private final List<Subscription> _subscriptions;
|
||||
|
||||
// The months where the player hasn't claimed chests/amplifiers
|
||||
private final Set<YearMonth> _unclaimedMonths;
|
||||
|
||||
@ -29,11 +38,11 @@ public class PowerPlayData
|
||||
*/
|
||||
private final Set<YearMonth> _cosmeticMonths;
|
||||
|
||||
static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> claimedMonths)
|
||||
public static PowerPlayData fromSubsAndClaims(List<Subscription> subscriptions, List<YearMonth> claimedMonths)
|
||||
{
|
||||
if (subscriptions.isEmpty())
|
||||
{
|
||||
return new PowerPlayData(Optional.empty(), new HashSet<>(), new HashSet<>());
|
||||
return new PowerPlayData(subscriptions, Optional.empty(), new HashSet<>(), new HashSet<>());
|
||||
}
|
||||
|
||||
final LocalDate today = LocalDate.now();
|
||||
@ -96,7 +105,7 @@ public class PowerPlayData
|
||||
.map(YearMonth::from)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return new PowerPlayData(nextClaimDate, unclaimedMonths, cosmeticMonths);
|
||||
return new PowerPlayData(subscriptions, nextClaimDate, unclaimedMonths, cosmeticMonths);
|
||||
}
|
||||
|
||||
private static List<LocalDate> buildMonths(Subscription subscription)
|
||||
@ -126,10 +135,10 @@ public class PowerPlayData
|
||||
}
|
||||
}
|
||||
|
||||
static class Subscription
|
||||
public static class Subscription
|
||||
{
|
||||
private final LocalDate _startDate;
|
||||
private final SubscriptionDuration _duration;
|
||||
public final LocalDate _startDate;
|
||||
public final SubscriptionDuration _duration;
|
||||
|
||||
Subscription(LocalDate startDate, SubscriptionDuration duration)
|
||||
{
|
||||
@ -143,13 +152,19 @@ public class PowerPlayData
|
||||
MONTH, YEAR
|
||||
}
|
||||
|
||||
private PowerPlayData(Optional<LocalDate> nextClaimDate, Set<YearMonth> unclaimedMonths, Set<YearMonth> cosmeticMonths)
|
||||
private PowerPlayData(List<Subscription> subscriptions, Optional<LocalDate> nextClaimDate, Set<YearMonth> unclaimedMonths, Set<YearMonth> cosmeticMonths)
|
||||
{
|
||||
_subscriptions = subscriptions;
|
||||
_nextClaimDate = nextClaimDate;
|
||||
_unclaimedMonths = unclaimedMonths;
|
||||
_cosmeticMonths = cosmeticMonths;
|
||||
}
|
||||
|
||||
public List<Subscription> getSubscriptions()
|
||||
{
|
||||
return _subscriptions;
|
||||
}
|
||||
|
||||
public Optional<LocalDate> getNextClaimDate()
|
||||
{
|
||||
return _nextClaimDate;
|
||||
@ -173,7 +188,7 @@ public class PowerPlayData
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return Objects.toStringHelper(this)
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("_nextClaimDate", _nextClaimDate)
|
||||
.add("_unclaimedMonths", _unclaimedMonths)
|
||||
.add("_cosmeticMonths", _cosmeticMonths)
|
||||
|
@ -72,6 +72,10 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
|
||||
_allowWeatherChange = true;
|
||||
Bukkit.getWorlds().get(0).setStorm(false);
|
||||
_allowWeatherChange = false;
|
||||
|
||||
addCommand(new checkCommand(this));
|
||||
addCommand(new checkOwnsPackageCommand(this));
|
||||
addCommand(new ListPPCCommand(this, _powerPlayRepo));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -100,13 +104,6 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
|
||||
|
||||
event.setFormat(C.cGold + "%1$s " + C.cWhite + "%2$s");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
addCommand(new checkCommand(this));
|
||||
addCommand(new checkOwnsPackageCommand(this));
|
||||
}
|
||||
|
||||
public void Help(Player caller)
|
||||
{
|
||||
|
@ -0,0 +1,117 @@
|
||||
package mineplex.staffServer.customerSupport;
|
||||
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.powerplayclub.PowerPlayClubRepository;
|
||||
import mineplex.core.powerplayclub.PowerPlayClubRewards;
|
||||
import mineplex.core.powerplayclub.PowerPlayData;
|
||||
|
||||
public class ListPPCCommand extends CommandBase<CustomerSupport>
|
||||
{
|
||||
private final PowerPlayClubRepository _powerPlayRepo;
|
||||
|
||||
public ListPPCCommand(CustomerSupport customerSupport, PowerPlayClubRepository powerPlayRepo)
|
||||
{
|
||||
super(customerSupport, Rank.MODERATOR, "listppc", "checkppc");
|
||||
_powerPlayRepo = powerPlayRepo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /" + _aliasUsed + " <Player>"));
|
||||
return;
|
||||
}
|
||||
|
||||
_commandCenter.GetClientManager().checkPlayerName(caller, args[0], name ->
|
||||
{
|
||||
if (name != null)
|
||||
{
|
||||
_commandCenter.GetClientManager().loadClientByName(name, client ->
|
||||
{
|
||||
if (client == null)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(Plugin.getName(), "Could not load data for " + name));
|
||||
return;
|
||||
}
|
||||
|
||||
PowerPlayData powerPlayData = _powerPlayRepo.loadData(client.getAccountId()).join();
|
||||
Inventory inventory = buildPPCDisplay(client.getName(), powerPlayData);
|
||||
caller.openInventory(inventory);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Inventory buildPPCDisplay(String playerName, PowerPlayData data)
|
||||
{
|
||||
Inventory result = Bukkit.createInventory(null, Math.max(1, (int)Math.ceil(data.getSubscriptions().size() / 9D)) * 9, playerName + "'s Subscriptions");
|
||||
data.getSubscriptions().stream().map(sub -> buildSubDisplay(data, sub)).forEach(result::addItem);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ItemStack buildSubDisplay(PowerPlayData data, PowerPlayData.Subscription sub)
|
||||
{
|
||||
PowerPlayData dataForSubscription = PowerPlayData.fromSubsAndClaims(Collections.singletonList(sub), Collections.emptyList());
|
||||
dataForSubscription.getUnclaimedMonths().removeIf(yearMonth -> !data.getUnclaimedMonths().contains(yearMonth));
|
||||
|
||||
boolean claimed = dataForSubscription.getUnclaimedMonths().isEmpty();
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(C.cYellow + "Start date: " + C.cWhite + sub._startDate.getMonth().getDisplayName(TextStyle.SHORT, Locale.US) + " " + sub._startDate.getDayOfMonth() + " " + sub._startDate.getYear());
|
||||
lore.add(C.cYellow + "Duration: " + C.cWhite + sub._duration.name());
|
||||
lore.add(" ");
|
||||
lore.add(C.cGreen + "Subscription Cosmetics");
|
||||
PowerPlayClubRewards.rewards().entrySet().stream()
|
||||
.filter(entry -> dataForSubscription.getUsableCosmeticMonths().contains(entry.getKey()))
|
||||
.sorted(Comparator.comparing(Map.Entry::getKey))
|
||||
.forEach(entry ->
|
||||
{
|
||||
YearMonth yearMonth = entry.getKey();
|
||||
lore.add(C.cWhite + " " + entry.getValue().getPrizeName() + " " + C.cGold + yearMonth.getMonth().getDisplayName(TextStyle.SHORT, Locale.US) + " " + yearMonth.getYear());
|
||||
});
|
||||
|
||||
lore.add(" ");
|
||||
|
||||
if (claimed)
|
||||
{
|
||||
lore.add(C.cYellow + "All current rewards claimed");
|
||||
}
|
||||
else
|
||||
{
|
||||
lore.add(C.cRed + "Unclaimed rewards");
|
||||
lore.add(" " + C.cWhite + (PowerPlayClubRewards.AMPLIFIERS_PER_MONTH * dataForSubscription.getUnclaimedMonths().size()) + " Game Amplifier");
|
||||
lore.add(" " + C.cWhite + (PowerPlayClubRewards.CHESTS_PER_MONTH * dataForSubscription.getUnclaimedMonths().size()) + " Omega Chest");
|
||||
}
|
||||
|
||||
ItemStack stack = new ItemStack(claimed ? Material.IRON_BLOCK : Material.GOLD_BLOCK);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
|
||||
meta.setDisplayName(C.cWhite + "Subscription");
|
||||
meta.setLore(lore);
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user