Completed Energy

This commit is contained in:
Shaun Bennett 2015-07-08 21:39:31 -05:00
parent abbf6957b0
commit a9e68ff777
17 changed files with 192 additions and 148 deletions

View File

@ -31,12 +31,33 @@ public class UtilTime
public enum TimeUnit public enum TimeUnit
{ {
FIT, FIT(1),
DAYS, DAYS(86400000),
HOURS, HOURS(3600000),
MINUTES, MINUTES(60000),
SECONDS, SECONDS(1000),
MILLISECONDS MILLISECONDS(1);
private long _ms;
TimeUnit(long ms)
{
_ms = ms;
}
public long getMilliseconds()
{
return _ms;
}
}
/**
* Convert from one TimeUnit to a different one
*/
public static long convert(long time, TimeUnit from, TimeUnit to)
{
long milleseconds = time * from.getMilliseconds();
return milleseconds / to.getMilliseconds();
} }
public static String since(long epoch) public static String since(long epoch)

View File

@ -103,17 +103,17 @@ public abstract class MiniPlugin implements Listener
System.out.println(F.main(_moduleName, message)); System.out.println(F.main(_moduleName, message));
} }
protected void runAsync(Runnable runnable) public void runAsync(Runnable runnable)
{ {
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable); _plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable);
} }
protected void runSync(Runnable runnable) public void runSync(Runnable runnable)
{ {
_plugin.getServer().getScheduler().runTask(_plugin, runnable); _plugin.getServer().getScheduler().runTask(_plugin, runnable);
} }
protected void runSyncLater(Runnable runnable, long delay) public void runSyncLater(Runnable runnable, long delay)
{ {
_plugin.getServer().getScheduler().runTaskLater(_plugin, runnable, delay); _plugin.getServer().getScheduler().runTaskLater(_plugin, runnable, delay);
} }

View File

@ -41,9 +41,9 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
public void addCommands() public void addCommands()
{ {
// TODO: Re-add commands? Where are command implementations, seen as missing at the moment. // TODO: Re-add commands? Where are command implementations, seen as missing at the moment.
//addCommand(new GemCommand(this)); addCommand(new GemCommand(this));
//addCommand(new CoinCommand(this)); addCommand(new CoinCommand(this));
//addCommand(new GoldCommand(this)); addCommand(new GoldCommand(this));
} }
@EventHandler @EventHandler
@ -59,7 +59,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins()); //_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
} }
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase) public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final CurrencyType currencyType, final int cost, boolean oneTimePurchase)
{ {
final Donor donor = Bukkit.getPlayerExact(name) != null ? Get(name) : null; final Donor donor = Bukkit.getPlayerExact(name) != null ? Get(name) : null;
@ -83,14 +83,14 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
if (donor != null) if (donor != null)
{ {
donor.AddUnknownSalesPackagesOwned(packageName); donor.AddUnknownSalesPackagesOwned(packageName);
donor.DeductCost(cost, coinPurchase ? CurrencyType.Coins : CurrencyType.Gems); donor.DeductCost(cost, currencyType);
} }
} }
if (callback != null) if (callback != null)
callback.run(response); callback.run(response);
} }
}, name, accountId, packageName, coinPurchase, cost); }, name, accountId, packageName, currencyType, cost);
} }
public void PurchaseKnownSalesPackage(final Callback<TransactionResponse> callback, final String name, final UUID uuid, final int cost, final int salesPackageId) public void PurchaseKnownSalesPackage(final Callback<TransactionResponse> callback, final String name, final UUID uuid, final int cost, final int salesPackageId)

View File

