From e339b0352a820c4f601309f8aaa1b1f74f7cac8c Mon Sep 17 00:00:00 2001 From: Nate Mortensen Date: Mon, 19 Dec 2016 16:23:10 -0700 Subject: [PATCH] Make GameComponent generic and store an instance of the Game. --- .../game/arcade/game/GameComponent.java | 10 ++++++++-- .../game/games/wizards/WizardSpellMenu.java | 18 ++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameComponent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameComponent.java index 00118f80c..2dba42c07 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameComponent.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameComponent.java @@ -6,12 +6,14 @@ import mineplex.core.lifetimes.ListenerComponent; import java.util.Arrays; -public class GameComponent extends ListenerComponent implements Lifetimed +public class GameComponent extends ListenerComponent implements Lifetimed { private final Lifetime _lifetime; + private final T _game; - public GameComponent(Game game, Game.GameState...active) + public GameComponent(T game, Game.GameState...active) { + _game = game; if (active == null || active.length == 0) { // Active for the entire duration of the game. @@ -28,4 +30,8 @@ public class GameComponent extends ListenerComponent implements Lifetimed { return _lifetime; } + + public T getGame() { + return _game; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java index f9f5a9236..e83bb4840 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java @@ -22,9 +22,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -public class WizardSpellMenu extends GameComponent +public class WizardSpellMenu extends GameComponent { - private Wizards _wizards; private WizardSpellMenuShop _wizardShop; private ItemStack _wizardSpells = new ItemBuilder(Material.ENCHANTED_BOOK).setTitle(C.cGold + "Wizard Spells") .addLore(C.cGray + "Right click with this to view the spells").build(); @@ -34,13 +33,12 @@ public class WizardSpellMenu extends GameComponent super(wizards); _wizardShop = new WizardSpellMenuShop(this, wizards.getArcadeManager().GetClients(), wizards.getArcadeManager() .GetDonation(), wizards); - _wizards = wizards; } @EventHandler public void onJoin(PlayerJoinEvent event) { - if (_wizards.GetState() == GameState.Recruit || _wizards.GetState() == GameState.Live) + if (getGame().GetState() == GameState.Recruit || getGame().GetState() == GameState.Live) { event.getPlayer().getInventory().setItem(0, _wizardSpells); } @@ -53,7 +51,7 @@ public class WizardSpellMenu extends GameComponent { public void run() { - if (_wizards.IsLive()) + if (getGame().IsLive()) { event.getEntity().getInventory().setItem(0, _wizardSpells); } @@ -66,7 +64,7 @@ public class WizardSpellMenu extends GameComponent { if (event.getMessage().equalsIgnoreCase("/spec")) { - if (!_wizards.IsAlive(event.getPlayer()) + if (!getGame().IsAlive(event.getPlayer()) && !UtilInv.contains(event.getPlayer(), _wizardSpells.getType(), (byte) 0, 1)) { event.getPlayer().getInventory().setItem(0, _wizardSpells); @@ -88,7 +86,7 @@ public class WizardSpellMenu extends GameComponent { for(Player player : UtilServer.GetPlayers()) { - if (!_wizards.IsAlive(player)) + if (!getGame().IsAlive(player)) { player.getInventory().setItem(0, _wizardSpells); } @@ -100,7 +98,7 @@ public class WizardSpellMenu extends GameComponent public void onInteract(PlayerInteractEvent event) { if (event.getAction() != Action.PHYSICAL && event.getAction().name().contains("RIGHT") - && (!_wizards.IsLive() || !_wizards.IsAlive(event.getPlayer()))) + && (!getGame().IsLive() || !getGame().IsAlive(event.getPlayer()))) { ItemStack item = event.getItem(); @@ -112,11 +110,11 @@ public class WizardSpellMenu extends GameComponent } } - if (_wizards.IsLive() && _wizards.IsAlive(event.getPlayer())) + if (getGame().IsLive() && getGame().IsAlive(event.getPlayer())) { Player p = event.getPlayer(); - if (p.getInventory().getHeldItemSlot() < _wizards.getWizard(p).getWandsOwned()) + if (p.getInventory().getHeldItemSlot() < getGame().getWizard(p).getWandsOwned()) { if (event.getAction().name().contains("RIGHT")) {