From 2421fd1cfed2cb1b07890ed994506511768d8e27 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Fri, 10 Jun 2016 19:40:27 -0500 Subject: [PATCH] Update booster page, proper booster rewards --- .../core/boosters/BoosterManager.java | 59 ++++++++++++++++++- .../boosters/gui/ActivateBoosterButton.java | 34 ++++++----- .../core/boosters/gui/BoosterPage.java | 39 ++++++++---- .../core/boosters/gui/BoosterShop.java | 12 ++++ .../nautilus/game/arcade/ArcadeManager.java | 8 +++ .../game/arcade/managers/GameGemManager.java | 22 +++---- .../arcade/managers/GameLobbyManager.java | 3 +- 7 files changed, 138 insertions(+), 39 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java index a29a07973..4a8b1128c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java @@ -9,15 +9,24 @@ import mineplex.core.boosters.event.BoosterUpdateEvent; import mineplex.core.boosters.gui.BoosterShop; import mineplex.core.boosters.redis.BoosterUpdateRepository; import mineplex.core.boosters.tips.BoosterTipManager; +import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilInv; import mineplex.core.donation.DonationManager; import mineplex.core.inventory.InventoryManager; +import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; @@ -29,6 +38,10 @@ import java.util.*; */ public class BoosterManager extends MiniPlugin { + public static final String BOOSTER_ITEM = "Game Booster"; + public static final ItemStack INTERFACE_ITEM = ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte)0, 1, ChatColor.RESET + C.cGreen + "Booster Menu"); + public static final int INTERFACE_SLOT = 6; + private BoosterRepository _repository; private CoreClientManager _clientManager; private DonationManager _donationManager; @@ -38,6 +51,8 @@ public class BoosterManager extends MiniPlugin private BoosterShop _shop; private String _boosterGroup; + private boolean _giveInterfaceItem; + private long _cacheLastUpdated; private Map> _boosterCache = new HashMap<>(); @@ -64,6 +79,8 @@ public class BoosterManager extends MiniPlugin e.printStackTrace(); } + _giveInterfaceItem = canActivateBoosters(); + new BoosterUpdateRepository(plugin); } @@ -181,6 +198,11 @@ public class BoosterManager extends MiniPlugin return time; } + public Booster getActiveBooster() + { + return getActiveBoosterFromCache(_boosterGroup); + } + public Booster getActiveBoosterFromCache(String boosterGroup) { List boosters = _boosterCache.get(boosterGroup); @@ -212,6 +234,11 @@ public class BoosterManager extends MiniPlugin }); } + public void activateBooster(Player player, Callback callback) + { + activateBooster(_boosterGroup, player, callback); + } + public void activateBooster(String serverGroup, Player player, Callback callback) { String playerName = player.getName(); @@ -224,6 +251,11 @@ public class BoosterManager extends MiniPlugin }); } + public void chargeBooster(Player player, Callback callback) + { + _inventoryManager.addItemToInventory(callback, player, BOOSTER_ITEM, -1); + } + public void openShop(Player player) { _shop.attemptShopOpen(player); @@ -247,7 +279,7 @@ public class BoosterManager extends MiniPlugin */ public int getAvailableBoosterCount(Player player) { - return _inventoryManager.Get(player).getItemCount("Game Booster"); + return _inventoryManager.Get(player).getItemCount(BOOSTER_ITEM); } /** @@ -259,6 +291,31 @@ public class BoosterManager extends MiniPlugin return _boosterGroup != null && _boosterGroup.length() > 0; } + public void giveInterfaceItem(Player player) + { + if (_giveInterfaceItem && !UtilGear.isMat(player.getInventory().getItem(INTERFACE_SLOT), Material.EMERALD)) + { + player.getInventory().setItem(INTERFACE_SLOT, INTERFACE_ITEM); + + UtilInv.Update(player); + } + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + giveInterfaceItem(event.getPlayer()); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + if (INTERFACE_ITEM.equals(event.getPlayer().getItemInHand())) + { + openShop(event.getPlayer()); + } + } + public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException { BoosterRepository repository = new BoosterRepository(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/ActivateBoosterButton.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/ActivateBoosterButton.java index 9aa9a054a..a872b6ca0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/ActivateBoosterButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/ActivateBoosterButton.java @@ -4,6 +4,7 @@ import mineplex.core.boosters.BoosterApiResponse; import mineplex.core.boosters.BoosterManager; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; import mineplex.core.common.util.UtilTime; import mineplex.core.shop.item.IButton; import org.bukkit.entity.Player; @@ -27,21 +28,26 @@ public class ActivateBoosterButton implements IButton public void onClick(Player player, ClickType clickType) { player.closeInventory(); - _boosterManager.activateBooster("Testing", player, new Callback() - { - @Override - public void run(BoosterApiResponse response) + + _boosterManager.chargeBooster(player, data -> { + if (data) { - if (response.isSuccess()) - { - long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis(); - if (timeToStart <= 0) player.sendMessage(C.cGreen + "Booster activated and enabled now!"); - else player.sendMessage(C.cGreen + "Booster activated. Enabled in " + UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT)); - } - else - { - player.sendMessage(C.cRed + "There was an error trying to enable your booster :("); - } + _boosterManager.activateBooster(player, response -> { + if (response.isSuccess()) + { + long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis(); + if (timeToStart <= 0) player.sendMessage(F.main("Booster", "Booster Activated!")); + else player.sendMessage(F.main("Booster", "Booster Added. It will start in " + F.elem(UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT)))); + } + else + { + player.sendMessage(C.cRed + "There was an error trying to enable your booster :("); + } + }); + } + else + { + player.sendMessage(F.main("Booster", "There was an error charging your account. Try again later!")); } }); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java index 952ff1cff..4fe09ba97 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java @@ -34,25 +34,41 @@ public class BoosterPage extends ShopPageBase int count = getPlugin().getAvailableBoosterCount(getPlayer()); lore.add(" "); - lore.add(C.cWhite + "You Own: " + getPlugin().getAvailableBoosterCount(getPlayer())); + lore.add(C.cWhite + "You Own " + C.cGreen + getPlugin().getAvailableBoosterCount(getPlayer())); if (getPlugin().canActivateBoosters() && count > 0) { + List boosters = getPlugin().getBoosters(); lore.add(" "); - lore.add(C.cWhite + "Click to Activate"); long waitTime = getPlugin().getBoostTime(); if (waitTime == 0) { - lore.add(C.cWhite + "Booster would activate " + C.cGreen + "now"); + lore.add(C.cGray + "Booster would activate " + C.cGreen + "now"); + lore.add(" "); + lore.add(C.cWhite + "Click to Activate Booster"); } else { - lore.add(C.cWhite + "Booster would activate in " + C.cGreen + UtilTime.convertString(waitTime, 1, UtilTime.TimeUnit.FIT)); + if (boosters.size() > 1) + { + lore.add(C.cGray + "There are " + C.cGreen + (boosters.size() - 1) + C.cGray + " boosters in queue"); + } + + lore.add(C.cGray + "Activation Time: " + C.cGreen + UtilTime.convertColonString(waitTime, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS)); + lore.add(" "); + lore.add(C.cWhite + "Click to Queue Booster"); } } ShopItem booster = new ShopItem(Material.SUGAR, "Game Booster", lore.toArray(new String[0]), 0, false, false); - setItem(4, booster); + if (getPlugin().canActivateBoosters()) + { + addButton(4, booster, new ActivateBoosterButton(getShop(), getPlugin())); + } + else + { + setItem(4, booster); + } addActiveBoosters(); } @@ -70,24 +86,25 @@ public class BoosterPage extends ShopPageBase int index = 18 + startIndex + i; long timeActivatedDif = System.currentTimeMillis() - booster.getActivationTime().getTime(); + String activationTime = UtilTime.convertString(timeActivatedDif, 2, UtilTime.TimeUnit.FIT); List lore = new ArrayList(); - lore.add(" "); if (active) { - lore.add(C.cGreen + "Active"); + lore.add(C.cWhite + "Active"); } else { long timeToActive = booster.getStartTime().getTime() - System.currentTimeMillis(); - lore.add(C.cWhite + "Activates in " + C.cGreen + UtilTime.convertString(timeToActive, 2, UtilTime.TimeUnit.FIT)); + lore.add(C.cWhite + "Starts in " + C.cGreen + UtilTime.convertColonString(timeToActive, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS)); } - String activationTime = UtilTime.convertString(timeActivatedDif, 2, UtilTime.TimeUnit.FIT); + lore.add(" "); + lore.add(C.cGray + "Added " + activationTime + " ago"); + ShopItem shopItem = new ShopItem(booster.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK, - "Added " + activationTime + " ago", lore.toArray(new String[0]), 1, false, false); + "Game Booster", lore.toArray(new String[0]), 1, !active, false); setItem(index, shopItem); } - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterShop.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterShop.java index 09787ecb7..92a515587 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterShop.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterShop.java @@ -5,7 +5,10 @@ import mineplex.core.boosters.BoosterManager; import mineplex.core.donation.DonationManager; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; /** * @author Shaun Bennett @@ -22,4 +25,13 @@ public class BoosterShop extends ShopBase { return new BoosterPage(getPlugin(), this, getClientManager(), getDonationManager(), player); } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + getPlayerPageMap().values().forEach(ShopPageBase::refresh); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index dc96d4551..c47d59f8b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -194,6 +194,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private Punish _punishmentManager; private BrandingManager _brandingManager; private BonusManager _bonusManager; + private BoosterManager _boosterManager; private IncognitoManager _incognitoManager; @@ -246,6 +247,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation _brandingManager = new BrandingManager(plugin); + _boosterManager = boosterManager; + //Dont see a reason to ever just use the normal one // if (serverConfig.GameList.contains(GameType.ChampionsDominate) // || serverConfig.GameList.contains(GameType.ChampionsTDM) @@ -1452,6 +1455,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation return _youtube.contains(player); } + public BoosterManager getBoosterManager() + { + return _boosterManager; + } + public void toggleUnlockKits(Player caller) { if (_youtube.remove(caller)) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java index ef80000d0..b225577dd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java @@ -180,10 +180,11 @@ public class GameGemManager implements Listener } //Gem Boooster - /* - if (game.GemBoosterEnabled && game.getGemBooster() != null) - total += (int)(earned * game.getGemBooster().getMultiplier()); - */ + Booster booster = Manager.getBoosterManager().getActiveBooster(); + if (game.GemBoosterEnabled && booster != null) + { + total *= booster.getMultiplier(); + } int shards = total; @@ -309,16 +310,15 @@ public class GameGemManager implements Listener int totalGems = earnedGems; //Gem Booster - /* - Booster gemBooster = game.getGemBooster(); - if (game.GemBoosterEnabled && gemBooster != null) + Booster booster = Manager.getBoosterManager().getActiveBooster(); + if (game.GemBoosterEnabled && booster != null) { - UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int) (earnedGems * gemBooster.getMultiplier()) + " Gems") + " for gem booster from " - + F.name(gemBooster.getPlayerName())); + int addedGems = (int) (earnedGems * booster.getMultiplier()) - earnedGems; + UtilPlayer.message(player, F.elem(C.cGreen + "+" + addedGems + " Gems") + " for gem booster from " + + F.name(booster.getPlayerName())); - totalGems += earnedGems * gemBooster.getMultiplier(); + totalGems *= booster.getMultiplier(); } - */ int shards = totalGems; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index 027865cbb..4e73bd40b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -86,8 +86,6 @@ public class GameLobbyManager implements Listener private Location spawn; - private Location _boosterLocation; - private NautHashMap _kits = new NautHashMap(); private NautHashMap _kitBlocks = new NautHashMap(); @@ -1337,6 +1335,7 @@ public class GameLobbyManager implements Listener //Cosmetic Menu Manager.getCosmeticManager().giveInterfaceItem(player); + Manager.getBoosterManager().giveInterfaceItem(player); } }