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

88 lines
2.0 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 net.minecraft.server.v1_7_R3.ChunkPreLoadEvent;
2013-08-27 17:14:08 +02:00
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();
}
}
}
/*
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);
}
}