Fix players using gadgets inside the hub games
This commit is contained in:
parent
5985d5ef99
commit
49f61e09cf
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user