//New GameLevel Method public void AddPlayer(SkyPlayer player) { if (player.Level != this && player.Level is GameLevel level) { level.RemovePlayer(player, true); //Clear from old world } //Remove a player from _incomingPlayers only if it's non-empty. //Avoid claiming a lock for a useless check if (_incomingPlayers.Count > 0) { lock (_incomingPlayers) { if (_incomingPlayers.ContainsKey(player.Username)) { _incomingPlayers.Remove(player.Username); } } } GameTeam defaultTeam = GetDefaultTeam(); SetPlayerTeam(player, defaultTeam); //SkyUtil.log($"Added {player.Username} to team {defaultTeam.DisplayName} in game {GameId}"); /*if (player.Level != this) * { * //Only show the level transition screen to players changing games on this instance * //player.SpawnLevel(this, GameLevelInfo.LobbyLocation, !_incomingPlayers.ContainsKey(player.Username)); * player.SpawnLevel(this, GameLevelInfo.LobbyLocation, false); //Remove loading screen to prevent 'building terrain' issue * } * else //Still teleport the player to the spawn location * { * player.Teleport(GameLevelInfo.LobbyLocation); * }*/ //Fix for maps on first join to an instance player.SpawnLevel(this, GameLevelInfo.LobbyLocation, false); //Remove loading screen to prevent 'building terrain' issue try { CurrentState.InitializePlayer(this, player); } catch (Exception e) { BugSnagUtil.ReportBug(e, this, CurrentState, player); } //Update Time McpeSetTime message = McpeSetTime.CreateObject(); message.time = GameLevelInfo.WorldTime; player.SendPackage(message); // //Pending Tasks //Attempts to execute tasks like spawning NPCs in once a single player has loaded the world if (_shouldSchedule) { _shouldSchedule = false; if (_pendingTasks.Count > 0) { foreach (SkyCoreAPI.PendingTask pendingTask in _pendingTasks) { RunnableTask.RunTaskLater(() => { try { pendingTask.Invoke(); } catch (Exception e) { BugSnagUtil.ReportBug(e, new AnonMetadatable((metadata) => { metadata.AddToTab("PendingTask", "Target", pendingTask.Target); metadata.AddToTab("PendingTask", "Method", pendingTask.Method); })); } }, 250); //Small delay for the level to initialize } _pendingTasks.Clear(); } } }