Implement Fountain GUI

This commit is contained in:
Shaun Bennett 2016-04-24 12:40:38 +10:00
parent 8a5fdccb60
commit c60beec68c
9 changed files with 107 additions and 9 deletions

View File

@ -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)
{

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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<FountainManager>
{
public AddCommand(FountainManager plugin)
{
super(plugin, Rank.ADMIN, "add");
super(plugin, Rank.ALL, "add");
}
@Override
@ -28,9 +32,28 @@ public class AddCommand extends CommandBase<FountainManager>
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<TransactionResponse>()
{
@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)
{

View File

@ -12,7 +12,7 @@ public class FountainCommand extends MultiCommandBase<FountainManager>
{
public FountainCommand(FountainManager plugin)
{
super(plugin, Rank.ADMIN, "fountain");
super(plugin, Rank.ALL, "fountain");
AddCommand(new AddCommand(plugin));
AddCommand(new GuiCommand(plugin));

View File

@ -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<FountainManager, FountainShop>
{
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<FountainManager, FountainShop>
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;
}
}
}

View File

@ -25,7 +25,7 @@ public class FountainShop extends ShopBase<FountainManager>
@Override
protected ShopPageBase<FountainManager, ? extends ShopBase<FountainManager>> buildPagesFor(Player player)
{
return new FountainPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
return new FountainPage(getPlugin(), this, getClientManager(), getDonationManager(), _fountain, player);
}
public Fountain getFountain()

View File

@ -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);
}
}

View File

@ -74,6 +74,11 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
}
public void purchaseUnknownSalesPackage(Callback<TransactionResponse> 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<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;