Create SupportShop and common SupportPage
This commit is contained in:
parent
31aae26bf9
commit
5ffb9a2ae7
@ -0,0 +1,152 @@
|
||||
package mineplex.staffServer.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilSkull;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.donation.Donor;
|
||||
import mineplex.core.donation.repository.token.TransactionToken;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.staffServer.customerSupport.CustomerSupport;
|
||||
|
||||
public class SupportPage extends ShopPageBase<CustomerSupport, SupportShop>
|
||||
{
|
||||
protected CoreClient _target;
|
||||
protected Donor _donor;
|
||||
protected SupportPage _previousPage;
|
||||
|
||||
public SupportPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage, String name)
|
||||
{
|
||||
super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), name + " - " + target.getName(), player);
|
||||
|
||||
_target = target;
|
||||
_donor = getPlugin().getDonationManager().Get(_target.getUniqueId());
|
||||
_previousPage = previousPage;
|
||||
}
|
||||
|
||||
public SupportPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage)
|
||||
{
|
||||
this(plugin, shop, player, target, previousPage, "Support");
|
||||
}
|
||||
|
||||
protected int getSlotIndex(int rowIndex, int columnIndex)
|
||||
{
|
||||
return (rowIndex * 9) + columnIndex;
|
||||
}
|
||||
|
||||
protected Map<String, Integer> getPackageOwnership(List<String> validNames)
|
||||
{
|
||||
Map<String, Integer> ownership = new HashMap<>();
|
||||
|
||||
for (TransactionToken transaction : _donor.getTransactions())
|
||||
{
|
||||
if (validNames.contains(transaction.SalesPackageName))
|
||||
{
|
||||
ownership.putIfAbsent(transaction.SalesPackageName, 0);
|
||||
ownership.compute(transaction.SalesPackageName, (treasureType, count) -> count + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Otherwise, try to see if everything but the last arg fits...
|
||||
String[] split = transaction.SalesPackageName.split(" ");
|
||||
|
||||
String newName = Arrays.asList(split).subList(0, split.length - 1).stream().collect(Collectors.joining(" "));
|
||||
|
||||
if (validNames.contains(newName))
|
||||
{
|
||||
int toAdd;
|
||||
try
|
||||
{
|
||||
toAdd = Integer.parseInt(split[split.length - 1]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
// nope
|
||||
continue;
|
||||
}
|
||||
|
||||
ownership.putIfAbsent(newName, 0);
|
||||
ownership.compute(newName, (treasureType, count) -> count + toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
return ownership;
|
||||
}
|
||||
|
||||
private List<String> getBasicPlayerInfo()
|
||||
{
|
||||
List<String> info = new ArrayList<>();
|
||||
|
||||
info.add("");
|
||||
info.add(C.mBody + "Rank: " + _target.getPrimaryGroup().getDisplay(true, true, true, true));
|
||||
info.addAll(UtilText.splitLine(C.mBody + "Subranks: " + C.cYellow + "(" + _target.getAdditionalGroups().size() + ") "
|
||||
+ _target.getAdditionalGroups()
|
||||
.stream()
|
||||
.map(g -> g.getDisplay(false, false, false, true).toLowerCase())
|
||||
.collect(Collectors.joining(", ")), LineFormat.LORE));
|
||||
info.add("");
|
||||
info.add(C.mBody + "Gems: " + C.cGreen + _donor.getBalance(GlobalCurrency.GEM));
|
||||
info.add(C.mBody + "Shards: " + C.cAqua + _donor.getBalance(GlobalCurrency.TREASURE_SHARD));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
private void buildPlayerSkull()
|
||||
{
|
||||
addItem(4, UtilSkull.getPlayerHead(_target.getName(), C.cGreenB + _target.getName(), getBasicPlayerInfo()));
|
||||
}
|
||||
|
||||
protected void playSuccess()
|
||||
{
|
||||
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 1F, 1F);
|
||||
}
|
||||
|
||||
protected void playFail()
|
||||
{
|
||||
_player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1F, 1F);
|
||||
}
|
||||
|
||||
protected void goBack()
|
||||
{
|
||||
getShop().openPageForPlayer(getPlayer(), _previousPage);
|
||||
}
|
||||
|
||||
private void buildBackButton()
|
||||
{
|
||||
if (_previousPage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
addButton(0, new ShopItem(Material.BED, "Go Back", new String[0], 1, false, true), (p, c)-> goBack());
|
||||
}
|
||||
|
||||
protected void message(String message)
|
||||
{
|
||||
_player.sendMessage(F.main(getPlugin().getName(), message));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
buildPlayerSkull();
|
||||
buildBackButton();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package mineplex.staffServer.ui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.staffServer.customerSupport.CustomerSupport;
|
||||
|
||||
public class SupportShop extends ShopBase<CustomerSupport>
|
||||
{
|
||||
public SupportShop(CustomerSupport plugin)
|
||||
{
|
||||
super(plugin, plugin.getClientManager(), plugin.getDonationManager(), "Support");
|
||||
}
|
||||
|
||||
public void openPageAsync(Player player, SupportPage page)
|
||||
{
|
||||
UtilServer.runAsync(() -> UtilServer.runSync(()-> super.openPageForPlayer(player, page)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<CustomerSupport, ? extends ShopBase<CustomerSupport>> buildPagesFor(Player player)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user