Add support for custom lower and upper bounds in GiveItemPage, do that in Chest

This commit is contained in:
Spencer 2018-01-07 00:07:46 -05:00 committed by Alexander Meech
parent 1fbd8031ed
commit 56122d0b9b
2 changed files with 9 additions and 4 deletions

View File

@ -21,6 +21,8 @@ public class SupportGiveChestPage extends SupportGiveItemPage
super(plugin, shop, player, target, chestPage);
_treasureType = treasureType;
_lowerBound = -100;
_upperBound = 100;
buildPage();
}
@ -39,7 +41,8 @@ public class SupportGiveChestPage extends SupportGiveItemPage
C.cYellow + _treasureType.getItemName() + C.mBody + "."
));
item.setAmount(Math.max(_count, 1));
// Clamp between 1 and 64 always
item.setAmount(Math.min(Math.max(Math.abs(_count), 1), 64));
return item;
}

View File

@ -13,6 +13,8 @@ import mineplex.staffServer.ui.SupportShop;
public abstract class SupportGiveItemPage extends SupportPage
{
protected int _count = 1;
protected int _lowerBound = 1;
protected int _upperBound = 64;
protected int _submitButtonSlot = getSlotIndex(3, 4);
@ -38,7 +40,7 @@ public abstract class SupportGiveItemPage extends SupportPage
private void addArrows()
{
int minusSlot = getSlotIndex(3, 2);
if (_count > 1)
if (_count > _lowerBound)
{
addButton(minusSlot,
new ShopItem(Material.ARROW, "-1", new String[0], 1, false, true),
@ -53,7 +55,7 @@ public abstract class SupportGiveItemPage extends SupportPage
}
int plusSlot = getSlotIndex(3, 6);
if (_count < 64)
if (_count < _upperBound)
{
addButton(plusSlot,
new ShopItem(Material.ARROW, "+1", new String[0], 1, false, true),
@ -70,7 +72,7 @@ public abstract class SupportGiveItemPage extends SupportPage
protected void addSubmitButton()
{
addButton(_submitButtonSlot, new ShopItem(Material.EMERALD_BLOCK, "Give " + getItemName(), new String[0], 1, false, true), (p, c) -> {
addButton(_submitButtonSlot, new ShopItem(_count > 0 ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK, "Give " + getItemName(), new String[0], 1, false, true), (p, c) -> {
giveUnknownSalesPackage(_count, getItemName(), true, (success) -> goBack());
});
}