Make GameComponent generic and store an instance of the Game.
This commit is contained in:
parent
5c4cc48e86
commit
e339b0352a
|
@ -6,12 +6,14 @@ import mineplex.core.lifetimes.ListenerComponent;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class GameComponent extends ListenerComponent implements Lifetimed
|
public class GameComponent<T extends Game> extends ListenerComponent implements Lifetimed
|
||||||
{
|
{
|
||||||
private final Lifetime _lifetime;
|
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)
|
if (active == null || active.length == 0)
|
||||||
{
|
{
|
||||||
// Active for the entire duration of the game.
|
// Active for the entire duration of the game.
|
||||||
|
@ -28,4 +30,8 @@ public class GameComponent extends ListenerComponent implements Lifetimed
|
||||||
{
|
{
|
||||||
return _lifetime;
|
return _lifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T getGame() {
|
||||||
|
return _game;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,8 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class WizardSpellMenu extends GameComponent
|
public class WizardSpellMenu extends GameComponent<Wizards>
|
||||||
{
|
{
|
||||||
private Wizards _wizards;
|
|
||||||
private WizardSpellMenuShop _wizardShop;
|
private WizardSpellMenuShop _wizardShop;
|
||||||
private ItemStack _wizardSpells = new ItemBuilder(Material.ENCHANTED_BOOK).setTitle(C.cGold + "Wizard Spells")
|
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();
|
.addLore(C.cGray + "Right click with this to view the spells").build();
|
||||||
|
@ -34,13 +33,12 @@ public class WizardSpellMenu extends GameComponent
|
||||||
super(wizards);
|
super(wizards);
|
||||||
_wizardShop = new WizardSpellMenuShop(this, wizards.getArcadeManager().GetClients(), wizards.getArcadeManager()
|
_wizardShop = new WizardSpellMenuShop(this, wizards.getArcadeManager().GetClients(), wizards.getArcadeManager()
|
||||||
.GetDonation(), wizards);
|
.GetDonation(), wizards);
|
||||||
_wizards = wizards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event)
|
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);
|
event.getPlayer().getInventory().setItem(0, _wizardSpells);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +51,7 @@ public class WizardSpellMenu extends GameComponent
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
if (_wizards.IsLive())
|
if (getGame().IsLive())
|
||||||
{
|
{
|
||||||
event.getEntity().getInventory().setItem(0, _wizardSpells);
|
event.getEntity().getInventory().setItem(0, _wizardSpells);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +64,7 @@ public class WizardSpellMenu extends GameComponent
|
||||||
{
|
{
|
||||||
if (event.getMessage().equalsIgnoreCase("/spec"))
|
if (event.getMessage().equalsIgnoreCase("/spec"))
|
||||||
{
|
{
|
||||||
if (!_wizards.IsAlive(event.getPlayer())
|
if (!getGame().IsAlive(event.getPlayer())
|
||||||
&& !UtilInv.contains(event.getPlayer(), _wizardSpells.getType(), (byte) 0, 1))
|
&& !UtilInv.contains(event.getPlayer(), _wizardSpells.getType(), (byte) 0, 1))
|
||||||
{
|
{
|
||||||
event.getPlayer().getInventory().setItem(0, _wizardSpells);
|
event.getPlayer().getInventory().setItem(0, _wizardSpells);
|
||||||
|
@ -88,7 +86,7 @@ public class WizardSpellMenu extends GameComponent
|
||||||
{
|
{
|
||||||
for(Player player : UtilServer.GetPlayers())
|
for(Player player : UtilServer.GetPlayers())
|
||||||
{
|
{
|
||||||
if (!_wizards.IsAlive(player))
|
if (!getGame().IsAlive(player))
|
||||||
{
|
{
|
||||||
player.getInventory().setItem(0, _wizardSpells);
|
player.getInventory().setItem(0, _wizardSpells);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +98,7 @@ public class WizardSpellMenu extends GameComponent
|
||||||
public void onInteract(PlayerInteractEvent event)
|
public void onInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
if (event.getAction() != Action.PHYSICAL && event.getAction().name().contains("RIGHT")
|
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();
|
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();
|
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"))
|
if (event.getAction().name().contains("RIGHT"))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue