Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java
Jonathan Williams 3fb52c5c71 Initial Commit
2013-08-27 08:14:08 -07:00

87 lines
2.0 KiB
Java

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;
private HashSet<WorldData> _worldLoader = new HashSet<WorldData>();
public GameWorldManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@EventHandler
public void LoadWorldChunks(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
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();
}
}
}
/* XXX This stops outside chunks from loading
@EventHandler
public void ChunkLoad(ChunkPreLoadEvent event)
{
if (Manager.GetGame() != null)
if (Manager.GetGame().WorldData != null)
Manager.GetGame().WorldData.ChunkLoad(event);
}
*/
@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);
}
}