diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java index cf8210198..e4493384c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java @@ -23,6 +23,16 @@ public class MaterialData return new MaterialData(material, data); } + public Material getMaterial() + { + return _material; + } + + public byte getData() + { + return _data; + } + @Override public boolean equals(Object o) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java index eea7a4146..81c03a54a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java @@ -23,12 +23,13 @@ public class Fountain private final String _name; private final String _dataKey; private final Location _location; + private Location _lavaLocation; private final Hologram _hologram; private final Counter _counter; private final FountainShop _shop; - public Fountain(Location location, String name, String dataKey, long goal, FountainManager fountainManager, + public Fountain(Location location, Location lavaLocation, String name, String dataKey, long goal, FountainManager fountainManager, CoreClientManager clientManager, DonationManager donationManager, HologramManager hologramManager, StatsManager statsManager) { @@ -38,6 +39,7 @@ public class Fountain _name = name; _dataKey = dataKey; _location = location; + _lavaLocation = lavaLocation; _hologram = new Hologram(hologramManager, location.clone().add(0, 2, 0), name).start(); _counter = new Counter(dataKey, goal); @@ -84,4 +86,14 @@ public class Fountain { _shop.attemptShopOpen(player); } + + public double getFillPercent() + { + return _counter.getFillPercent(); + } + + public long getCount() + { + return _counter.getCount(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java index efdff59c3..257a57ec0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java @@ -15,6 +15,7 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.redis.counter.Counter; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -26,6 +27,7 @@ public class FountainManager extends MiniPlugin { private HologramManager _hologramManager; private StatsManager _statsManager; + private DonationManager _donationManager; private Fountain _gemFountain; @@ -35,8 +37,10 @@ public class FountainManager extends MiniPlugin _hologramManager = hologramManager; _statsManager = statsManager; + _donationManager = donationManager; - _gemFountain = new Fountain(new Location(Bukkit.getWorlds().get(0), -32.5, 72, -23.5), + 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), C.cGreen + "Gem Fountain", "GemFountain", 1000000, this, clientManager, donationManager, _hologramManager, _statsManager); } @@ -59,4 +63,9 @@ public class FountainManager extends MiniPlugin { return _gemFountain; } + + public DonationManager getDonationManager() + { + return _donationManager; + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java index 1a6235154..1b0b70843 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java @@ -2,10 +2,14 @@ package mineplex.core.brawl.fountain.command; import mineplex.core.brawl.fountain.FountainManager; import mineplex.core.command.CommandBase; +import mineplex.core.common.CurrencyType; import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.server.util.TransactionResponse; import org.bukkit.entity.Player; +import org.omg.PortableInterceptor.SUCCESSFUL; /** * @author Shaun Bennett @@ -14,7 +18,7 @@ public class AddCommand extends CommandBase { public AddCommand(FountainManager plugin) { - super(plugin, Rank.ADMIN, "add"); + super(plugin, Rank.ALL, "add"); } @Override @@ -28,9 +32,28 @@ public class AddCommand extends CommandBase try { - long amount = Long.parseLong(args[0]); - Plugin.getGemFountain().increment(caller, amount); - UtilPlayer.message(caller, F.main("Fountain", "Added " + F.elem(amount) + " to the fountain!")); + int amount = Integer.parseInt(args[0]); + + Plugin.getDonationManager().purchaseUnknownSalesPackage(new Callback() + { + @Override + public void run(TransactionResponse result) + { + if (result == TransactionResponse.Success) + { + Plugin.getGemFountain().increment(caller, amount); + UtilPlayer.message(caller, F.main("Fountain", "Added " + F.elem(amount) + " to the fountain!")); + } + else if (result == TransactionResponse.InsufficientFunds) + { + UtilPlayer.message(caller, F.main("Fountain", "You do not have enough gems!")); + } + else + { + UtilPlayer.message(caller, F.main("Fountain", "There was an error processing your request!")); + } + } + }, caller, "GemFountain.Add", CurrencyType.Gems, amount, false); } catch (NumberFormatException ex) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/FountainCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/FountainCommand.java index 12397b482..65c306ed3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/FountainCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/FountainCommand.java @@ -12,7 +12,7 @@ public class FountainCommand extends MultiCommandBase { public FountainCommand(FountainManager plugin) { - super(plugin, Rank.ADMIN, "fountain"); + super(plugin, Rank.ALL, "fountain"); AddCommand(new AddCommand(plugin)); AddCommand(new GuiCommand(plugin)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainPage.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainPage.java index c2d8f840b..920fdaa60 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainPage.java @@ -1,12 +1,16 @@ package mineplex.core.brawl.fountain.gui; import mineplex.core.account.CoreClientManager; +import mineplex.core.brawl.fountain.Fountain; import mineplex.core.brawl.fountain.FountainManager; import mineplex.core.brawl.fountain.gui.button.FountainAddButton; import mineplex.core.common.CurrencyType; +import mineplex.core.common.MaterialData; +import mineplex.core.common.util.C; import mineplex.core.donation.DonationManager; import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ShopPageBase; +import org.bukkit.Material; import org.bukkit.entity.Player; /** @@ -14,10 +18,18 @@ import org.bukkit.entity.Player; */ public class FountainPage extends ShopPageBase { - public FountainPage(FountainManager plugin, FountainShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) + private final MaterialData EMPTY_XP = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 7); + private final MaterialData XP = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 5); + private final int[] XP_SLOTS = { 2, 3, 4, 5, 6 }; + + private Fountain _fountain; + + public FountainPage(FountainManager plugin, FountainShop shop, CoreClientManager clientManager, DonationManager donationManager, Fountain fountain, Player player) { super(plugin, shop, clientManager, donationManager, "Fountain Keeper", player, 27); + _fountain = fountain; + buildPage(); } @@ -28,5 +40,22 @@ public class FountainPage extends ShopPageBase new String[] {}, 1, false, false); addButton(22, addItem, new FountainAddButton()); + + final double fillPercent = _fountain.getFillPercent(); + 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!" }; + + final double percentForEach = 1D / XP_SLOTS.length; + double check = percentForEach; + + for (int i = 0; i < XP_SLOTS.length; i++) + { + MaterialData data = fillPercent >= check ? XP : EMPTY_XP; + ShopItem shopItem = new ShopItem(data.getMaterial(), data.getData(), title, + lore, 1, false, false); + + setItem(XP_SLOTS[i], shopItem); + check += percentForEach; + } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainShop.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainShop.java index e6fc7cde7..227aee069 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainShop.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/gui/FountainShop.java @@ -25,7 +25,7 @@ public class FountainShop extends ShopBase @Override protected ShopPageBase> buildPagesFor(Player player) { - return new FountainPage(getPlugin(), this, getClientManager(), getDonationManager(), player); + return new FountainPage(getPlugin(), this, getClientManager(), getDonationManager(), _fountain, player); } public Fountain getFountain() 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 a8f7de39d..43e1d48d7 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,5 +1,8 @@ package mineplex.core.brawl.fountain.gui.button; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; import mineplex.core.shop.item.IButton; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -12,6 +15,13 @@ public class FountainAddButton implements IButton @Override public void onClick(Player player, ClickType clickType) { + player.closeInventory(); + new JsonMessage("Click to add to gem pool").sendToPlayer(player); + 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") + .extra(C.cGreenB + "10000 Gems ").click(ClickEvent.RUN_COMMAND, "/fountain add 10000") + .extra(C.cGreenB + "100000 Gems ").click(ClickEvent.RUN_COMMAND, "/fountain add 100000") + .sendToPlayer(player); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 379d048bc..b5708c16e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -73,6 +73,11 @@ public class DonationManager extends MiniDbClientPlugin Get(token.Name).loadToken(token.DonorToken); //_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins()); } + + public void purchaseUnknownSalesPackage(Callback callback, Player player, String packageName, CurrencyType currencyType, int cost, boolean oneTimePurchase) + { + PurchaseUnknownSalesPackage(callback, player.getName(), getClientManager().getAccountId(player), packageName, currencyType, cost, oneTimePurchase); + } public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final int accountId, final String packageName, final CurrencyType currencyType, final int cost, boolean oneTimePurchase) {