diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/PlayerInfo.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/PlayerInfo.java new file mode 100644 index 000000000..0f9a3c686 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/PlayerInfo.java @@ -0,0 +1,26 @@ +package mineplex.core.common.util; + +import java.util.UUID; + +public class PlayerInfo +{ + private String _name; + private UUID _uuid; + + public PlayerInfo(String name, UUID uuid) + { + _name = name; + _uuid = uuid; + } + + public String getName() + { + return _name; + } + + public UUID getUUID() + { + return _uuid; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index fd8ff6eb3..a8555b4d8 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -6,7 +6,6 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; @@ -256,7 +255,7 @@ public class UtilPlayer return nearbyMap; } - + public static Player getClosest(Location loc, Collection ignore) { Player best = null; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index f9afd04de..0d52f76f5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -42,6 +42,7 @@ public class DonationManager extends MiniDbClientPlugin { addCommand(new GemCommand(this)); addCommand(new CoinCommand(this)); + addCommand(new GoldCommand(this)); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java new file mode 100644 index 000000000..99e12ed0d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java @@ -0,0 +1,84 @@ +package mineplex.core.donation; + +import java.util.UUID; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UUIDFetcher; +import mineplex.core.common.util.UtilPlayer; + +public class GoldCommand extends CommandBase +{ + public GoldCommand(DonationManager plugin) + { + super(plugin, Rank.ADMIN, "givegold"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args == null || args.length == 0) + { + UtilPlayer.message(caller, F.main("Gold", "Your Gold: " + F.elem("" + Plugin.Get(caller).getGold()))); + } + else if (args.length < 2) + { + UtilPlayer.message(caller, F.main("Gold", "Missing Args: " + F.elem("/gold "))); + return; + } + + String targetName = args[0]; + String goldString = args[1]; + Player target = UtilPlayer.searchExact(targetName); + + if (target == null) + { + UUID uuid = UUIDFetcher.getUUIDOf(targetName); + if (uuid != null) + { + rewardGold(caller, null, targetName, uuid, goldString); + } + else + { + UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName))); + } + } + else + { + rewardGold(caller, target, target.getName(), target.getUniqueId(), goldString); + } + } + + private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, String goldString) + { + try + { + int gold = Integer.parseInt(goldString); + rewardGold(caller, target, targetName, uuid, gold); + } + catch (Exception e) + { + UtilPlayer.message(caller, F.main("Gold", "Invalid Gold Amount")); + } + } + + private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, final int gold) + { + Plugin.RewardGold(new Callback() + { + public void run(Boolean completed) + { + UtilPlayer.message(caller, F.main("Gold", "You gave " + F.elem(gold + " Gold") + " to " + F.name(targetName) + ".")); + + if (target != null) + { + UtilPlayer.message(target, F.main("Gold", F.name(caller.getName()) + " gave you " + F.elem(gold + " Gold") + ".")); + } + } + }, caller.getName(), targetName, uuid, gold); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java index 711e1614d..945f819b0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java @@ -18,7 +18,6 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.donation.DonationManager; import mineplex.core.shop.ShopBase; import mineplex.core.shop.item.IButton; -import mineplex.core.shop.item.ShopItem; public abstract class ShopPageBase> extends CraftInventoryCustom implements Listener { @@ -187,10 +186,16 @@ public abstract class ShopPageBase 0) + { + runAsync(new Runnable() + { + @Override + public void run() + { + _clansManager.getClanDataAccess().updateEnergy(clanInfo); + } + }); + } + } + } + } + + public void openShop(Player player) + { + _shop.attemptShopOpen(player); + } + + // TODO DEBUG + @EventHandler + public void command(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("/energyshop")) + { + openShop(event.getPlayer()); + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java index 83e159ff4..21e554aae 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java @@ -1,7 +1,14 @@ package mineplex.game.clans.clans; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -9,18 +16,14 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.common.util.UtilWorld; import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken; import mineplex.game.clans.clans.repository.tokens.ClanMemberToken; import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken; import mineplex.game.clans.clans.repository.tokens.ClanToken; -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - public class ClanInfo { public enum Role @@ -60,6 +63,7 @@ public class ClanInfo // Temporary private NautHashMap _inviteeMap = new NautHashMap(); private NautHashMap _inviterMap = new NautHashMap(); + private List _onlinePlayers = new ArrayList(); private NautHashMap _requestMap = new NautHashMap(); @@ -152,9 +156,9 @@ public class ClanInfo return true; } - public boolean isMember(String clan) + public boolean isMember(String other) { - return getMembers().containsKey(clan); + return getMembers().containsKey(other); } public boolean isAlly(String other) @@ -204,6 +208,16 @@ public class ClanInfo // Land stringList.add(F.value("Territory", getClaims() + "/" + getClaimsMax())); + // Energy + int energy = getEnergy(); + int costPerHour = getEnergyCostPerMinute() * 60; + stringList.add(" "); + stringList.add(F.value("Clan Energy", "" + energy)); +// stringList.add(F.value("Max Energy", "" + getEnergyMax())); + stringList.add(F.value("Energy Drain/Hour", "" + costPerHour)); + stringList.add(F.value("Hours Left", "" + energy / costPerHour)); + stringList.add(" "); + // Ally String String allySorted = ""; HashSet allyUnsorted = new HashSet(); @@ -413,4 +427,52 @@ public class ClanInfo { _energy += energy; } + + public int getClaimCount() + { + return _claimSet.size(); + } + + public int getSize() + { + return _memberMap.size(); + } + + public int getEnergyMax() + { + // TODO + // 10080 = 7 days of minutes + return 1440 + (getEnergyCostPerMinute() * 10080); + } + + public int getEnergyCostPerMinute() + { + return (getSize() * getClaimCount()); + } + + public int getEnergyPurchasable() + { + int diff = getEnergyMax() - getEnergy(); + return diff > 0 ? diff : 0; + } + + public List getOnlinePlayers() + { + ArrayList players = new ArrayList(_onlinePlayers.size()); + for (UUID uuid : _onlinePlayers) + { + players.add(UtilPlayer.searchExact(uuid)); + } + return players; + } + + protected void playerOnline(Player player) + { + _onlinePlayers.add(player.getUniqueId()); + } + + protected void playerOffline(Player player) + { + _onlinePlayers.remove(player.getUniqueId()); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java index 6c5b37313..3c91df4f8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java @@ -255,11 +255,17 @@ public class ClansDataAccessLayer // _manager.getUnclaimMap().put(chunk, System.currentTimeMillis()); //Log - _manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "]."); + if (player != null) + _manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "]."); return true; } + public boolean unclaimSilent(String chunk, boolean sql) + { + return unclaim(chunk, null, sql); + } + public void home(ClanInfo clan, Location loc, String player) { //Memory diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 4c07c40f3..2d968864b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -2,12 +2,12 @@ package mineplex.game.clans.clans; import java.util.HashSet; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -134,6 +134,8 @@ public class ClansManager extends MiniClientPlugin implements IRelat AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, donationManager); ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager); _classShop = new ClassCombatShop(shopManager, _clientManager, donationManager, true, "Class Shop"); + + ClanEnergyManager clanEnergyManager = new ClanEnergyManager(plugin, this, clientManager, donationManager); for (ClanToken token : _clanDataAccess.getRepository().retrieveClans()) { @@ -171,6 +173,16 @@ public class ClansManager extends MiniClientPlugin implements IRelat return _clanMemberMap; } + public ClanInfo getClan(Player player) + { + return _clanMemberMap.get(player.getName()); + } + + public boolean isInClan(Player player) + { + return _clanMemberMap.containsKey(player.getName()); + } + public ClanInfo getClan(String clan) { return _clanMap.get(clan); @@ -218,6 +230,28 @@ public class ClansManager extends MiniClientPlugin implements IRelat getClanGame().Interact(event); getClanDisplay().handleInteract(event); } + + @EventHandler + public void join(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + ClanInfo clanInfo = getClanMemberMap().get(player.getName()); + if (clanInfo != null) + { + clanInfo.playerOnline(player); + } + } + + @EventHandler + public void quit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + ClanInfo clanInfo = getClanMemberMap().get(player.getName()); + if (clanInfo != null) + { + clanInfo.playerOffline(player); + } + } @EventHandler public void handlePlayerChat(AsyncPlayerChatEvent event) @@ -302,46 +336,29 @@ public class ClansManager extends MiniClientPlugin implements IRelat } } - + public void messageClan(ClanInfo clan, String message) + { + for (Player player : clan.getOnlinePlayers()) + UtilPlayer.message(player, message); + } + public void chatClan(ClanInfo clan, Player caller, String message) { - for (String cur : clan.getMembers().keySet()) - { - Player player = UtilPlayer.searchOnline(null, cur, false); - - if (player == null) - continue; - - UtilPlayer.message(player, C.cAqua + caller.getName() + " " + C.cDAqua + message); - } + messageClan(clan, C.cAqua + caller.getName() + " " + C.cDAqua + message); } public void chatAlly(ClanInfo clan, Player caller, String message) { - for (String cur : clan.getMembers().keySet()) - { - Player player = UtilPlayer.searchOnline(null, cur, false); + String sendMessage = C.cDGreen + clan.getName() + " " + C.cDGreen + caller.getName() + " " + C.cGreen + message; - if (player == null) - continue; + messageClan(clan, sendMessage); - UtilPlayer.message(player, C.cDGreen + clan.getName() + " " + C.cDGreen + caller.getName() + " " + C.cGreen + message); - } - for (String allyName : clan.getAllyMap().keySet()) { ClanInfo ally = _clanUtility.getClanByClanName(allyName); if (ally == null) continue; - - for (String playerName : ally.getMembers().keySet()) - { - Player player = UtilPlayer.searchOnline(null, playerName, false); - if (player == null) - continue; - - UtilPlayer.message(player, C.cDGreen + clan.getName() + " " + C.cDGreen + caller.getName() + " " + C.cGreen + message); - } + messageClan(ally, sendMessage); } } @@ -466,4 +483,14 @@ public class ClansManager extends MiniClientPlugin implements IRelat { return _classShop; } + + public int convertGoldToEnergy(int gold) + { + return gold * 4; + } + + public int convertEnergyToGold(int energy) + { + return (energy / 4) + (energy % 4 == 0 ? 0 : 1); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java index 53f71597c..0416e8ca3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java @@ -3,6 +3,7 @@ package mineplex.game.clans.clans.repository; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; +import java.util.UUID; import org.bukkit.plugin.java.JavaPlugin; @@ -27,7 +28,7 @@ public class ClanRepository extends RepositoryBase private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BOOL, PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));"; private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverName = ?;"; - private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;"; + private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;"; private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverName = ?;"; private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;"; @@ -117,7 +118,8 @@ public class ClanRepository extends RepositoryBase { ClanMemberToken memberToken = new ClanMemberToken(); memberToken.Name = resultSet.getString(2); - memberToken.ClanRole = resultSet.getString(3); + memberToken.PlayerUUID = UUID.fromString(resultSet.getString(3)); + memberToken.ClanRole = resultSet.getString(4); clans.get(clanName).Members.add(memberToken); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java index 3ff8fe52f..4af96feb0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java @@ -1,7 +1,10 @@ package mineplex.game.clans.clans.repository.tokens; +import java.util.UUID; + public class ClanMemberToken { public String Name; + public UUID PlayerUUID; public String ClanRole; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java index 9c6263372..7cd4061ff 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java @@ -5,6 +5,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; @@ -28,7 +30,7 @@ public class BuildingShop extends ShopBase { if (event.getMessage().startsWith("/gold")) { - UtilPlayer.message(event.getPlayer(), "PVP SHOP > Gold balance : " + DonationManager.Get(event.getPlayer().getName()).getGold()); + UtilPlayer.message(event.getPlayer(), F.main("Gold", "Your Balance is " + C.cYellow + DonationManager.Get(event.getPlayer().getName()).getGold() + "g")); event.setCancelled(true); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPage.java new file mode 100644 index 000000000..ee4400ea8 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyPage.java @@ -0,0 +1,129 @@ +package mineplex.game.clans.shop.energy; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; + +public class EnergyPage extends ShopPageBase +{ + private ClanInfo _clanInfo; + + public EnergyPage(ClansManager plugin, EnergyShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) + { + super(plugin, shop, clientManager, donationManager, "Energy Shop", player, 9); + _clanInfo = Plugin.getClan(Player); + + BuildPage(); + } + + @Override + protected void BuildPage() + { + if (_clanInfo == null) + { + buildNoClan(); + return; + } + else if (_clanInfo.getEnergyPurchasable() > 0) + { + if (hasEnoughGold()) + { + buildPurchasable(_clanInfo); + } + else + { + buildNotEnoughGold(_clanInfo); + } + } + else + { + buildMaxEnergy(_clanInfo); + } + } + + private void buildPurchasable(ClanInfo _clanInfo) + { + int playerGold = getPlayerGold(); + int energyCost = getEnergyPerHour(); + int goldCost = getGoldPerHour(); + + EnergyShopButton button = new EnergyShopButton(Player, Plugin, this, _clanInfo, true, getDonationManager()); + String title = "Purchase Energy"; + 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"); + String purchaseString = ChatColor.RESET + C.cWhite + "Click to buy 1 hour of energy for " + C.cYellow + goldCost + "g"; + ShopItem shopItem = new ShopItem(Material.LAVA_BUCKET, title, new String[] {" ", currentEnergy, energyString, " ", playerGoldString, purchaseString}, 0, false, false); + AddButton(4, shopItem, button); + } + + private void buildNotEnoughGold(ClanInfo _clanInfo) + { + int playerGold = getPlayerGold(); + int energyCost = getEnergyPerHour(); + int goldCost = getGoldPerHour(); + + EnergyShopButton button = new EnergyShopButton(Player, Plugin, this, _clanInfo, true, getDonationManager()); + String title = ChatColor.RED + C.Bold + "Missing Gold!"; + 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"); + 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"; + ShopItem shopItem = new ShopItem(Material.GOLD_INGOT, title, new String[] {" ", currentEnergy, energyString, " ", playerGoldString, purchaseString, goldString}, 0, false, false); + AddButton(4, shopItem, button); + } + + 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); + 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 Plugin.convertEnergyToGold(getEnergyPerHour()); + } + + protected int getEnergyPerHour() + { + return _clanInfo.getEnergyCostPerMinute() * 60; + } + + protected int getPlayerGold() + { + return getDonationManager().Get(Player).getGold(); + } + + public void showLoading() + { + ItemStack is = ItemStackFactory.Instance.CreateStack(Material.WOOL, (byte) 11, 1, C.cAqua + C.Bold + "Please Wait.."); + setItem(4, is); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShop.java new file mode 100644 index 000000000..cd7214b35 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShop.java @@ -0,0 +1,24 @@ +package mineplex.game.clans.shop.energy; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ClansManager; + +public class EnergyShop extends ShopBase +{ + + public EnergyShop(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Energy Shop"); + } + + @Override + protected ShopPageBase> BuildPagesFor(Player player) + { + return new EnergyPage(Plugin, this, ClientManager, DonationManager, player); + } +} 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 new file mode 100644 index 000000000..b956e5b82 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/energy/EnergyShopButton.java @@ -0,0 +1,57 @@ +package mineplex.game.clans.shop.energy; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.item.IButton; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; + +public class EnergyShopButton implements IButton +{ + private Player _player; + private ClansManager _clansManager; + private EnergyPage _page; + private ClanInfo _clanInfo; + private boolean _canPurchaseEnergy; + private DonationManager _donationManager; + + public EnergyShopButton(Player player, ClansManager clansManager, EnergyPage page, ClanInfo clanInfo, boolean canPurchaseEnergy, DonationManager donationManager) + { + _player = player; + _clansManager = clansManager; + _clanInfo = clanInfo; + _canPurchaseEnergy = canPurchaseEnergy; + _donationManager = donationManager; + _page = page; + } + + + @Override + public void onClick(final Player player, ClickType clickType) + { + if (_page.hasEnoughGold()) + { + int playerGold = _page.getPlayerGold(); + final int energy = _page.getEnergyPerHour(); + int goldCost = _page.getGoldPerHour(); + + _page.clearPage(); + _page.showLoading(); + _donationManager.RewardGold(new Callback() + { + @Override + public void run(Boolean data) + { + player.playSound(player.getEyeLocation(), Sound.ANVIL_USE, 1, 1); + _clanInfo.adjustEnergy(energy); + _page.Refresh(); + } + }, "Energy Purchase", player.getName(), player.getUniqueId(), -goldCost, true); + } + } + +}