@ -6,6 +6,7 @@ import java.sql.SQLException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.database.DBPool; import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable; import mineplex.core.database.DatabaseRunnable;
@ -69,12 +70,12 @@ public class DonationRepository extends RepositoryBase
}), "Error purchasing known sales package in DonationRepository : "); }), "Error purchasing known sales package in DonationRepository : ");
} }
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final boolean coinPurchase, final int cost) public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final CurrencyType currencyType, final int cost)
{ {
final UnknownPurchaseToken token = new UnknownPurchaseToken(); final UnknownPurchaseToken token = new UnknownPurchaseToken();
token.AccountName = name; token.AccountName = name;
token.SalesPackageName = packageName; token.SalesPackageName = packageName;
token.CoinPurchase = coinPurchase; token.CoinPurchase = currencyType == CurrencyType.Coins;
token.Cost = cost; token.Cost = cost;
token.Premium = false; token.Premium = false;
@ -84,11 +85,15 @@ public class DonationRepository extends RepositoryBase
{ {
if (response == TransactionResponse.Success) if (response == TransactionResponse.Success)
{ {
if (coinPurchase) if (currencyType == CurrencyType.Coins)
{ {
executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnInt("id", accountId)); executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnInt("id", accountId));
//executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost)); //executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost));
} }
else if (currencyType == CurrencyType.Gold)
{
executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", -cost), new ColumnInt("id", accountId));
}
} }
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()

View File

@ -3,6 +3,7 @@ package mineplex.core.reward.rewards;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.CurrencyType;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.reward.Reward; import mineplex.core.reward.Reward;
import mineplex.core.reward.RewardData; import mineplex.core.reward.RewardData;
@ -31,7 +32,7 @@ public class UnknownPackageReward extends Reward
@Override @Override
protected RewardData giveRewardCustom(Player player) protected RewardData giveRewardCustom(Player player)
{ {
_donationManager.PurchaseUnknownSalesPackage(null, player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _packageName, true, 0, true); _donationManager.PurchaseUnknownSalesPackage(null, player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _packageName, CurrencyType.Coins, 0, true);
return new RewardData(getRarity().getColor() + _name, _itemStack); return new RewardData(getRarity().getColor() + _name, _itemStack);
} }

View File

@ -147,7 +147,7 @@ public class ConfirmationPage<PluginType extends MiniPlugin, ShopType extends Sh
{ {
showResultsPage(response); showResultsPage(response);
} }
}, getPlayer().getName(), getClientManager().Get(getPlayer()).getAccountId(), _salesItem.GetName(), getCurrencyType() == CurrencyType.Coins, _salesItem.GetCost(getCurrencyType()), _salesItem.OneTimePurchase()); }, getPlayer().getName(), getClientManager().Get(getPlayer()).getAccountId(), _salesItem.GetName(), getCurrencyType(), _salesItem.GetCost(getCurrencyType()), _salesItem.OneTimePurchase());
} }
_taskId = getPlugin().getScheduler().scheduleSyncRepeatingTask(getPlugin().getPlugin(), this, 2L, 2L); _taskId = getPlugin().getScheduler().scheduleSyncRepeatingTask(getPlugin().getPlugin(), this, 2L, 2L);

View File

@ -7,6 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.game.clans.shop.energy.EnergyShop; import mineplex.game.clans.shop.energy.EnergyShop;
@ -14,6 +15,7 @@ import mineplex.game.clans.shop.energy.EnergyShop;
public class ClanEnergyManager extends MiniPlugin implements Runnable public class ClanEnergyManager extends MiniPlugin implements Runnable
{ {
private ClansManager _clansManager; private ClansManager _clansManager;
private DonationManager _donationManager;
private EnergyShop _shop; private EnergyShop _shop;
private int tickCount; private int tickCount;
@ -21,7 +23,8 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable
{ {
super("Clan Energy", plugin); super("Clan Energy", plugin);
_clansManager = clansManager; _clansManager = clansManager;
_shop = new EnergyShop(clansManager, clientManager, donationManager); _donationManager = donationManager;
_shop = new EnergyShop(this, clientManager, donationManager);
// Wait 5 seconds and then tick every 60 seconds // Wait 5 seconds and then tick every 60 seconds
_plugin.getServer().getScheduler().runTaskTimer(_plugin, this, 20 * 5, 20 * 60); _plugin.getServer().getScheduler().runTaskTimer(_plugin, this, 20 * 5, 20 * 60);
@ -66,11 +69,22 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable
} }
} }
public void purchaseEnergy(Player player, ClanInfo clanInfo, int energy, Callback<Boolean> callback)
{
}
public void openShop(Player player) public void openShop(Player player)
{ {
_shop.attemptShopOpen(player); _shop.attemptShopOpen(player);
} }
public ClansManager getClansManager()
{
return _clansManager;
}
@EventHandler @EventHandler
public void command(PlayerCommandPreprocessEvent event) public void command(PlayerCommandPreprocessEvent event)
{ {
@ -79,4 +93,9 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable
openShop(event.getPlayer()); openShop(event.getPlayer());
} }
} }
public int convertEnergyToGold(int energy)
{
return (energy / 4) + (energy % 4 == 0 ? 0 : 1);
}
} }

