Abstract GiveChestPage to SupportGiveItemPage

This commit is contained in:
Spencer 2018-01-06 16:43:32 -05:00 committed by Alexander Meech
parent 1094cf997e
commit 37766a8a3b

View File

@ -0,0 +1,87 @@
package mineplex.staffServer.ui.item;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClient;
import mineplex.core.shop.item.ShopItem;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.ui.SupportPage;
import mineplex.staffServer.ui.SupportShop;
public abstract class SupportGiveItemPage extends SupportPage
{
protected int _count = 1;
protected int _submitButtonSlot = getSlotIndex(3, 4);
public SupportGiveItemPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage)
{
super(plugin, shop, player, target, previousPage, "Give");
}
protected abstract String getItemName();
protected void addItemIcon()
{
addItem(getSlotIndex(2, 4), buildItemIcon());
}
protected abstract ItemStack buildItemIcon();
private ShopItem getBoundItem(String name)
{
return new ShopItem(Material.BARRIER, name, new String[0], 1, true, true);
}
private void addArrows()
{
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"));
}
}
protected void addSubmitButton()
{
addButton(_submitButtonSlot, new ShopItem(Material.EMERALD_BLOCK, "Give " + getItemName(), new String[0], 1, false, true), (p, c) -> {
giveUnknownSalesPackage(_count, getItemName(), true, (success) -> goBack());
});
}
@Override
protected void buildPage()
{
super.buildPage();
addItemIcon();
addArrows();
addSubmitButton();
}
}