game host stuff

This commit is contained in:
Chiss 2014-11-07 12:14:33 +11:00
parent 4c675cca9c
commit b7ce12165e
2 changed files with 141 additions and 0 deletions

View File

@ -397,6 +397,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _gameCreationManager;
}
public GameHostManager GetGameHostManager()
{
return _gameHostManager;
}
public GameFactory GetGameFactory()
{
return _gameFactory;

View File

@ -2,17 +2,26 @@ package nautilus.game.arcade.managers;
import java.util.HashSet;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemStackFactory;
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;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -92,9 +101,62 @@ public class GameHostManager implements Listener
private void giveHostItem()
{
if (Manager.GetGame() == null)
return;
if (_host == null)
return;
if (UtilGear.isMat(_host.getInventory().getItem(5), Material.BOOK_AND_QUILL))
return;
_host.getInventory().setItem(5, ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte)0, 1, C.cGreen + C.Bold + "/menu"));
}
public HashSet<String> getWhitelist()
{
return _whitelist;
}
public HashSet<String> getBlacklist()
{
return _blacklist;
}
@EventHandler
public void menuCommand(PlayerCommandPreprocessEvent event)
{
if (_host == null || !event.getPlayer().equals(_host))
return;
if (!event.getMessage().toLowerCase().startsWith("/menu"))
return;
openMenu();
}
@EventHandler
public void menuInteract(PlayerInteractEvent event)
{
if (_host == null || !event.getPlayer().equals(_host))
return;
if (!UtilGear.isMat(_host.getItemInHand(), Material.BOOK_AND_QUILL))
return;
openMenu();
}
private void openMenu()
{
if (_host == null)
return;
//XXX OPEN GUI HERE
}
@EventHandler
public void whitelistCommand(PlayerCommandPreprocessEvent event)
{
@ -116,4 +178,78 @@ public class GameHostManager implements Listener
}
}
}
@EventHandler
public void setHostDebug(PlayerCommandPreprocessEvent event)
{
if (!event.getPlayer().isOp())
return;
if (!event.getMessage().toLowerCase().startsWith("/sethost "))
return;
Manager.GetServerConfig().HostName = event.getMessage().split(" ")[1];
event.getPlayer().sendMessage("Set host to: " + event.getMessage().split(" ")[1]);
}
public void setGame(GameType type)
{
if (_host == null)
return;
Manager.GetGameCreationManager().SetNextGameType(type);
//End Current
if (Manager.GetGame().GetState() == GameState.Recruit)
{
Manager.GetGame().SetState(GameState.Dead);
Bukkit.broadcastMessage(C.cGreen + C.Bold + _host.getName() + " has changed game to " + type.GetName() + ".");
}
else
{
Bukkit.broadcastMessage(C.cGreen + C.Bold + _host.getName() + " set next game to " + type.GetName() + ".");
}
}
public void startGame()
{
if (_host == null)
return;
Manager.GetGameManager().StateCountdown(Manager.GetGame(), 10, true);
Manager.GetGame().Announce(C.cGreen + C.Bold + _host.getName() + " has started the game.");
}
public void stopGame()
{
if (_host == null)
return;
if (Manager.GetGame() == null)
return;
HandlerList.unregisterAll(Manager.GetGame());
if (Manager.GetGame().GetState() == GameState.End || Manager.GetGame().GetState() == GameState.End)
{
_host.sendMessage("Game is already ending...");
return;
}
else if (Manager.GetGame().GetState() == GameState.Recruit)
{
Manager.GetGame().SetState(GameState.Dead);
}
else
{
Manager.GetGame().SetState(GameState.End);
}
Manager.GetGame().Announce(C.cGreen + C.Bold + _host.getName() + " has stopped the game.");
}
}