add SupportChestPage and SupportGiveChestPage
This commit is contained in:
parent
5ffb9a2ae7
commit
1e610f3dac
@ -0,0 +1,131 @@
|
|||||||
|
package mineplex.staffServer.ui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.shop.item.ShopItem;
|
||||||
|
import mineplex.core.treasure.types.TreasureType;
|
||||||
|
import mineplex.staffServer.customerSupport.CustomerSupport;
|
||||||
|
|
||||||
|
public class SupportChestPage extends SupportPage
|
||||||
|
{
|
||||||
|
private static final int ELEMENTS_PER_PAGE = 28;
|
||||||
|
private int _page;
|
||||||
|
|
||||||
|
private Map<TreasureType, Integer> _treasureRecieved;
|
||||||
|
|
||||||
|
public SupportChestPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportHomePage homePage)
|
||||||
|
{
|
||||||
|
super(plugin, shop, player, target, homePage, "Chests");
|
||||||
|
|
||||||
|
_treasureRecieved = new LinkedHashMap<>();
|
||||||
|
processReceivedTreasures();
|
||||||
|
|
||||||
|
buildPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getTreasureItem(TreasureType type, List<String> lore)
|
||||||
|
{
|
||||||
|
ItemStack item = type.getItemStack().clone();
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
meta.setDisplayName(C.cGreenB + type.getItemName());
|
||||||
|
meta.setLore(lore);
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processReceivedTreasures()
|
||||||
|
{
|
||||||
|
Map<String, TreasureType> treasureNameToType = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (TreasureType type : TreasureType.values())
|
||||||
|
{
|
||||||
|
treasureNameToType.put(type.getItemName(), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Integer> ownership = getPackageOwnership(new LinkedList<>(treasureNameToType.keySet()));
|
||||||
|
|
||||||
|
ownership.forEach((treasureName, count) -> {
|
||||||
|
_treasureRecieved.put(treasureNameToType.get(treasureName), count);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildTreasure(TreasureType type, int slot)
|
||||||
|
{
|
||||||
|
int count = _treasureRecieved.computeIfAbsent(type, t -> 0);
|
||||||
|
|
||||||
|
ItemStack item = getTreasureItem(type, Arrays.asList(
|
||||||
|
C.cYellow + _target.getName() + C.mBody + " has received " + C.cYellow + count,
|
||||||
|
C.cYellow + type.getItemName() + C.mBody + ".",
|
||||||
|
"",
|
||||||
|
C.cGreen + "Click to give chests of this type"));
|
||||||
|
|
||||||
|
item.setAmount(Math.min(count, 64));
|
||||||
|
|
||||||
|
addButton(slot, item, (p, c)-> getShop().openPageForPlayer(getPlayer(), new SupportGiveChestPage(getPlugin(), getShop(), getPlayer(), _target, this, type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private LinkedList<TreasureType> getTypesSet()
|
||||||
|
{
|
||||||
|
return _treasureRecieved.keySet().stream().sorted(Comparator.comparingInt(Enum::ordinal)).collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildPage()
|
||||||
|
{
|
||||||
|
super.buildPage();
|
||||||
|
|
||||||
|
LinkedList<TreasureType> types = getTypesSet();
|
||||||
|
|
||||||
|
int slot = 10;
|
||||||
|
int startIndex = _page * ELEMENTS_PER_PAGE;
|
||||||
|
int endIndex = startIndex + ELEMENTS_PER_PAGE;
|
||||||
|
|
||||||
|
for (TreasureType type : types)
|
||||||
|
{
|
||||||
|
buildTreasure(type, slot);
|
||||||
|
|
||||||
|
if (++slot % 9 == 8)
|
||||||
|
{
|
||||||
|
slot += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_page != 0)
|
||||||
|
{
|
||||||
|
addButton(45, new ShopItem(Material.ARROW, C.cGreen + "Previous Page", new String[0], 1, false), (player, clickType) ->
|
||||||
|
{
|
||||||
|
_page--;
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex <= getTypesSet().size())
|
||||||
|
{
|
||||||
|
addButton(53, new ShopItem(Material.ARROW, C.cGreen + "Next Page", new String[0], 1, false), (player, clickType) ->
|
||||||
|
{
|
||||||
|
_page++;
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
package mineplex.staffServer.ui;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.shop.item.SalesPackageBase;
|
||||||
|
import mineplex.core.shop.item.ShopItem;
|
||||||
|
import mineplex.core.treasure.ChestPackage;
|
||||||
|
import mineplex.core.treasure.types.Treasure;
|
||||||
|
import mineplex.core.treasure.types.TreasureType;
|
||||||
|
import mineplex.staffServer.customerSupport.CustomerSupport;
|
||||||
|
|
||||||
|
public class SupportGiveChestPage extends SupportPage
|
||||||
|
{
|
||||||
|
private TreasureType _treasureType;
|
||||||
|
private int _count = 1;
|
||||||
|
|
||||||
|
public SupportGiveChestPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportChestPage chestPage, TreasureType treasureType)
|
||||||
|
{
|
||||||
|
super(plugin, shop, player, target, chestPage, "Give");
|
||||||
|
|
||||||
|
_treasureType = treasureType;
|
||||||
|
|
||||||
|
buildPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildChest()
|
||||||
|
{
|
||||||
|
ItemStack item = ((SupportChestPage) _previousPage).getTreasureItem(_treasureType, Arrays.asList(
|
||||||
|
C.cYellow + _target.getName() + C.mBody + " will receive " + C.cYellow + _count,
|
||||||
|
C.cYellow + _treasureType.getItemName() + C.mBody + "."
|
||||||
|
));
|
||||||
|
|
||||||
|
item.setAmount(Math.max(_count, 1));
|
||||||
|
|
||||||
|
addButton(getSlotIndex(2, 4), item, (p, c) -> {
|
||||||
|
SalesPackageBase salesPackage = new ChestPackage(_treasureType.getItemName(), Material.CHEST, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopItem getBoundItem(String name)
|
||||||
|
{
|
||||||
|
return new ShopItem(Material.BARRIER, name, new String[0], 1, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildArrows()
|
||||||
|
{
|
||||||
|
int minusSlot = getSlotIndex(3, 2);
|
||||||
|
if (_count > 1)
|
||||||
|
{
|
||||||
|
addButton(minusSlot,
|
||||||
|
new ShopItem(Material.ARROW, "-1", new String[0], 1, false, true),
|
||||||
|
(p, c) -> {
|
||||||
|
_count--;
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addItem(minusSlot, getBoundItem("-1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int plusSlot = getSlotIndex(3, 6);
|
||||||
|
if (_count < 64)
|
||||||
|
{
|
||||||
|
addButton(plusSlot,
|
||||||
|
new ShopItem(Material.ARROW, "+1", new String[0], 1, false, true),
|
||||||
|
(p, c) -> {
|
||||||
|
_count++;
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addItem(plusSlot, getBoundItem("+1"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildSubmitButton()
|
||||||
|
{
|
||||||
|
addButton(getSlotIndex(3, 4), new ShopItem(Material.EMERALD_BLOCK, "Give Chests", new String[0], 1, false, true), (p, c) -> {
|
||||||
|
getPlugin().getInventoryManager().addItemToInventoryForOffline((success) -> {
|
||||||
|
goBack();
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 1F, 1F);
|
||||||
|
_player.sendMessage(F.main(getPlugin().getName(), "You gave " + C.cYellow + _count + " " + _treasureType.getItemName() + C.mBody + " to " + C.cYellow + _target.getName()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1F, 1F);
|
||||||
|
_player.sendMessage(F.main(getPlugin().getName(), "Could not award treasure to " + C.cYellow + _target.getName() + C.mBody + " at this time. Please try again later."));
|
||||||
|
}
|
||||||
|
}, _target.getAccountId(), _treasureType.getItemName(), _count);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildPage()
|
||||||
|
{
|
||||||
|
super.buildPage();
|
||||||
|
|
||||||
|
buildChest();
|
||||||
|
buildArrows();
|
||||||
|
buildSubmitButton();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user