Update item count when giving items to players in GiveItemPage

This commit is contained in:
ArcticZeroo 2018-01-07 13:47:48 -05:00 committed by Alexander Meech
parent b1f6e5c06c
commit f470071ca0
2 changed files with 13 additions and 2 deletions

View File

@ -165,6 +165,11 @@ public class SupportPage extends ShopPageBase<CustomerSupport, SupportShop>
message("Unable to give " + C.cYellow + amount + " " + itemName + C.mBody + " to " + C.cYellow + _target.getName() + C.mBody + ", please try again later."); message("Unable to give " + C.cYellow + amount + " " + itemName + C.mBody + " to " + C.cYellow + _target.getName() + C.mBody + ", please try again later.");
} }
private void addItemsToClient(int amount, String itemName)
{
getPlugin().getInventoryManager().Get(_target.getUniqueId()).getClientItem(itemName).Count += amount;
}
protected void giveUnknownSalesPackage(int amount, String itemName, boolean isItem, Consumer<Boolean>callback) protected void giveUnknownSalesPackage(int amount, String itemName, boolean isItem, Consumer<Boolean>callback)
{ {
getPlugin().getDonationManager().purchaseUnknownSalesPackage(_target, (amount == 1 ? itemName : itemName + " " + amount), GlobalCurrency.GEM, 0, false, response -> getPlugin().getDonationManager().purchaseUnknownSalesPackage(_target, (amount == 1 ? itemName : itemName + " " + amount), GlobalCurrency.GEM, 0, false, response ->
@ -172,7 +177,7 @@ public class SupportPage extends ShopPageBase<CustomerSupport, SupportShop>
if (response == TransactionResponse.Failed || response == TransactionResponse.InsufficientFunds) if (response == TransactionResponse.Failed || response == TransactionResponse.InsufficientFunds)
{ {
giveFailed(amount, itemName); giveFailed(amount, itemName);
callback.accept(true); callback.accept(false);
} }
else if (response == TransactionResponse.Success) else if (response == TransactionResponse.Success)
{ {
@ -183,6 +188,7 @@ public class SupportPage extends ShopPageBase<CustomerSupport, SupportShop>
if (success) if (success)
{ {
giveSuccess(amount, itemName); giveSuccess(amount, itemName);
addItemsToClient(amount, itemName);
callback.accept(true); callback.accept(true);
} }
else else
@ -195,6 +201,7 @@ public class SupportPage extends ShopPageBase<CustomerSupport, SupportShop>
else else
{ {
giveSuccess(amount, itemName); giveSuccess(amount, itemName);
addItemsToClient(amount, itemName);
callback.accept(true); callback.accept(true);
} }
} }

View File

@ -75,7 +75,11 @@ public abstract class SupportGiveItemPage extends SupportPage
protected void addSubmitButton() protected void addSubmitButton()
{ {
addButton(_submitButtonSlot, new ShopItem(_count > 0 ? Material.EMERALD_BLOCK : Material.REDSTONE_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()); giveUnknownSalesPackage(_count, getItemName(), true, (success) ->
{
_previousPage.refresh();
goBack();
});
}); });
} }