Update Gem Fountain purchase gui

This commit is contained in:
Shaun Bennett 2016-05-18 15:59:04 +10:00
parent b802cdec6d
commit e3833b95ad
7 changed files with 92 additions and 18 deletions

View File

@ -2,11 +2,13 @@ package mineplex.core.brawl.fountain;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.brawl.fountain.gui.FountainShop; import mineplex.core.brawl.fountain.gui.FountainShop;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.hologram.Hologram; import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager; import mineplex.core.hologram.HologramManager;
import mineplex.core.shop.item.SalesPackageBase;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.serverdata.redis.counter.GoalCounter; import mineplex.serverdata.redis.counter.GoalCounter;
import mineplex.serverdata.redis.counter.GoalCounterListener; import mineplex.serverdata.redis.counter.GoalCounterListener;
@ -67,11 +69,21 @@ public class Fountain implements GoalCounterListener
public void increment(Player player, long amount) public void increment(Player player, long amount)
{ {
_statsManager.incrementStat(player, "Global.Fountain." + getDataKey(), amount); _statsManager.incrementStat(player, getStatName(), amount);
_counter.addAndGet(amount); _counter.addAndGet(amount);
updateVisuals(); updateVisuals();
} }
public long getAmountAdded(Player player)
{
return _statsManager.Get(player).getStat(getStatName());
}
private final String getStatName()
{
return "Global.Fountain." + getDataKey();
}
public String getName() public String getName()
{ {
return _name; return _name;

View File

@ -41,7 +41,7 @@ public class FountainManager extends MiniPlugin
World world = Bukkit.getWorlds().get(0); World world = Bukkit.getWorlds().get(0);
_gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -33.5, 71, -31.5), _gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -33.5, 71, -31.5),
C.cGreen + "Gem Fountain", "GemFountain", 1000000, this, clientManager, donationManager, _hologramManager, _statsManager); C.cGreen + "Gem Fountain", "GemFountain_01", 1000000, this, clientManager, donationManager, _hologramManager, _statsManager);
} }
@Override @Override

View File

@ -0,0 +1,27 @@
package mineplex.core.brawl.fountain;
import mineplex.core.common.CurrencyType;
import mineplex.core.shop.item.SalesPackageBase;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* @author Shaun Bennett
*/
public class GemFountainSalesPackage extends SalesPackageBase
{
public GemFountainSalesPackage(int gems)
{
super("Add " + gems + " Gems", Material.EMERALD, (byte) 0, new String[] {}, gems, 1);
CurrencyCostMap.put(CurrencyType.Gems, gems);
KnownPackage = false;
OneTimePurchaseOnly = false;
}
@Override
public void Sold(Player player, CurrencyType currencyType)
{
}
}

View File

@ -14,7 +14,7 @@ public class GuiCommand extends CommandBase<FountainManager>
{ {
public GuiCommand(FountainManager plugin) public GuiCommand(FountainManager plugin)
{ {
super(plugin, Rank.ADMIN, "gui"); super(plugin, Rank.ALL, "gui");
} }
@Override @Override

View File

@ -14,7 +14,7 @@ public class ResetCommand extends CommandBase<FountainManager>
{ {
public ResetCommand(FountainManager plugin) public ResetCommand(FountainManager plugin)
{ {
super(plugin, Rank.DEVELOPER, "reset"); super(plugin, Rank.ADMIN, "reset");
} }
@Override @Override

View File

@ -36,14 +36,16 @@ public class FountainPage extends ShopPageBase<FountainManager, FountainShop>
@Override @Override
protected void buildPage() protected void buildPage()
{ {
ShopItem addItem = new ShopItem(CurrencyType.Gems.GetDisplayMaterial(), "Add to Fountain", // Experience Bar
new String[] {}, 1, false, false); long added = _fountain.getAmountAdded(getPlayer());
addButton(22, addItem, new FountainAddButton());
final double fillPercent = _fountain.getFillPercent(); final double fillPercent = _fountain.getFillPercent();
String title = Math.round(fillPercent * 100) + "% Complete"; String title = Math.round(fillPercent * 100) + "% Complete";
String[] lore = new String[] { " ", C.cWhite + "Reaching the goal for this week will", C.cWhite + "unlock the weekend brawl minigame!" }; String[] lore = new String[] {
" ",
C.cWhite + "Reaching the goal for this week will",
C.cWhite + "unlock the weekend brawl minigame!",
" ",
C.cWhite + "You have added " + C.cGreen + added + " Gems"};
final double percentForEach = 1D / XP_SLOTS.length; final double percentForEach = 1D / XP_SLOTS.length;
double check = percentForEach; double check = percentForEach;
@ -57,5 +59,16 @@ public class FountainPage extends ShopPageBase<FountainManager, FountainShop>
setItem(XP_SLOTS[i], shopItem); setItem(XP_SLOTS[i], shopItem);
check += percentForEach; check += percentForEach;
} }
int playerGems = getDonationManager().Get(getPlayer()).GetGems();
ShopItem add1 = new ShopItem(Material.EMERALD, "Add 100 Gems", new String[] {}, 1, playerGems < 100, false);
ShopItem add2 = new ShopItem(Material.EMERALD, "Add 1,000 Gems", new String[] {}, 64, playerGems < 1000, false);
ShopItem add3 = new ShopItem(Material.EMERALD, "Add 10,000 Gems", new String[] {}, 1, playerGems < 10000, false);
ShopItem add4 = new ShopItem(Material.EMERALD, "Add 100,000 Gems", new String[] {}, 64, playerGems < 100000, false);
// Buttons
addButton(19, add1, new FountainAddButton(this, 100));
addButton(21, add2, new FountainAddButton(this, 1000));
addButton(23, add3, new FountainAddButton(this, 10000));
addButton(25, add4, new FountainAddButton(this, 100000));
} }
} }

View File

@ -1,9 +1,20 @@
package mineplex.core.brawl.fountain.gui.button; package mineplex.core.brawl.fountain.gui.button;
import mineplex.core.brawl.fountain.Fountain;
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.CurrencyType;
import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.SalesPackageBase;
import mineplex.core.shop.page.ConfirmationPage;
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;
@ -12,16 +23,27 @@ import org.bukkit.event.inventory.ClickType;
*/ */
public class FountainAddButton implements IButton public class FountainAddButton implements IButton
{ {
private final FountainPage _page;
private final int _gems;
private final SalesPackageBase _salesPackage;
public FountainAddButton(FountainPage page, int gems)
{
_page = page;
_gems = gems;
_salesPackage = new GemFountainSalesPackage(gems);
}
@Override @Override
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
player.closeInventory(); _page.getShop().openPageForPlayer(player, new ConfirmationPage<FountainManager, FountainShop>(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable()
{
new JsonMessage("Click to add to gem pool").sendToPlayer(player); public void run()
new JsonMessage(C.cGreenB + "100 Gems ").click(ClickEvent.RUN_COMMAND, "/fountain add 100") {
.extra(C.cGreenB + "1000 Gems ").click(ClickEvent.RUN_COMMAND, "/fountain add 1000") _page.getPlugin().getGemFountain().increment(player, _gems);
.extra(C.cGreenB + "10000 Gems ").click(ClickEvent.RUN_COMMAND, "/fountain add 10000") _page.refresh();
.extra(C.cGreenB + "100000 Gems ").click(ClickEvent.RUN_COMMAND, "/fountain add 100000") }
.sendToPlayer(player); }, _page, _salesPackage, CurrencyType.Gems, player));
} }
} }