Use new GiveItemPage in GiveChestPage,add GivePackagePage

This commit is contained in:
Spencer 2018-01-06 16:43:48 -05:00 committed by Alexander Meech
parent 37766a8a3b
commit 94a525c5b4
2 changed files with 59 additions and 81 deletions

View File

@ -2,37 +2,37 @@ package mineplex.staffServer.ui.chest;
import java.util.Arrays;
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.TreasureType;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.ui.SupportPage;
import mineplex.staffServer.ui.SupportShop;
import mineplex.staffServer.ui.item.SupportGiveItemPage;
public class SupportGiveChestPage extends SupportPage
public class SupportGiveChestPage extends SupportGiveItemPage
{
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");
super(plugin, shop, player, target, chestPage);
_treasureType = treasureType;
buildPage();
}
private void buildChest()
@Override
protected String getItemName()
{
return _treasureType.getItemName();
}
@Override
protected ItemStack buildItemIcon()
{
ItemStack item = ((SupportChestPage) _previousPage).getTreasureItem(_treasureType, Arrays.asList(
C.cYellow + _target.getName() + C.mBody + " will receive " + C.cYellow + _count,
@ -41,75 +41,6 @@ public class SupportGiveChestPage extends SupportPage
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();
return item;
}
}

View File

@ -0,0 +1,47 @@
package mineplex.staffServer.ui.packages;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.ui.SupportPage;
import mineplex.staffServer.ui.SupportShop;
import mineplex.staffServer.ui.item.SupportGiveItemPage;
public class SupportGivePackagePage extends SupportGiveItemPage
{
private ItemBuilder _builder;
private String _salesPackage;
public SupportGivePackagePage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage, ItemBuilder item, String salesPackage)
{
super(plugin, shop, player, target, previousPage);
_builder = item;
_salesPackage = salesPackage;
buildPage();
}
@Override
protected String getItemName()
{
return _salesPackage;
}
@Override
protected ItemStack buildItemIcon()
{
return _builder
// 1 - 64
.setAmount(Math.min(Math.max(_count, 1), 64))
.setLore(
C.cYellow + _target.getName() + C.mBody + " will receive " + C.cYellow + _count,
C.cYellow + getItemName() + C.mBody + "."
)
.build();
}
}