From 3cddf35d1222f53e8e6fac385d4e095e0bc22c5a Mon Sep 17 00:00:00 2001 From: cnr Date: Mon, 25 Jul 2016 21:57:24 -0500 Subject: [PATCH] Refactor out legacy ConfirmationPage --- .../core/boosters/BoosterProcessor.java | 4 + .../core/boosters/gui/BoosterPage.java | 4 +- .../gui/button/FountainAddButton.java | 16 +- .../core/cosmetic/ui/button/MountButton.java | 16 +- .../core/cosmetic/ui/page/GadgetPage.java | 14 +- .../core/cosmetic/ui/page/PetTagPage.java | 68 ++-- .../core/donation/DonationManager.java | 22 ++ .../shop/confirmation/ConfirmationPage.java | 16 +- .../confirmation/ConfirmationProcessor.java | 3 + .../core/shop/item/ICurrencyPackage.java | 4 +- .../core/shop/item/SalesPackageBase.java | 12 +- .../core/shop/item/SalesPackageProcessor.java | 97 ++++++ .../core/shop/page/ConfirmationPage.java | 324 ------------------ .../core/treasure/gui/BuyChestButton.java | 15 +- .../game/clans/shop/energy/EnergyPackage.java | 17 - .../clans/shop/energy/EnergyShopButton.java | 10 +- .../game/classcombat/shop/page/SkillPage.java | 21 +- .../game/arcade/kit/ProgressingKit.java | 10 +- 18 files changed, 229 insertions(+), 444 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/shop/item/SalesPackageProcessor.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPackage.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterProcessor.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterProcessor.java index 0cc567715..23ae2e6eb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterProcessor.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterProcessor.java @@ -6,6 +6,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.shop.confirmation.ConfirmationCallback; import mineplex.core.shop.confirmation.ConfirmationProcessor; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; /** * @author Shaun Bennett @@ -21,6 +22,9 @@ public class BoosterProcessor implements ConfirmationProcessor _player = player; } + @Override + public void init(Inventory inventory) {} + @Override public void process(ConfirmationCallback callback) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java index 3a6315ec9..9e4ae655f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java @@ -4,7 +4,6 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.boosters.Booster; import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterProcessor; -import mineplex.core.common.Pair; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilTime; import mineplex.core.donation.DonationManager; @@ -115,8 +114,7 @@ public class BoosterPage extends ShopPageBase ShopItem booster = new ShopItem(Material.SUGAR, "Game Amplifier", lore.toArray(new String[0]), 0, false, false); BoosterProcessor processor = new BoosterProcessor(getPlugin(), getPlayer()); - ConfirmationPage page = new ConfirmationPage<>(getPlugin(), getShop(), - getClientManager(), getDonationManager(), getPlayer(), this, processor, booster); + ConfirmationPage page = new ConfirmationPage<>(getPlayer(), this, processor, booster); getShop().openPageForPlayer(getPlayer(), page); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java index 622b44add..3dcc6ebd7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/button/FountainAddButton.java @@ -1,13 +1,12 @@ package mineplex.core.brawl.fountain.gui.button; -import mineplex.core.brawl.fountain.FountainManager; import mineplex.core.brawl.fountain.GemFountainSalesPackage; import mineplex.core.brawl.fountain.gui.FountainPage; -import mineplex.core.brawl.fountain.gui.FountainShop; import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.shop.confirmation.ConfirmationPage; import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.SalesPackageBase; -import mineplex.core.shop.page.ConfirmationPage; +import mineplex.core.shop.item.SalesPackageProcessor; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -30,13 +29,10 @@ public class FountainAddButton implements IButton @Override public void onClick(Player player, ClickType clickType) { - _page.getShop().openPageForPlayer(player, new ConfirmationPage(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable() + _page.getShop().openPageForPlayer(player, new ConfirmationPage<>(player, _page, new SalesPackageProcessor(player, GlobalCurrency.GEM, _salesPackage, _page.getDonationManager(), () -> { - public void run() - { - _page.getPlugin().getGemFountain().increment(player, _gems, null); - _page.refresh(); - } - }, _page, _salesPackage, GlobalCurrency.GEM, player)); + _page.getPlugin().getGemFountain().increment(player, _gems, null); + _page.refresh(); + }), _salesPackage.buildIcon())); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/MountButton.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/MountButton.java index e60b042f5..3d1039572 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/MountButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/MountButton.java @@ -1,12 +1,11 @@ package mineplex.core.cosmetic.ui.button; import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.cosmetic.CosmeticManager; -import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.cosmetic.ui.page.MountPage; import mineplex.core.mount.Mount; +import mineplex.core.shop.confirmation.ConfirmationPage; import mineplex.core.shop.item.IButton; -import mineplex.core.shop.page.ConfirmationPage; +import mineplex.core.shop.item.SalesPackageProcessor; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -24,13 +23,10 @@ public class MountButton implements IButton @Override public void onClick(final Player player, ClickType clickType) { - _page.getShop().openPageForPlayer(player, new ConfirmationPage(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable() + _page.getShop().openPageForPlayer(player, new ConfirmationPage<>(player, _page, new SalesPackageProcessor(player, GlobalCurrency.TREASURE_SHARD, _mount, _page.getDonationManager(), () -> { - public void run() - { - _page.getPlugin().getInventoryManager().addItemToInventory(null, player, _mount.getName(), 1); - _page.refresh(); - } - }, _page, _mount, GlobalCurrency.TREASURE_SHARD, player)); + _page.getPlugin().getInventoryManager().addItemToInventory(null, player, _mount.getName(), 1); + _page.refresh(); + }), _mount.buildIcon())); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java index 19c2f2a8c..cd40f9b06 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java @@ -19,9 +19,10 @@ import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.HatGadget; import mineplex.core.gadget.types.ItemGadget; +import mineplex.core.shop.confirmation.ConfirmationPage; import mineplex.core.shop.item.IButton; +import mineplex.core.shop.item.SalesPackageProcessor; import mineplex.core.shop.item.ShopItem; -import mineplex.core.shop.page.ConfirmationPage; import mineplex.core.shop.page.ShopPageBase; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -371,14 +372,11 @@ public class GadgetPage extends ShopPageBase UtilPlayer.message(player, F.main("Disguise", "You cant buy things while you are disguised!")); return; } - getShop().openPageForPlayer(getPlayer(), new ConfirmationPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), new Runnable() + getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(player, this, new SalesPackageProcessor(player, GlobalCurrency.TREASURE_SHARD, gadget, getDonationManager(), () -> { - public void run() - { - getPlugin().getInventoryManager().addItemToInventory(getPlayer(), gadget.getName(), (gadget instanceof ItemGadget ? ((ItemGadget) gadget).getAmmo().getQuantity() : gadget.getQuantity())); - refresh(); - } - }, this, (gadget instanceof ItemGadget ? ((ItemGadget) gadget).getAmmo() : gadget), GlobalCurrency.TREASURE_SHARD, getPlayer())); + getPlugin().getInventoryManager().addItemToInventory(getPlayer(), gadget.getName(), (gadget instanceof ItemGadget ? ((ItemGadget) gadget).getAmmo().getQuantity() : gadget.getQuantity())); + refresh(); + }), gadget.buildIcon())); } public void activateGadget(Player player, Gadget gadget) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java index 63079412e..0a5c568fa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java @@ -15,7 +15,9 @@ import mineplex.core.pet.Pet; import mineplex.core.pet.PetExtra; import mineplex.core.pet.repository.token.PetChangeToken; import mineplex.core.pet.repository.token.PetToken; -import mineplex.core.shop.page.ConfirmationPage; +import mineplex.core.shop.confirmation.ConfirmationPage; +import mineplex.core.shop.item.SalesPackageBase; +import mineplex.core.shop.item.SalesPackageProcessor; import mineplex.core.shop.page.ShopPageBase; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.Items; @@ -92,44 +94,42 @@ public class PetTagPage extends ShopPageBase } PetExtra tag = new PetExtra("Rename " + _pet.getName() + " to " + _tagName, Material.NAME_TAG, 100); + final SalesPackageBase salesPackage = _petPurchase ? _pet : tag; _pet.setDisplayName(C.cGreen + "Purchase " + _tagName); - - getShop().openPageForPlayer(getPlayer(), new ConfirmationPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), new Runnable() + + getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(_player, this, new SalesPackageProcessor(_player, GlobalCurrency.TREASURE_SHARD, salesPackage, _donationManager, () -> { - public void run() + PetChangeToken token = new PetChangeToken(); + + if (getClientManager().Get(getPlayer()) != null) + token.AccountId = getClientManager().Get(getPlayer()).getAccountId(); + else + token.AccountId = PlayerCache.getInstance().getPlayer(getPlayer().getUniqueId()).getAccountId(); + + token.Name = getPlayer().getName(); + token.PetType = _pet.getPetType().toString(); + token.PetId = _pet.getPetType().ordinal(); + token.PetName = _tagName; + + PetToken petToken = new PetToken(); + petToken.PetType = token.PetType; + + if (_petPurchase) { - PetChangeToken token = new PetChangeToken(); - - if (getClientManager().Get(getPlayer()) != null) - token.AccountId = getClientManager().Get(getPlayer()).getAccountId(); - else - token.AccountId = PlayerCache.getInstance().getPlayer(getPlayer().getUniqueId()).getAccountId(); - - token.Name = getPlayer().getName(); - token.PetType = _pet.getPetType().toString(); - token.PetId = _pet.getPetType().ordinal(); - token.PetName = _tagName; - - PetToken petToken = new PetToken(); - petToken.PetType = token.PetType; - - if (_petPurchase) - { - getPlugin().getPetManager().getRepository().AddPet(token); - getPlugin().getPetManager().addPetOwnerToQueue(getPlayer().getName(), _pet.getPetType()); - } - else - { - getPlugin().getPetManager().getRepository().UpdatePet(token); - getPlugin().getPetManager().addRenamePetToQueue(getPlayer().getName(), token.PetName); - } - - getPlugin().getPetManager().Get(getPlayer()).getPets().put(_pet.getPetType(), token.PetName); - - getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer())); + getPlugin().getPetManager().getRepository().AddPet(token); + getPlugin().getPetManager().addPetOwnerToQueue(getPlayer().getName(), _pet.getPetType()); } - }, null, _petPurchase ? _pet : tag, GlobalCurrency.TREASURE_SHARD, getPlayer())); + else + { + getPlugin().getPetManager().getRepository().UpdatePet(token); + getPlugin().getPetManager().addRenamePetToQueue(getPlayer().getName(), token.PetName); + } + + getPlugin().getPetManager().Get(getPlayer()).getPets().put(_pet.getPetType(), token.PetName); + + getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer())); + }), salesPackage.buildIcon())); } public void SetTagName(String tagName) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 4cbab4787..206d245be 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -112,6 +112,28 @@ public class DonationManager extends MiniClientPlugin }, name, accountId, packageName, currencyType, cost); } + public void PurchaseKnownSalesPackage(final Callback callback, final String name, final UUID uuid, final int cost, final int salesPackageId) + { + _repository.PurchaseKnownSalesPackage(new Callback() + { + public void run(TransactionResponse response) + { + if (response == TransactionResponse.Success) + { + Donor donor = Get(name); + + if (donor != null) + { + donor.AddSalesPackagesOwned(salesPackageId); + } + } + + if (callback != null) + callback.run(response); + } + }, name, uuid.toString(), cost, salesPackageId); + } + public void RewardGems(Callback callback, String caller, String name, UUID uuid, int amount) { RewardGems(callback, caller, name, uuid, amount, true); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/confirmation/ConfirmationPage.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/confirmation/ConfirmationPage.java index 5bcdcfb82..67a43b2e8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/confirmation/ConfirmationPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/confirmation/ConfirmationPage.java @@ -31,11 +31,21 @@ public class ConfirmationPage returnPage, ConfirmationProcessor processor, ItemStack displayItem) + public ConfirmationPage(Player player, ShopPageBase returnPage, ConfirmationProcessor processor, ItemStack displayItem) + { + super(returnPage.getPlugin(), returnPage.getShop(), returnPage.getClientManager(), returnPage.getDonationManager(), "Confirmation", player); + + _returnPage = returnPage; + _displayItem = displayItem; + _processor = processor; + + buildPage(); + } + + public ConfirmationPage(Player player, PluginType plugin, ShopType shop, CoreClientManager clientManager, DonationManager donationManager, ConfirmationProcessor processor, ItemStack displayItem) { super(plugin, shop, clientManager, donationManager, "Confirmation", player); - _returnPage = returnPage; _displayItem = displayItem; _processor = processor; @@ -49,6 +59,8 @@ public class ConfirmationPage CurrencyCostMap; + protected NautHashMap CurrencyCostMap; protected boolean KnownPackage = true; protected boolean OneTimePurchaseOnly = true; @@ -65,7 +66,7 @@ public abstract class SalesPackageBase implements ICurrencyPackage, IDisplayPack } @Override - public int getCost(Currency currencyType) + public int getCost(GlobalCurrency currencyType) { return CurrencyCostMap.containsKey(currencyType) ? CurrencyCostMap.get(currencyType) : 0; } @@ -130,4 +131,9 @@ public abstract class SalesPackageBase implements ICurrencyPackage, IDisplayPack { DisplayName = name; } + + public ItemStack buildIcon() + { + return new ItemBuilder(_displayMaterial).setData(_displayData).setTitle(DisplayName).addLore(Description).build(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/SalesPackageProcessor.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/SalesPackageProcessor.java new file mode 100644 index 000000000..d7c75985f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/SalesPackageProcessor.java @@ -0,0 +1,97 @@ +package mineplex.core.shop.item; + +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.server.util.TransactionResponse; +import mineplex.core.shop.confirmation.ConfirmationCallback; +import mineplex.core.shop.confirmation.ConfirmationProcessor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +public class SalesPackageProcessor implements ConfirmationProcessor { + /* + int goldCount = _donationManager.Get(_player).getGold(); + int cost = _salesItem.getCost(_currencyType); + + if (cost > goldCount) + showResultsPage(TransactionResponse.InsufficientFunds); + else + { + _donationManager.rewardGold(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + showResultsPage(TransactionResponse.Success); + _player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f); + } + else + { + showResultsPage(TransactionResponse.Failed); + } + } + }, "Energy Purchase", _player.getName(), getClientManager().Get(_player).getAccountId(), -cost); + + } + */ + private final GlobalCurrency _currencyType; + private final SalesPackageBase _salesItem; + private final DonationManager _donationManager; + private final Player _player; + private final Runnable _runAfterPurchase; + + public SalesPackageProcessor(Player player, GlobalCurrency currencyType, SalesPackageBase salesItem, DonationManager donationManager, Runnable runAfterPurchase) + { + _currencyType = currencyType; + _salesItem = salesItem; + _donationManager = donationManager; + _player = player; + _runAfterPurchase = runAfterPurchase; + } + + @Override + public void init(Inventory inventory) + { + inventory.setItem(4, new ItemBuilder(_currencyType.getDisplayMaterial()).setTitle(_currencyType.getPrefix()).addLore(C.cGray + _salesItem.getCost(_currencyType) + " " + _currencyType.getPrefix() + " will be", C.cGray + "deducted from your account balance").build()); + } + + @Override + public void process(ConfirmationCallback callback) + { + if (_salesItem.isKnown()) + { + _donationManager.PurchaseKnownSalesPackage(response -> showResults(callback, response), _player.getName(), _player.getUniqueId(), _salesItem.getCost(_currencyType), _salesItem.getSalesPackageId()); + } + else + { + _donationManager.PurchaseUnknownSalesPackage(response -> showResults(callback, response), _player.getName(), _donationManager.getClientManager().Get(_player).getAccountId(), _salesItem.getName(), _currencyType, _salesItem.getCost(_currencyType), _salesItem.oneTimePurchase()); + } + } + + private void showResults(ConfirmationCallback callback, TransactionResponse response) + { + switch (response) + { + case Failed: + callback.reject("There was an error processing your request."); + break; + case AlreadyOwns: + callback.reject("You already own this package."); + break; + case InsufficientFunds: + callback.reject("Your account has insufficient funds."); + break; + case Success: + callback.resolve("Your purchase was successful."); + + if (_runAfterPurchase != null) + _runAfterPurchase.run(); + + break; + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java deleted file mode 100644 index f388caf9c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java +++ /dev/null @@ -1,324 +0,0 @@ -package mineplex.core.shop.page; - -import mineplex.core.MiniPlugin; -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.currency.Currency; -import mineplex.core.common.util.C; -import mineplex.core.donation.DonationManager; -import mineplex.core.server.util.TransactionResponse; -import mineplex.core.shop.ShopBase; -import mineplex.core.shop.item.IButton; -import mineplex.core.shop.item.SalesPackageBase; -import mineplex.core.shop.item.ShopItem; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -public class ConfirmationPage> extends ShopPageBase implements Runnable -{ - private Runnable _runnable; - private ShopPageBase _returnPage; - private SalesPackageBase _salesItem; - private int _okSquareSlotStart; - private boolean _processing; - private int _progressCount; - private ShopItem _progressItem; - private int _taskId; - private final Currency _currencyType; - - public ConfirmationPage(PluginType plugin, ShopType shop, CoreClientManager clientManager, DonationManager donationManager, Runnable runnable, ShopPageBase returnPage, SalesPackageBase salesItem, Currency currencyType, Player player) - { - super(plugin, shop, clientManager, donationManager, " Confirmation", player); - - _runnable = runnable; - _returnPage = returnPage; - _salesItem = salesItem; - _progressItem = new ShopItem(Material.LAPIS_BLOCK, (byte)11, ChatColor.BLUE + "Processing", null, 1, false, true); - _okSquareSlotStart = 27; - _currencyType = currencyType; - - if (getShop().canPlayerAttemptPurchase(player)) - { - buildPage(); - } - else - { - buildErrorPage(new String[]{ChatColor.RED + "You have attempted too many invalid transactions.", ChatColor.RED + "Please wait 10 seconds before retrying."}); - _taskId = plugin.getScheduler().scheduleSyncRepeatingTask(plugin.getPlugin(), this, 2L, 2L); - } - } - - protected void buildPage() - { - this.getInventory().setItem(22, new ShopItem(_salesItem.getDisplayMaterial(), (byte)0, _salesItem.getDisplayName(), _salesItem.getDescription(), 1, false, true).getHandle()); - - IButton okClicked = new IButton() - { - @Override - public void onClick(Player player, ClickType clickType) - { - okClicked(player); - } - }; - - IButton cancelClicked = new IButton() - { - @Override - public void onClick(Player player, ClickType clickType) - { - cancelClicked(player); - } - }; - - buildSquareAt(_okSquareSlotStart, new ShopItem(Material.EMERALD_BLOCK, (byte) 0, ChatColor.GREEN + "OK", null, 1, false, true), okClicked); - buildSquareAt(_okSquareSlotStart + 6, new ShopItem(Material.REDSTONE_BLOCK, (byte) 0, ChatColor.RED + "CANCEL", null, 1, false, true), cancelClicked); - - this.getInventory().setItem(4, new ShopItem(_currencyType.getDisplayMaterial(), (byte)0, _currencyType.getPrefix(), new String[] { C.cGray + _salesItem.getCost(_currencyType) + " " + _currencyType.getPrefix() + " will be", C.cGray + "deducted from your account balance." }, 1, false, true).getHandle()); - } - - protected void okClicked(Player player) - { - processTransaction(); - } - - protected void cancelClicked(Player player) - { - getPlugin().getScheduler().cancelTask(_taskId); - - if (_returnPage != null) - getShop().openPageForPlayer(player, _returnPage); - else - { - player.closeInventory(); - } - - } - - private void buildSquareAt(int slot, ShopItem item, IButton button) - { - addButton(slot, item, button); - addButton(slot + 1, item, button); - addButton(slot + 2, item, button); - - slot += 9; - - addButton(slot, item, button); - addButton(slot + 1, item, button); - addButton(slot + 2, item, button); - - slot += 9; - - addButton(slot, item, button); - addButton(slot + 1, item, button); - addButton(slot + 2, item, button); - } - - private void processTransaction() - { - for (int i=_okSquareSlotStart; i < 54; i++) - { - getButtonMap().remove(i); - clear(i); - } - - /*_processing = true; - - if (_currencyType == GlobalCurrency.GOLD) - { - int goldCount = getDonationManager().Get(getPlayer()).getGold(); - int cost = _salesItem.getCost(_currencyType); - - if (cost > goldCount) - showResultsPage(TransactionResponse.InsufficientFunds); - else - { - getDonationManager().rewardGold(new Callback() - { - @Override - public void run(Boolean data) - { - if (data) - { - showResultsPage(TransactionResponse.Success); - getPlayer().playSound(getPlayer().getLocation(), Sound.LEVEL_UP, 2f, 1.5f); - } - else - { - showResultsPage(TransactionResponse.Failed); - } - } - }, "Energy Purchase", getPlayer().getName(), getClientManager().Get(getPlayer()).getAccountId(), -cost); - - } - - } - else - { - if (_salesItem.isKnown()) - { - getDonationManager().PurchaseKnownSalesPackage(new Callback() - { - public void run(TransactionResponse response) - { - showResultsPage(response); - } - }, getPlayer().getName(), getPlayer().getUniqueId(), _salesItem.getCost(_currencyType), _salesItem.getSalesPackageId()); - } - else - { - getDonationManager().PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse response) - { - showResultsPage(response); - } - }, getPlayer().getName(), getClientManager().Get(getPlayer()).getAccountId(), _salesItem.getName(), _currencyType, _salesItem.getCost(_currencyType), _salesItem.oneTimePurchase()); - } - } - - _taskId = getPlugin().getScheduler().scheduleSyncRepeatingTask(getPlugin().getPlugin(), this, 2L, 2L);*/ - // TODO - } - - private void showResultsPage(TransactionResponse response) - { - _processing = false; - - switch (response) - { - case Failed: - buildErrorPage(ChatColor.RED + "There was an error processing your request."); - getShop().addPlayerProcessError(getPlayer()); - break; - case AlreadyOwns: - buildErrorPage(ChatColor.RED + "You already own this package."); - getShop().addPlayerProcessError(getPlayer()); - break; - case InsufficientFunds: - buildErrorPage(ChatColor.RED + "Your account has insufficient funds."); - getShop().addPlayerProcessError(getPlayer()); - break; - case Success: - buildSuccessPage("Your purchase was successful."); - - if (_runnable != null) - _runnable.run(); - - break; - default: - break; - } - - _progressCount = 0; - } - - private void buildErrorPage(String... message) - { - IButton returnButton = new IButton() - { - @Override - public void onClick(Player player, ClickType clickType) - { - cancelClicked(player); - } - }; - - ShopItem item = new ShopItem(Material.REDSTONE_BLOCK, (byte)0, ChatColor.RED + "" + ChatColor.UNDERLINE + "ERROR", message, 1, false, true); - for (int i = 0; i < this.getSize(); i++) - { - addButton(i, item, returnButton); - } - - getPlayer().playSound(getPlayer().getLocation(), Sound.BLAZE_DEATH, 1, .1f); - } - - private void buildSuccessPage(String message) - { - IButton returnButton = new IButton() - { - @Override - public void onClick(Player player, ClickType clickType) - { - cancelClicked(player); - } - }; - - ShopItem item = new ShopItem(Material.EMERALD_BLOCK, (byte)0, ChatColor.GREEN + message, null, 1, false, true); - for (int i = 0; i < this.getSize(); i++) - { - addButton(i, item, returnButton); - } - - getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, .9f); - } - - @Override - public void playerClosed() - { - super.playerClosed(); - - Bukkit.getScheduler().cancelTask(_taskId); - - if (_returnPage != null && getShop() != null) - getShop().setCurrentPageForPlayer(getPlayer(), _returnPage); - } - - @Override - public void run() - { - if (_processing) - { - if (_progressCount == 9) - { - for (int i=45; i < 54; i++) - { - clear(i); - } - - _progressCount = 0; - } - - setItem(45 + _progressCount, _progressItem); - } - else - { - if (_progressCount >= 20) - { - try - { - Bukkit.getScheduler().cancelTask(_taskId); - - if (_returnPage != null && getShop() != null) - { - getShop().openPageForPlayer(getPlayer(), _returnPage); - } - else if (getPlayer() != null) - { - getPlayer().closeInventory(); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - dispose(); - } - } - } - - _progressCount++; - } - - @Override - public void dispose() - { - super.dispose(); - - Bukkit.getScheduler().cancelTask(_taskId); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java index 4dbb912a9..2d7203f06 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java @@ -4,8 +4,10 @@ import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.inventory.InventoryManager; +import mineplex.core.shop.confirmation.ConfirmationPage; import mineplex.core.shop.item.IButton; -import mineplex.core.shop.page.ConfirmationPage; +import mineplex.core.shop.item.SalesPackageBase; +import mineplex.core.shop.item.SalesPackageProcessor; import mineplex.core.treasure.ChestPackage; import mineplex.core.treasure.TreasureType; import org.bukkit.Material; @@ -63,10 +65,11 @@ public class BuyChestButton implements IButton UtilPlayer.message(player, F.main("Disguise", "You cant buy things while you are disguised!")); return; } - _page.getShop().openPageForPlayer(player, new ConfirmationPage<>( - _page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), () -> { - _inventoryManager.addItemToInventory(player, _chestName, 1); - _page.refresh(); - }, _page, new ChestPackage(_chestName, _chestMat, _chestCost), GlobalCurrency.TREASURE_SHARD, player)); + SalesPackageBase salesPackage = new ChestPackage(_chestName, _chestMat, _chestCost); + _page.getShop().openPageForPlayer(player, new ConfirmationPage<>(player, _page, new SalesPackageProcessor(player, GlobalCurrency.TREASURE_SHARD, salesPackage, _page.getDonationManager(), () -> + { + _inventoryManager.addItemToInventory(player, _chestName, 1); + _page.refresh(); + }), salesPackage.buildIcon())); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPackage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPackage.java deleted file mode 100644 index ba5a9ded0..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPackage.java +++ /dev/null @@ -1,17 +0,0 @@ -package mineplex.game.clans.shop.energy; - -import mineplex.core.shop.item.SalesPackageBase; -import mineplex.game.clans.economy.ClansCurrency; -import org.bukkit.ChatColor; -import org.bukkit.Material; - -public class EnergyPackage extends SalesPackageBase -{ - public EnergyPackage(String name, int cost) - { - super(name, Material.REDSTONE, " ", ChatColor.RESET + "Clan Energy"); - CurrencyCostMap.put(ClansCurrency.GOLD, cost); - KnownPackage = false; - OneTimePurchaseOnly = false; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShopButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShopButton.java index 35e4c5979..cea8d672a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShopButton.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShopButton.java @@ -1,13 +1,10 @@ package mineplex.game.clans.shop.energy; -import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; import mineplex.core.shop.item.IButton; -import mineplex.core.shop.page.ConfirmationPage; import mineplex.game.clans.clans.ClanEnergyManager; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.event.PreEnergyShopBuyEvent; -import mineplex.game.clans.economy.ClansCurrency; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -35,8 +32,8 @@ public class EnergyShopButton implements IButton { return; } - - _page.getShop().openPageForPlayer(player, new ConfirmationPage( + + /*_page.getShop().openPageForPlayer(player, new ConfirmationPage( _page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable() { public void run() @@ -56,7 +53,8 @@ public class EnergyShopButton implements IButton // Notify _energyManager.getClansManager().messageClan(_clanInfo, F.main("Energy", F.name(player.getName()) + " purchased " + F.elem(_energyToPurchase + " Energy") + " for the clan")); } - }, _page, new EnergyPackage(_energyToPurchase + " Energy", _cost), ClansCurrency.GOLD, player)); + }, _page, new EnergyPackage(_energyToPurchase + " Energy", _cost), ClansCurrency.GOLD, player));*/ + // TODO } diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/page/SkillPage.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/page/SkillPage.java index 08dd9397e..90eac4190 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/page/SkillPage.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/page/SkillPage.java @@ -6,8 +6,9 @@ import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; import mineplex.core.donation.DonationManager; import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.shop.item.SalesPackageBase; +import mineplex.core.shop.item.SalesPackageProcessor; import mineplex.core.shop.item.ShopItem; -import mineplex.core.shop.page.ConfirmationPage; import mineplex.core.shop.page.ShopPageBase; import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Class.IPvpClass; @@ -387,13 +388,8 @@ public class SkillPage extends ShopPageBase public void PurchaseSkill(Player player, ISkill skill) { - getShop().openPageForPlayer(player, new ConfirmationPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), new Runnable() - { - public void run() - { - buildPage(); - } - }, this, new SkillSalesPackage(skill), GlobalCurrency.GEM, player)); + SalesPackageBase salesPackage = new SkillSalesPackage(skill); + getShop().openPageForPlayer(player, new mineplex.core.shop.confirmation.ConfirmationPage<>(player, this, new SalesPackageProcessor(player, GlobalCurrency.GEM, salesPackage, getDonationManager(), this::buildPage), salesPackage.buildIcon())); } private boolean isSkillLocked(ISkill skill) @@ -414,13 +410,8 @@ public class SkillPage extends ShopPageBase public void PurchaseItem(Player player, Item item) { - getShop().openPageForPlayer(player, new ConfirmationPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), new Runnable() - { - public void run() - { - buildPage(); - } - }, this, new ItemSalesPackage(item), GlobalCurrency.GEM, player)); + SalesPackageBase salesPackage = new ItemSalesPackage(item); + getShop().openPageForPlayer(player, new mineplex.core.shop.confirmation.ConfirmationPage<>(player, this, new SalesPackageProcessor(player, GlobalCurrency.GEM, salesPackage, getDonationManager(), this::buildPage), salesPackage.buildIcon())); } public void SelectItem(Player player, Item item) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java index 9ab3d48ab..12395f010 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java @@ -14,7 +14,8 @@ import mineplex.core.progression.data.PlayerKit; import mineplex.core.progression.data.PlayerKitDataManager; import mineplex.core.progression.gui.Menu; import mineplex.core.progression.math.Calculations; -import mineplex.core.shop.page.ConfirmationPage; +import mineplex.core.shop.item.SalesPackageBase; +import mineplex.core.shop.item.SalesPackageProcessor; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.game.games.evolution.Evolution; @@ -300,13 +301,14 @@ public abstract class ProgressingKit extends Kit implements ProgressiveKit } else if (this.GetAvailability() == KitAvailability.Gem && donor.getBalance(GlobalCurrency.GEM) >= this.GetCost()) { - Manager.GetShop().openPageForPlayer(player, new ConfirmationPage<>( - Manager, Manager.GetShop(), Manager.GetClients(), Manager.GetDonation(), () -> { + SalesPackageBase salesPackage = new KitPackage(Manager.GetGame().GetType().GetKitGameName(Manager.GetGame()), this); + Manager.GetShop().openPageForPlayer(player, new mineplex.core.shop.confirmation.ConfirmationPage<>(player, Manager, Manager.GetShop(), Manager.GetClients(), Manager.GetDonation(), new SalesPackageProcessor(player, GlobalCurrency.GEM, salesPackage, Manager.GetDonation(), () -> + { if (player.isOnline()) { Manager.GetGame().SetKit(player, this, true); } - }, null, new KitPackage(Manager.GetGame().GetType().GetKitGameName(Manager.GetGame()), this), GlobalCurrency.GEM, player)); + }), salesPackage.buildIcon())); } else if (this.GetAvailability() == KitAvailability.Achievement) {