Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/MiscManager.java

165 lines
4.2 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.managers;
2014-04-20 07:54:52 +02:00
import java.util.ArrayList;
import java.util.List;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.Game.GameState;
2013-08-27 17:14:08 +02:00
2014-05-10 01:55:27 +02:00
import org.bukkit.GameMode;
2013-08-27 17:14:08 +02:00
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
2013-08-27 17:14:08 +02:00
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
2014-04-20 07:54:52 +02:00
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
2013-08-27 17:14:08 +02:00
import org.bukkit.event.player.PlayerInteractEvent;
public class MiscManager implements Listener
{
2014-04-20 07:54:52 +02:00
private List<String> _dontGiveClockList = new ArrayList<String>();
private ArcadeManager Manager;
2013-08-27 17:14:08 +02:00
public MiscManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@EventHandler(priority = EventPriority.LOWEST)
public void InteractActive(PlayerInteractEvent event)
{
event.setCancelled(false);
}
@EventHandler(priority = EventPriority.LOW)
public void InteractClickCancel(PlayerInteractEvent event)
{
if (Manager.GetGame() == null)
return;
Player player = event.getPlayer();
if (!Manager.GetGame().IsAlive(player))
{
event.setCancelled(true);
}
//BoneMeal
2013-08-27 17:14:08 +02:00
else if (event.getPlayer().getItemInHand().getType() == Material.INK_SACK && event.getPlayer().getItemInHand().getData().getData() == (byte)15)
{
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && Manager.GetGame().GetType() != GameType.UHC)
2013-08-27 17:14:08 +02:00
event.setCancelled(true);
}
else if (Manager.GetGame().GetState() != GameState.Live)
{
event.setCancelled(true);
}
2013-08-27 17:14:08 +02:00
}
@EventHandler(priority = EventPriority.LOWEST)
public void InventoryClickCancel(InventoryClickEvent event)
{
if (Manager.GetGame() == null)
return;
Player player = UtilPlayer.searchExact(event.getWhoClicked().getName());
2014-05-10 01:55:27 +02:00
if (player == null)
return;
if (player.getGameMode() != GameMode.SURVIVAL && !player.isOp())
{
event.setCancelled(true);
player.closeInventory();
}
2013-08-27 17:14:08 +02:00
2014-05-10 01:55:27 +02:00
else if (Manager.GetGame().IsLive() && !Manager.GetGame().IsAlive(player) && !((CraftPlayer)player).getHandle().spectating)
2013-08-27 17:14:08 +02:00
{
event.setCancelled(true);
player.closeInventory();
}
}
2014-04-20 07:54:52 +02:00
@EventHandler
public void addClockPrevent(InventoryOpenEvent event)
{
if (event.getPlayer() instanceof Player)
{
_dontGiveClockList.add(event.getPlayer().getName());
}
}
@EventHandler
public void removeClockPrevent(InventoryCloseEvent event)
{
if (event.getPlayer() instanceof Player)
{
_dontGiveClockList.remove(event.getPlayer().getName());
}
}
2013-08-27 17:14:08 +02:00
@EventHandler
public void HubClockUpdate(UpdateEvent event)
2013-08-27 17:14:08 +02:00
{
2014-05-03 09:26:21 +02:00
if (Manager.IsTournamentServer())
return;
2013-08-27 17:14:08 +02:00
if (event.getType() != UpdateType.SLOW)
return;
if (Manager.GetGame() == null)
return;
if (Manager.GetGame().GetType() == GameType.UHC)
return;
2013-08-27 17:14:08 +02:00
for (Player player : UtilServer.getPlayers())
{
if (!Manager.GetGame().IsAlive(player))
2013-08-27 17:14:08 +02:00
{
2014-04-20 07:54:52 +02:00
if (!_dontGiveClockList.contains(player.getName()) && !player.getInventory().contains(Material.WATCH))
2013-08-27 17:14:08 +02:00
{
Manager.HubClock(player);
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void HubClockInteract(PlayerInteractEvent event)
{
2014-05-03 09:26:21 +02:00
if (Manager.IsTournamentServer())
return;
Player player = event.getPlayer();
if (player.getItemInHand() == null)
return;
if (player.getItemInHand().getType() != Material.WATCH)
return;
Manager.GetPortal().SendPlayerToServer(player, "Lobby");
}
@EventHandler
public void HubCommand(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/hub") || event.getMessage().startsWith("/leave"))
{
Manager.GetPortal().SendPlayerToServer(event.getPlayer(), "Lobby");
event.setCancelled(true);
}
}
2013-08-27 17:14:08 +02:00
}