From 468930a35e0b06ddc16cb8237187d494600868f0 Mon Sep 17 00:00:00 2001 From: Spencer Date: Sat, 6 Jan 2018 15:09:11 -0500 Subject: [PATCH] add giveUnkownSalesPackage method to SupportPage --- .../mineplex/staffServer/ui/SupportPage.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/SupportPage.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/SupportPage.java index 39d295fea..3de292255 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/SupportPage.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/ui/SupportPage.java @@ -23,6 +23,7 @@ import mineplex.core.common.util.UtilText; import mineplex.core.donation.DonationManager; import mineplex.core.donation.Donor; import mineplex.core.donation.repository.token.TransactionToken; +import mineplex.core.server.util.TransactionResponse; import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ShopPageBase; import mineplex.staffServer.customerSupport.CustomerSupport; @@ -156,6 +157,62 @@ public class SupportPage extends ShopPageBase _player.sendMessage(F.main(getPlugin().getName(), message)); } + private void giveSuccess(int amount, String itemName) + { + message("Gave " + C.cYellow + amount + " " + itemName + C.mBody + " to " + C.cYellow + _target.getName()); + } + + private void giveFailed(int amount, String itemName) + { + message("Unable to give " + C.cYellow + amount + " " + itemName + C.mBody + " to " + C.cYellow + _target.getName() + C.mBody + ", please try again later."); + } + + protected void giveUnknownSalesPackage(int amount, String itemName, boolean isItem) + { + getPlugin().getDonationManager().purchaseUnknownSalesPackage(_target, (amount == 1 ? itemName : itemName + " " + amount), GlobalCurrency.GEM, 0, false, response -> + { + if (response == TransactionResponse.Failed || response == TransactionResponse.InsufficientFunds) + { + giveFailed(amount, itemName); + } + else if (response == TransactionResponse.Success) + { + if (isItem) + { + getPlugin().getInventoryManager().addItemToInventoryForOffline(success -> + { + if (success) + { + giveSuccess(amount, itemName); + } + else + { + giveFailed(amount, itemName); + } + }, _target.getAccountId(), itemName, amount); + } + else + { + giveSuccess(amount, itemName); + } + } + else if (response == TransactionResponse.AlreadyOwns) + { + message(C.cYellow + _target.getName() + C.mBody + " already owns " + C.cYellow + itemName); + } + }); + } + + protected void giveUnknownSalesPackage(String itemName, boolean isItem) + { + giveUnknownSalesPackage(1, itemName, isItem); + } + + protected void giveUnknownSalesPackage(String itemName) + { + giveUnknownSalesPackage(itemName, false); + } + @Override protected void buildPage() {