From 137b8692e433044dbefcd480f67267dd0d40e55f Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 26 Aug 2014 00:33:48 -0700 Subject: [PATCH] Added Gem booster use. --- .../core/cosmetic/CosmeticManager.java | 4 +- .../event/ActivateGemBoosterEvent.java | 44 +++++++++++ .../core/cosmetic/ui/CosmeticShop.java | 15 +++- .../mineplex/core/cosmetic/ui/page/Menu.java | 78 ++++++++++++------- .../mineplex/core/inventory/GemBooster.java | 7 +- .../src/mineplex/hub/HubManager.java | 2 +- .../src/nautilus/game/arcade/Arcade.java | 2 +- .../src/nautilus/game/arcade/GameFactory.java | 1 - .../arcade/managers/GameLobbyManager.java | 31 +++----- 9 files changed, 127 insertions(+), 57 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/cosmetic/event/ActivateGemBoosterEvent.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java index ffae2320d..80f378357 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java @@ -37,7 +37,7 @@ public class CosmeticManager extends MiniPlugin private boolean _showInterface = true; private int _interfaceSlot = 4; - public CosmeticManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager) + public CosmeticManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager, boolean useBooster) { super("Cosmetic Manager", plugin); @@ -46,7 +46,7 @@ public class CosmeticManager extends MiniPlugin _mountManager = mountManager; _petManager = petManager; - _shop = new CosmeticShop(this, clientManager, donationManager, _moduleName); + _shop = new CosmeticShop(this, clientManager, donationManager, _moduleName, useBooster); } public void showInterface(boolean showInterface) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/event/ActivateGemBoosterEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/event/ActivateGemBoosterEvent.java new file mode 100644 index 000000000..9d7318bb1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/event/ActivateGemBoosterEvent.java @@ -0,0 +1,44 @@ +package mineplex.core.cosmetic.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ActivateGemBoosterEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + + private boolean _cancelled = false; + + public ActivateGemBoosterEvent(Player player) + { + _player = player; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Player getPlayer() + { + return _player; + } + + public void setCancelled(boolean cancel) + { + _cancelled = cancel; + } + + public boolean isCancelled() + { + return _cancelled; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/CosmeticShop.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/CosmeticShop.java index ed0313350..7d709cf94 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/CosmeticShop.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/CosmeticShop.java @@ -13,7 +13,6 @@ import mineplex.core.cosmetic.ui.page.PetTagPage; import mineplex.core.cosmetic.ui.page.TreasurePage; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.event.ItemGadgetOutOfAmmoEvent; -import mineplex.core.inventory.InventoryManager; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.core.updater.UpdateType; @@ -21,10 +20,13 @@ import mineplex.core.updater.event.UpdateEvent; public class CosmeticShop extends ShopBase implements PluginMessageListener { - public CosmeticShop(CosmeticManager plugin, CoreClientManager clientManager, DonationManager donationManager, String name) + private boolean _useBooster; + + public CosmeticShop(CosmeticManager plugin, CoreClientManager clientManager, DonationManager donationManager, String name, boolean useBooster) { super(plugin, clientManager, donationManager, name, CurrencyType.Gems, CurrencyType.Coins); + _useBooster = useBooster; plugin.GetPlugin().getServer().getMessenger().registerIncomingPluginChannel(plugin.GetPlugin(), "MC|ItemName", this); } @@ -56,6 +58,7 @@ public class CosmeticShop extends ShopBase implements PluginMes { new GadgetPage(Plugin, this, ClientManager, DonationManager, "Gadgets", event.getPlayer()).purchaseGadget(event.getPlayer(), event.getGadget()); } + @EventHandler public void updateTreasure(UpdateEvent event) { @@ -67,4 +70,10 @@ public class CosmeticShop extends ShopBase implements PluginMes if (shop instanceof TreasurePage) ((TreasurePage) shop).update(); } - }} + } + + public boolean getBoosterEnabled() + { + return _useBooster; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java index 8686cacf7..4394c3f90 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java @@ -1,29 +1,26 @@ package mineplex.core.cosmetic.ui.page; -import org.bukkit.ChatColor; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import mineplex.core.account.CoreClientManager; import mineplex.core.common.CurrencyType; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; import mineplex.core.cosmetic.CosmeticManager; +import mineplex.core.cosmetic.event.ActivateGemBoosterEvent; import mineplex.core.cosmetic.ui.CosmeticShop; -import mineplex.core.cosmetic.ui.button.DeactivateGadgetButton; -import mineplex.core.cosmetic.ui.button.DeactivateMountButton; -import mineplex.core.cosmetic.ui.button.DeactivatePetButton; import mineplex.core.cosmetic.ui.button.OpenGadgets; import mineplex.core.cosmetic.ui.button.OpenMorphs; import mineplex.core.cosmetic.ui.button.OpenMounts; import mineplex.core.cosmetic.ui.button.OpenParticles; import mineplex.core.cosmetic.ui.button.OpenPets; -import mineplex.core.cosmetic.ui.button.TreasureButton; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.inventory.GemBooster; import mineplex.core.mount.Mount; +import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.SingleButton; import mineplex.core.shop.page.ConfirmationPage; @@ -52,35 +49,48 @@ public class Menu extends ShopPageBase else { */ - AddItem(13, new ShopItem(Material.CHEST, C.cGold + treasureChestCount + " Treasure Chests", 1, false)); + AddItem(13, new ShopItem(Material.CHEST, C.cGold + treasureChestCount + " Treasure Chests (COMING SOON!)", 1, false)); //} - final GemBooster gemBoosterItem = new GemBooster(Plugin.getInventoryManager().Get(Player).getItemCount("Gem Booster")); + final GemBooster gemBoosterItem = new GemBooster(Shop.getBoosterEnabled(), Plugin.getInventoryManager().Get(Player).getItemCount("Gem Booster")); - if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= gemBoosterItem.GetCost(CurrencyType.Coins)) - { - AddButton(15, new ShopItem( - gemBoosterItem.GetDisplayMaterial(), - gemBoosterItem.GetDisplayName(), - gemBoosterItem.GetDescription(), - 1, - false), - new SingleButton() + + AddButton(15, new ShopItem( + gemBoosterItem.GetDisplayMaterial(), + gemBoosterItem.GetDisplayName(), + gemBoosterItem.GetDescription(), + 1, + false), + new IButton() + { + @Override + public void ClickedLeft(Player player) { - @Override - public void Clicked(Player player) + if (Shop.getBoosterEnabled()) { - Shop.OpenPageForPlayer(Player, new ConfirmationPage(Plugin, Shop, ClientManager, DonationManager, new Runnable() - { - public void run() - { - Plugin.getInventoryManager().addItemToInventory(Player, "Utility", "Gem Booster", 20); - Shop.OpenPageForPlayer(Player, new Menu(Plugin, Shop, ClientManager, DonationManager, Player)); - } - }, null, gemBoosterItem, CurrencyType.Coins, Player)); + ActivateGemBoosterEvent boosterEvent = new ActivateGemBoosterEvent(player); + Bukkit.getServer().getPluginManager().callEvent(boosterEvent); + + if (!boosterEvent.isCancelled()) + Plugin.getInventoryManager().addItemToInventory(Player, "Utility", "Gem Booster", -1); + } + else + { + purchaseGemBooster(gemBoosterItem, player); } } - ); + + @Override + public void ClickedRight(Player player) + { + purchaseGemBooster(gemBoosterItem, player); + } + } + ); + + if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= gemBoosterItem.GetCost(CurrencyType.Coins)) + { + } else { @@ -186,6 +196,18 @@ public class Menu extends ShopPageBase } } + private void purchaseGemBooster(GemBooster gemBoosterItem, Player player) + { + Shop.OpenPageForPlayer(Player, new ConfirmationPage(Plugin, Shop, ClientManager, DonationManager, new Runnable() + { + public void run() + { + Plugin.getInventoryManager().addItemToInventory(Player, "Utility", "Gem Booster", 20); + Shop.OpenPageForPlayer(Player, new Menu(Plugin, Shop, ClientManager, DonationManager, Player)); + } + }, null, gemBoosterItem, CurrencyType.Coins, Player)); + } + public void openParticles(Player player) { Shop.OpenPageForPlayer(player, new ParticlePage(Plugin, Shop, ClientManager, DonationManager, "Particles", player)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/GemBooster.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/GemBooster.java index bc4b473cf..2431b67c4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/GemBooster.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/GemBooster.java @@ -5,20 +5,25 @@ import org.bukkit.entity.Player; import mineplex.core.common.CurrencyType; import mineplex.core.common.util.C; +import mineplex.core.gadget.types.ItemGadget; import mineplex.core.shop.item.SalesPackageBase; public class GemBooster extends SalesPackageBase { - public GemBooster(int gemBoosters) + public GemBooster(boolean enabled, int gemBoosters) { super("20 Gem Booster Pack", Material.EMERALD, (byte)0, new String[] { C.cYellow + "1000 Coins", " ", + (enabled ? C.cGreen + "Left-Click To Use:" : ""), C.cWhite + "Use these before games start to", C.cWhite + "boost the amount of Gems earned", C.cWhite + "for all players in the game!", " ", + C.cGreen + "Right-Click To Purchase:", + C.cWhite + "20 Gem Boosters for " + C.cYellow + "1000 Coins", + " ", C.cWhite + "Your Gem Boosters: " + C.cGreen + gemBoosters }, 1000, 20); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 26a8532d4..ec1a5020b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -157,7 +157,7 @@ public class HubManager extends MiniClientPlugin _mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager); _inventoryManager = new InventoryManager(plugin); _gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin)); - new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager); + new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, false); _partyManager = partyManager; _preferences = preferences; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index b4dbfd5c6..c972d0f14 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -116,7 +116,7 @@ public class Arcade extends JavaPlugin PetManager petManager = new PetManager(this, _clientManager, _donationManager, creature, webServerAddress); MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager); GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager); - CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager); + CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, true); cosmeticManager.setInterfaceSlot(7); //Arcade Manager diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java index 7c2310a51..5ff22c544 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java @@ -26,7 +26,6 @@ import nautilus.game.arcade.game.games.halloween.Halloween; import nautilus.game.arcade.game.games.hideseek.HideSeek; import nautilus.game.arcade.game.games.micro.Micro; import nautilus.game.arcade.game.games.milkcow.MilkCow; -import nautilus.game.arcade.game.games.minestrike.MineStrike; import nautilus.game.arcade.game.games.mineware.MineWare; import nautilus.game.arcade.game.games.quiver.Quiver; import nautilus.game.arcade.game.games.quiver.QuiverTeams; 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 1e88d7fd4..251c54dad 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 @@ -41,6 +41,7 @@ import org.bukkit.scoreboard.Scoreboard; import mineplex.core.account.CoreClient; import mineplex.core.common.Rank; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilEnt; @@ -51,6 +52,7 @@ import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText.TextAlign; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; +import mineplex.core.cosmetic.event.ActivateGemBoosterEvent; import mineplex.core.donation.Donor; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.packethandler.IPacketRunnable; @@ -1178,29 +1180,18 @@ public class GameLobbyManager implements IPacketRunnable, Listener } @EventHandler(priority = EventPriority.LOWEST) - public void GemBoosterInteract(PlayerInteractEvent event) + public void GemBoosterInteract(ActivateGemBoosterEvent event) { - if (Manager.IsTournamentServer()) + if (Manager.IsTournamentServer() || Manager.GetGame() == null || Manager.GetGame().GetState() != GameState.Recruit) + { + event.setCancelled(true); + + event.getPlayer().sendMessage(F.main("Arcade", "You can't use Gem Boosters right now.")); + return; + } - Player player = event.getPlayer(); - - if (player.getItemInHand() == null) - return; - - if (player.getItemInHand().getType() != Material.EMERALD) - return; - - if (Manager.GetGame() == null) - return; - - if (Manager.GetGame().GetState() != GameState.Recruit) - return; - - if (Manager.getInventoryManager().Get(player).getItemCount("Gem Booster") <= 0) - return; - - Manager.GetGame().AddGemBooster(player); + Manager.GetGame().AddGemBooster(event.getPlayer()); } @EventHandler(priority = EventPriority.LOWEST)