public override void Load(bool auto)
{
OnPlayerFinishConnectingEvent.Register(HandleOnPlayerFinishConnecting, Priority.High);
}
public override void Unload(bool auto)
{
OnPlayerFinishConnectingEvent.Unregister(HandleOnPlayerFinishConnecting);
}
private void HandleOnPlayerFinishConnecting(Player p)
{
if (!LevelInfo.AllMapNames().Contains(map))
{
p.Message("&WThe map you were on no longer exists!");
return;
}
Level lvl = LevelInfo.FindExact(map);
if (lvl == null)
{
if (!Server.Config.AutoLoadMaps)
return;
string propsPath = LevelInfo.PropsPath(map);
LevelConfig cfg = new LevelConfig();
cfg.Load(propsPath);
AccessController visitAccess = new LevelAccessController(cfg, map, true);
if (!visitAccess.CheckDetailed(p, p.Rank)) return;
lvl = LevelActions.Load(p, map, false);
if (lvl == null)
{
p.Message("&WFailed to load the map you were on!");
return;
}
}
bool canJoin = lvl.CanJoin(p);
//We are joining a level right? As it's not the main level.
OnJoiningLevelEvent.Call(p, lvl, ref canJoin);
if (!canJoin) return;
p.level = lvl;
}
Most of it is fluff for checking if player even has permissions to be in the map they were on or if the level exists and to load it if not loaded. Also this snippet doesn't work as-is because I have yet to complete the plugin, which is for making player join at previous location.