diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetEnableEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetEnableEvent.java index cc1050a84..61c970a1e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetEnableEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetEnableEvent.java @@ -1,24 +1,26 @@ package mineplex.core.gadget.event; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + import mineplex.core.gadget.types.Gadget; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class GadgetEnableEvent extends Event +public class GadgetEnableEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); - private Player _player; - private Gadget _gadget; + private final Gadget _gadget; private boolean _showMessage = true; private boolean _cancelled = false; public GadgetEnableEvent(Player player, Gadget gadget) { - _player = player; + super(player); + _gadget = gadget; } @@ -37,16 +39,13 @@ public class GadgetEnableEvent extends Event return _gadget; } - public Player getPlayer() - { - return _player; - } - + @Override public void setCancelled(boolean cancel) { _cancelled = cancel; } - + + @Override public boolean isCancelled() { return _cancelled; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java index 7f709020b..a34d9de3d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java @@ -7,8 +7,10 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; @@ -21,6 +23,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.event.GadgetEnableEvent; import mineplex.core.gadget.types.GadgetType; import mineplex.core.newnpc.NPC; import mineplex.core.newnpc.NewNPCManager; @@ -372,6 +375,42 @@ public class HubGameManager extends MiniPlugin } } + @EventHandler + public void gadgetEnable(GadgetEnableEvent event) + { + cancelIfPlaying(event.getPlayer(), event); + } + + @EventHandler + public void inventoryOpen(InventoryOpenEvent event) + { + if (event.getInventory().equals(event.getPlayer().getInventory())) + { + return; + } + + cancelIfPlaying((Player) event.getPlayer(), event); + } + + private void cancelIfPlaying(Player player, Cancellable event) + { + for (HubGame game : _games) + { + if (!(game instanceof CycledGame)) + { + continue; + } + + CycledGame cycledGame = (CycledGame) game; + + if (cycledGame.getQueuedPlayers().contains(player) || cycledGame.isAlive(player)) + { + event.setCancelled(true); + return; + } + } + } + private boolean isEnoughPlayers(CycledGame game) { boolean enough = game.getQueuedPlayers().size() >= game.getGameType().getMinPlayers();