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

87 lines
1.9 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.managers;
import java.util.HashSet;
import java.util.Iterator;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.world.WorldData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent;
public class GameWorldManager implements Listener
{
ArcadeManager Manager;
2014-08-08 09:05:11 +02:00
2013-08-27 17:14:08 +02:00
private HashSet<WorldData> _worldLoader = new HashSet<WorldData>();
public GameWorldManager(ArcadeManager manager)
{
Manager = manager;
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
2013-08-27 17:14:08 +02:00
}
@EventHandler
public void LoadWorldChunks(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
2014-08-08 09:05:11 +02:00
2013-08-27 17:14:08 +02:00
Iterator<WorldData> worldIterator = _worldLoader.iterator();
long endTime = System.currentTimeMillis() + 25;
while (worldIterator.hasNext())
{
long timeLeft = endTime - System.currentTimeMillis();
if (timeLeft <= 0) continue;
final WorldData worldData = worldIterator.next();
if (worldData.World == null)
{
worldIterator.remove();
}
else if (worldData.LoadChunks(timeLeft))
{
worldData.Host.SetState(GameState.Recruit);
worldIterator.remove();
}
}
}
/*
2013-08-27 17:14:08 +02:00
@EventHandler
public void ChunkLoad(ChunkPreLoadEvent event)
{
if (Manager.GetGame() != null)
if (Manager.GetGame().WorldData != null)
Manager.GetGame().WorldData.ChunkLoad(event);
}
*/
2013-08-27 17:14:08 +02:00
@EventHandler
public void ChunkUnload(ChunkUnloadEvent event)
{
if (event.getWorld().getName().equals("world"))
{
event.setCancelled(true);
return;
}
if (Manager.GetGame() != null)
if (Manager.GetGame().WorldData != null)
Manager.GetGame().WorldData.ChunkUnload(event);
}
public void RegisterWorld(WorldData worldData)
{
_worldLoader.add(worldData);
}
}