From 37766a8a3bdc55d6df1e4b9fb01415695788c07c Mon Sep 17 00:00:00 2001 From: Spencer Date: Sat, 6 Jan 2018 16:43:32 -0500 Subject: [PATCH] Abstract GiveChestPage to SupportGiveItemPage --- .../ui/item/SupportGiveItemPage.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/item/SupportGiveItemPage.java diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/item/SupportGiveItemPage.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/item/SupportGiveItemPage.java new file mode 100644 index 000000000..b6a18709e --- /dev/null +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/item/SupportGiveItemPage.java @@ -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(); + } +}