View File

@ -469,7 +469,7 @@ public class ClanInfo
public int getEnergyMax() public int getEnergyMax()
{ {
// 10080 = 7 days of minutes // 10080 = 7 days of minutes
return 1440 + (getEnergyCostPerMinute() * 10080); return Math.max(1440, getEnergyCostPerMinute() * 60 * 24 * 3);
} }
public int getEnergyCostPerMinute() public int getEnergyCostPerMinute()
@ -477,6 +477,11 @@ public class ClanInfo
return (getSize() * getClaimCount()); return (getSize() * getClaimCount());
} }
public int getEnergyPurchasableMinutes()
{
return getEnergyPurchasable() / getEnergyCostPerMinute();
}
public int getEnergyPurchasable() public int getEnergyPurchasable()
{ {
int diff = getEnergyMax() - getEnergy(); int diff = getEnergyMax() - getEnergy();

View File

@ -66,6 +66,7 @@ public class ClansDataAccessLayer
token.Description = "No Description"; token.Description = "No Description";
token.Home = ""; token.Home = "";
token.Admin = admin; token.Admin = admin;
token.Energy = 1440;
//Create Clan //Create Clan
ClanInfo clan = new ClanInfo(_manager, token); ClanInfo clan = new ClanInfo(_manager, token);

View File

@ -587,16 +587,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
return _chat; return _chat;
} }
public int convertGoldToEnergy(int gold)
{
return gold * 4;
}
public int convertEnergyToGold(int energy)
{
return (energy / 4) + (energy % 4 == 0 ? 0 : 1);
}
/** /**
* Get the timezone for this server. * Get the timezone for this server.
* This may be used in the future if we have * This may be used in the future if we have

View File

@ -799,6 +799,12 @@ public class ClansCommand extends CommandBase<ClansManager>
return; return;
} }
if (clan.getEnergy() == 0)
{
UtilPlayer.message(caller, F.main("Clans", "You must purchase energy at a shop before you can claim land."));
return;
}
String chunk = UtilWorld.chunkToStr(caller.getLocation().getChunk()); String chunk = UtilWorld.chunkToStr(caller.getLocation().getChunk());
ClanInfo ownerClan = Plugin.getClanUtility().getOwner(caller.getLocation()); ClanInfo ownerClan = Plugin.getClanUtility().getOwner(caller.getLocation());

View File

@ -138,7 +138,8 @@ public class ClansRegions extends MiniPlugin
sendBorder(event.getPlayer()); sendBorder(event.getPlayer());
} }
@EventHandler public void onTeleport(PlayerTeleportEvent event) @EventHandler
public void onTeleport(PlayerTeleportEvent event)
{ {
Location from = event.getFrom(); Location from = event.getFrom();
Location to = event.getTo(); Location to = event.getTo();

View File

@ -0,0 +1,25 @@
package mineplex.game.clans.shop.energy;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.common.CurrencyType;
import mineplex.core.shop.item.SalesPackageBase;
public class EnergyPackage extends SalesPackageBase
{
public EnergyPackage(String name, int cost)
{
super(name, Material.REDSTONE, " ", ChatColor.RESET + "Clan Energy");
CurrencyCostMap.put(CurrencyType.Gold, cost);
KnownPackage = false;
OneTimePurchaseOnly = false;
}
@Override
public void Sold(Player player, CurrencyType currencyType)
{
}
}

View File

@ -1,5 +1,8 @@
package mineplex.game.clans.shop.energy; package mineplex.game.clans.shop.energy;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -8,122 +11,80 @@ import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanEnergyManager;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
public class EnergyPage extends ShopPageBase<ClansManager, EnergyShop> public class EnergyPage extends ShopPageBase<ClanEnergyManager, EnergyShop>
{ {
private ClanInfo _clanInfo; public EnergyPage(ClanEnergyManager plugin, EnergyShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
public EnergyPage(ClansManager plugin, EnergyShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{ {
super(plugin, shop, clientManager, donationManager, "Energy Shop", player, 9); super(plugin, shop, clientManager, donationManager, "Energy Shop", player, 18);
_clanInfo = getPlugin().getClan(getPlayer());
buildPage(); buildPage();
} }
@Override @Override
protected void buildPage() protected void buildPage()
{ {
if (_clanInfo == null) ClanInfo clanInfo = getPlugin().getClansManager().getClan(getPlayer());
{ if (clanInfo == null)
buildNoClan(); buildNoClan();
return;
}
else if (_clanInfo.getEnergyPurchasable() > 0)
{
if (hasEnoughGold())
{
buildPurchasable(_clanInfo);
}
else
{
buildNotEnoughGold(_clanInfo);
}
}
else else
{ {
buildMaxEnergy(_clanInfo); addInfo(clanInfo, 4);
buildPurchase(clanInfo);
} }
} }
private void buildPurchasable(ClanInfo _clanInfo) private void buildPurchase(ClanInfo clanInfo)
{ {
int playerGold = getPlayerGold(); int energyPerMin = Math.max(1, clanInfo.getEnergyCostPerMinute());
int energyCost = getEnergyPerHour();
int goldCost = getGoldPerHour();
EnergyShopButton button = new EnergyShopButton(getPlayer(), getPlugin(), this, _clanInfo, true, getDonationManager()); int oneHourEnergy = energyPerMin * 60;
String title = "Purchase Energy"; int oneDayEnergy = oneHourEnergy * 24;
String currentEnergy = ChatColor.RESET + F.value("Clan Energy", "" + _clanInfo.getEnergy()); int maxEnergy = clanInfo.getEnergyPurchasable();
String energyString = ChatColor.RESET + F.value("Energy drain/hour", "" + energyCost);
String playerGoldString = ChatColor.RESET + F.value("Your Gold", playerGold + "g"); addButton(clanInfo, 11, oneHourEnergy, Material.REDSTONE, (byte) 0, " ", ChatColor.RESET + "1 Hour of Energy", " ", ChatColor.RESET + "Costs " + C.cGreen + "$" + getPlugin().convertEnergyToGold(oneHourEnergy));
String purchaseString = ChatColor.RESET + C.cWhite + "Click to buy 1 hour of energy for " + C.cYellow + goldCost + "g"; addButton(clanInfo, 13, oneDayEnergy, Material.REDSTONE_BLOCK, (byte) 0, " ", ChatColor.RESET + "1 Day of Energy", " ", ChatColor.RESET + "Costs " + C.cGreen + "$" + getPlugin().convertEnergyToGold(oneDayEnergy));
ShopItem shopItem = new ShopItem(Material.LAVA_BUCKET, title, new String[] {" ", currentEnergy, energyString, " ", playerGoldString, purchaseString}, 0, false, false); addButton(clanInfo, 15, maxEnergy, Material.FURNACE, (byte) 0, " ", ChatColor.RESET + "Maxed Out Energy", " ", ChatColor.RESET + "Costs " + C.cGreen + "$" + getPlugin().convertEnergyToGold(maxEnergy));
addButton(4, shopItem, button);
} }
private void buildNotEnoughGold(ClanInfo _clanInfo) private void addInfo(ClanInfo clanInfo, int slot)
{ {
int playerGold = getPlayerGold(); String itemName = clanInfo.getName();
int energyCost = getEnergyPerHour(); ArrayList<String> lore = new ArrayList<String>();
int goldCost = getGoldPerHour(); lore.add(" ");
lore.add(C.cYellow + "Energy: " + ChatColor.RESET + clanInfo.getEnergy());
lore.add(C.cYellow + "Drain: " + ChatColor.RESET + clanInfo.getEnergyCostPerMinute() * 60 + " per Hour");
lore.add(C.cYellow + "Max Energy: " + ChatColor.RESET + clanInfo.getEnergyMax());
if (clanInfo.getEnergyCostPerMinute() > 0)
lore.add(C.cYellow + "Time Left: " + ChatColor.RESET + UtilTime.convertString((clanInfo.getEnergy() / clanInfo.getEnergyCostPerMinute()) * 60000L, 1, UtilTime.TimeUnit.FIT));
EnergyShopButton button = new EnergyShopButton(getPlayer(), getPlugin(), this, _clanInfo, true, getDonationManager()); ShopItem shopItem = new ShopItem(Material.DIAMOND, itemName, lore.toArray(new String[0]), 1, false, false);
String title = ChatColor.RED + C.Bold + "Missing Gold!"; setItem(slot, shopItem);
String currentEnergy = ChatColor.RESET + F.value("Clan Energy", "" + _clanInfo.getEnergy()); }
String energyString = ChatColor.RESET + F.value("Energy drain/hour", "" + energyCost);
String playerGoldString = ChatColor.RESET + F.value("Your Gold", playerGold + "g"); private void addButton(ClanInfo clanInfo, int slot, int energyAmount, Material material, byte data, String... lore)
String purchaseString = ChatColor.RESET + C.cWhite + "You don't have enough gold"; {
String goldString = ChatColor.RESET + C.cWhite + "You need " + C.cYellow + goldCost + C.cWhite + " gold to purchase energy"; boolean locked = energyAmount > clanInfo.getEnergyPurchasable() || energyAmount == 0;
ShopItem shopItem = new ShopItem(Material.GOLD_INGOT, title, new String[] {" ", currentEnergy, energyString, " ", playerGoldString, purchaseString, goldString}, 0, false, false); String itemName = "Purchase " + energyAmount + " Energy";
addButton(4, shopItem, button);
ShopItem shopItem = new ShopItem(material, itemName, lore, 1, locked, false);
if (locked)
setItem(slot, shopItem);
else
addButton(slot, shopItem, new EnergyShopButton(getPlugin(), this, energyAmount, clanInfo));
} }
private void buildNoClan() private void buildNoClan()
{ {
ShopItem shopItem = new ShopItem(Material.GLASS, "No Clan!", new String[] {" ", "You need to be in a", "clan to purchase energy!"}, 1, false, false); ShopItem shopItem = new ShopItem(Material.BEDROCK, "No Clan!", new String[] {" ", ChatColor.RESET + "You need to be in a", ChatColor.RESET + "clan to purchase energy!"}, 1, false, false);
setItem(4, shopItem); setItem(4, shopItem);
} }
private void buildMaxEnergy(ClanInfo _clanInfo)
{
int energy = _clanInfo.getEnergy();
String title = C.cRed + C.Bold + "Cannot Purchase Energy!";
String currentEnergy = ChatColor.RESET + F.value("Clan Energy", "" + energy);
String[] lore = new String[] {" ", currentEnergy, ChatColor.RESET + "Your clan is at the energy cap"};
ShopItem shopItem = new ShopItem(Material.BUCKET, title, lore, 0, false, false);
addItem(4, shopItem);
}
protected boolean hasEnoughGold()
{
return getPlayerGold() >= getGoldPerHour();
}
protected int getGoldPerHour()
{
return getPlugin().convertEnergyToGold(getEnergyPerHour());
}
protected int getEnergyPerHour()
{
return _clanInfo.getEnergyCostPerMinute() * 60;
}
protected int getPlayerGold()
{
return getDonationManager().Get(getPlayer()).getGold();
}
public void showLoading()
{
ItemStack is = ItemStackFactory.Instance.CreateStack(Material.WOOL, (byte) 11, 1, C.cAqua + C.Bold + "Please Wait..");
setItem(4, is);
}
} }

View File

@ -6,18 +6,18 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase; import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanEnergyManager;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
public class EnergyShop extends ShopBase<ClansManager> public class EnergyShop extends ShopBase<ClanEnergyManager>
{ {
public EnergyShop(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager) public EnergyShop(ClanEnergyManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{ {
super(plugin, clientManager, donationManager, "Energy Shop"); super(plugin, clientManager, donationManager, "Energy Shop");
} }
@Override @Override
protected ShopPageBase<ClansManager, ? extends ShopBase<ClansManager>> buildPagesFor(Player player) protected ShopPageBase<ClanEnergyManager, ? extends ShopBase<ClanEnergyManager>> buildPagesFor(Player player)
{ {
return new EnergyPage(getPlugin(), this, getClientManager(), getDonationManager(), player); return new EnergyPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
} }

View File

@ -1,56 +1,64 @@
package mineplex.game.clans.shop.energy; package mineplex.game.clans.shop.energy;
import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.energy.Energy;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.item.IButton; 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.ClanInfo;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
public class EnergyShopButton implements IButton public class EnergyShopButton implements IButton
{ {
private Player _player; private ClanEnergyManager _energyManager;
private ClansManager _clansManager;
private EnergyPage _page; private EnergyPage _page;
private int _energyToPurchase;
private ClanInfo _clanInfo; private ClanInfo _clanInfo;
private boolean _canPurchaseEnergy;
private DonationManager _donationManager;
public EnergyShopButton(Player player, ClansManager clansManager, EnergyPage page, ClanInfo clanInfo, boolean canPurchaseEnergy, DonationManager donationManager) public EnergyShopButton(ClanEnergyManager energyManager, EnergyPage page, int energyToPurchase, ClanInfo clanInfo)
{ {
_player = player; _energyManager = energyManager;
_clansManager = clansManager;
_clanInfo = clanInfo; _clanInfo = clanInfo;
_canPurchaseEnergy = canPurchaseEnergy; _energyToPurchase = energyToPurchase;
_donationManager = donationManager;
_page = page; _page = page;
} }
@Override @Override
public void onClick(final Player player, ClickType clickType) public void onClick(final Player player, ClickType clickType)
{ {
if (_page.hasEnoughGold()) _page.getShop().openPageForPlayer(player, new ConfirmationPage<ClanEnergyManager, EnergyShop>(
_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable()
{ {
int playerGold = _page.getPlayerGold(); public void run()
final int energy = _page.getEnergyPerHour();
int goldCost = _page.getGoldPerHour();
_page.clearPage();
_page.showLoading();
_donationManager.RewardGold(new Callback<Boolean>()
{ {
@Override _clanInfo.adjustEnergy(_energyToPurchase);
public void run(Boolean data) _page.refresh();
_energyManager.runAsync(new Runnable()
{ {
player.playSound(player.getEyeLocation(), Sound.ANVIL_USE, 1, 1); @Override
_clanInfo.adjustEnergy(energy); public void run()
_page.refresh(); {
} _energyManager.getClansManager().getClanDataAccess().updateEnergy(_clanInfo);
}, "Energy Purchase", player.getName(), _page.getClientManager().Get(player).getAccountId(), -goldCost, true); }
} });
// 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", _energyManager.convertEnergyToGold(_energyToPurchase)), CurrencyType.Gold, player));
} }
} }

View File

@ -23,6 +23,7 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
@ -399,7 +400,7 @@ public class Halloween extends SoloGame
{ {
for (Player player : GetPlayers(false)) for (Player player : GetPlayers(false))
{ {
Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), Manager.GetClients().Get(player).getAccountId(), "Pumpling", false, 0, true); Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), Manager.GetClients().Get(player).getAccountId(), "Pumpling", CurrencyType.Gems, 0, true);
Manager.GetGame().AddGems(player, 30, "Killing the Pumpkin King", false, false); Manager.GetGame().AddGems(player, 30, "Killing the Pumpkin King", false, false);
Manager.GetGame().AddGems(player, 10, "Participation", false, false); Manager.GetGame().AddGems(player, 10, "Participation", false, false);
} }