2013-08-27 17:14:08 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.UtilMath;
|
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.common.util.UtilTime;
|
|
|
|
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;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.HandlerList;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
|
|
|
public class GameCreationManager implements Listener
|
|
|
|
{
|
|
|
|
ArcadeManager Manager;
|
|
|
|
|
|
|
|
private ArrayList<Game> _ended = new ArrayList<Game>();
|
|
|
|
|
|
|
|
private GameType _nextGame = null;
|
|
|
|
|
|
|
|
private String _lastMap = "";
|
2013-09-11 04:22:55 +02:00
|
|
|
private ArrayList<GameType> _lastGames = new ArrayList<GameType>();
|
2014-05-02 06:35:41 +02:00
|
|
|
|
|
|
|
public String MapPref = null;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
public GameCreationManager(ArcadeManager manager)
|
|
|
|
{
|
|
|
|
Manager = manager;
|
|
|
|
|
|
|
|
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
public String GetLastMap()
|
|
|
|
{
|
|
|
|
return _lastMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetLastMap(String file)
|
|
|
|
{
|
|
|
|
_lastMap = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void NextGame(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.FAST)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Manager.GetGameList().isEmpty())
|
|
|
|
return;
|
|
|
|
|
2013-09-11 04:22:55 +02:00
|
|
|
while (_lastGames.size() > Manager.GetGameList().size() - 1)
|
|
|
|
_lastGames.remove(_lastGames.size()-1);
|
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (Manager.GetGame() == null && _ended.isEmpty())
|
|
|
|
{
|
|
|
|
CreateGame(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Archive Game
|
|
|
|
if (Manager.GetGame() != null)
|
|
|
|
{
|
|
|
|
if (Manager.GetGame().GetState() == GameState.Dead)
|
|
|
|
{
|
|
|
|
HandlerList.unregisterAll(Manager.GetGame());
|
|
|
|
|
|
|
|
//Schedule Cleanup
|
|
|
|
_ended.add(Manager.GetGame());
|
|
|
|
|
|
|
|
//Lobby Display
|
|
|
|
Manager.GetLobby().DisplayLast(Manager.GetGame());
|
|
|
|
|
|
|
|
Manager.SetGame(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Clean Archived Games
|
|
|
|
Iterator<Game> gameIterator = _ended.iterator();
|
|
|
|
|
|
|
|
while (gameIterator.hasNext())
|
|
|
|
{
|
|
|
|
Game game = gameIterator.next();
|
|
|
|
|
|
|
|
HandlerList.unregisterAll(game);
|
2014-05-01 01:31:47 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
//Cleaned
|
|
|
|
if (game.WorldData == null)
|
|
|
|
{
|
|
|
|
gameIterator.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (game.WorldData.World == null)
|
|
|
|
{
|
|
|
|
gameIterator.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Kick Players
|
|
|
|
if (UtilTime.elapsed(game.GetStateTime(), 10000))
|
|
|
|
{
|
|
|
|
for (Player player : game.WorldData.World.getPlayers())
|
|
|
|
player.kickPlayer("Dead World");
|
|
|
|
}
|
|
|
|
|
|
|
|
//Clean
|
|
|
|
if (game.WorldData.World.getPlayers().isEmpty())
|
|
|
|
{
|
|
|
|
game.WorldData.Uninitialize();
|
|
|
|
game.WorldData = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CreateGame(GameType gameType)
|
|
|
|
{
|
2013-09-13 04:24:33 +02:00
|
|
|
//Reset Changes
|
2013-09-09 10:06:44 +02:00
|
|
|
Manager.GetDamage().DisableDamageChanges = false;
|
|
|
|
Manager.GetCreature().SetDisableCustomDrops(false);
|
2013-09-13 04:24:33 +02:00
|
|
|
Manager.GetDamage().SetEnabled(true);
|
2013-11-07 09:49:21 +01:00
|
|
|
Manager.GetExplosion().SetRegenerate(false);
|
2013-11-15 08:52:46 +01:00
|
|
|
Manager.GetExplosion().SetTNTSpread(true);
|
2013-11-22 08:40:38 +01:00
|
|
|
Manager.GetAntiStack().SetEnabled(true);
|
2013-09-09 10:06:44 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
HashMap<String, ChatColor> pastTeams = null;
|
|
|
|
|
2014-05-02 06:35:41 +02:00
|
|
|
//Chosen Game
|
|
|
|
if (_nextGame != null)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
gameType = _nextGame;
|
|
|
|
_nextGame = null;
|
2014-05-02 06:35:41 +02:00
|
|
|
|
|
|
|
System.out.println("Staff Selected GameType: " + gameType);
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Pick Game
|
|
|
|
if (gameType == null)
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<50 ; i++)
|
|
|
|
{
|
|
|
|
gameType = Manager.GetGameList().get(UtilMath.r(Manager.GetGameList().size()));
|
|
|
|
|
2013-09-11 04:22:55 +02:00
|
|
|
if (!_lastGames.contains(gameType))
|
2013-08-27 17:14:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 04:22:55 +02:00
|
|
|
_lastGames.add(0, gameType);
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
//Make Game
|
|
|
|
Manager.SetGame(Manager.GetGameFactory().CreateGame(gameType, pastTeams));
|
|
|
|
|
|
|
|
if (Manager.GetGame() == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Manager.GetLobby().DisplayNext(Manager.GetGame(), pastTeams);
|
|
|
|
|
|
|
|
UtilServer.getServer().getPluginManager().registerEvents(Manager.GetGame(), Manager.GetPlugin());
|
|
|
|
}
|
2014-05-02 06:35:41 +02:00
|
|
|
|
|
|
|
public void SetNextGameType(GameType type)
|
|
|
|
{
|
|
|
|
_nextGame = type;
|
|
|
|
}
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|