Reimplement EnergyShopButton with new machinery
This commit is contained in:
parent
3cddf35d12
commit
167c0f2b5e
@ -11,33 +11,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public class SalesPackageProcessor implements ConfirmationProcessor {
|
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<Boolean>()
|
|
||||||
{
|
|
||||||
@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 GlobalCurrency _currencyType;
|
||||||
private final SalesPackageBase _salesItem;
|
private final SalesPackageBase _salesItem;
|
||||||
private final DonationManager _donationManager;
|
private final DonationManager _donationManager;
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
package mineplex.game.clans.economy;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
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.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
public class GoldPurchaseProcessor implements ConfirmationProcessor {
|
||||||
|
private final Player _player;
|
||||||
|
private final int _price;
|
||||||
|
private final GoldManager _goldManager;
|
||||||
|
private final Runnable _runAfterPurchase;
|
||||||
|
|
||||||
|
public GoldPurchaseProcessor(Player player, int price, GoldManager goldManager, Runnable runAfterPurchase)
|
||||||
|
{
|
||||||
|
_player = player;
|
||||||
|
_price = price;
|
||||||
|
_goldManager = goldManager;
|
||||||
|
_runAfterPurchase = runAfterPurchase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Inventory inventory) {
|
||||||
|
inventory.setItem(4, new ItemBuilder(ClansCurrency.GOLD.getDisplayMaterial()).setTitle(ClansCurrency.GOLD.getPrefix()).addLore(C.cGray + _price + " " + ClansCurrency.GOLD.getPrefix() + " will be", C.cGray + "deducted from your account balance").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(ConfirmationCallback callback) {
|
||||||
|
int goldCount = _goldManager.Get(_player).getBalance();
|
||||||
|
|
||||||
|
if (_price > goldCount)
|
||||||
|
showResults(callback, TransactionResponse.InsufficientFunds);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_goldManager.rewardGold(data ->
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
showResults(callback, TransactionResponse.Success);
|
||||||
|
_player.playSound(_player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
showResults(callback, TransactionResponse.Failed);
|
||||||
|
}
|
||||||
|
}, _player, -_price, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.");
|
||||||
|
_runAfterPurchase.run();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,24 @@
|
|||||||
package mineplex.game.clans.shop.energy;
|
package mineplex.game.clans.shop.energy;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
|
import mineplex.core.shop.confirmation.ConfirmationPage;
|
||||||
import mineplex.core.shop.item.IButton;
|
import mineplex.core.shop.item.IButton;
|
||||||
import mineplex.game.clans.clans.ClanEnergyManager;
|
import mineplex.game.clans.clans.ClanEnergyManager;
|
||||||
import mineplex.game.clans.clans.ClanInfo;
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
import mineplex.game.clans.clans.event.PreEnergyShopBuyEvent;
|
import mineplex.game.clans.clans.event.PreEnergyShopBuyEvent;
|
||||||
|
import mineplex.game.clans.economy.GoldPurchaseProcessor;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class EnergyShopButton implements IButton
|
public class EnergyShopButton implements IButton
|
||||||
{
|
{
|
||||||
|
private static final ItemStack ICON = new ItemBuilder(Material.REDSTONE).setTitle(ChatColor.RESET + "Clan Energy").build();
|
||||||
|
|
||||||
private ClanEnergyManager _energyManager;
|
private ClanEnergyManager _energyManager;
|
||||||
private EnergyPage _page;
|
private EnergyPage _page;
|
||||||
private int _energyToPurchase;
|
private int _energyToPurchase;
|
||||||
@ -33,30 +42,16 @@ public class EnergyShopButton implements IButton
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*_page.getShop().openPageForPlayer(player, new ConfirmationPage<ClanEnergyManager, EnergyShop>(
|
_page.getShop().openPageForPlayer(player, new ConfirmationPage<>(player, _page, new GoldPurchaseProcessor(player, _cost, _energyManager.getClansManager().getGoldManager(), () ->
|
||||||
_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
_clanInfo.adjustEnergy(_energyToPurchase);
|
_clanInfo.adjustEnergy(_energyToPurchase);
|
||||||
_page.refresh();
|
_page.refresh();
|
||||||
|
|
||||||
_energyManager.runAsync(new Runnable()
|
_energyManager.runAsync(() -> _energyManager.getClansManager().getClanDataAccess().updateEnergy(_clanInfo));
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
_energyManager.getClansManager().getClanDataAccess().updateEnergy(_clanInfo);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Notify
|
// Notify
|
||||||
_energyManager.getClansManager().messageClan(_clanInfo, F.main("Energy", F.name(player.getName()) + " purchased " + F.elem(_energyToPurchase + " Energy") + " for the clan"));
|
_energyManager.getClansManager().messageClan(_clanInfo, F.main("Energy", F.name(player.getName()) + " purchased " + F.elem(_energyToPurchase + " Energy") + " for the clan"));
|
||||||
}
|
}), ICON));
|
||||||
}, _page, new EnergyPackage(_energyToPurchase + " Energy", _cost), ClansCurrency.GOLD, player));*/
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user