private async Task OnPlayerLeave(PlayerLeaveEventArgs e) { var player = e.Player as Player; await player.SaveAsync(); player.World.TryRemovePlayer(player); var destroy = new DestroyEntities(player.EntityId); foreach (Player other in Players) { if (other == player) { continue; } await other.client.RemovePlayerFromListAsync(player); if (other.visiblePlayers.Contains(player.EntityId)) { await other.client.QueuePacketAsync(destroy); } } BroadcastMessage(string.Format(Config.LeaveMessage, e.Player.Username)); }
public async Task <bool> DestroyEntityAsync(Entity entity) { var destroyed = new DestroyEntities { Count = 1 }; destroyed.AddEntity(entity); await this.Server.BroadcastPacketAsync(destroyed); var(chunkX, chunkZ) = entity.Location.ToChunkCoord(); var region = this.GetRegion(chunkX, chunkZ); if (region is null) { throw new InvalidOperationException("Region is null this wasn't supposed to happen."); } return(region.Entities.TryRemove(entity.EntityId, out _)); }
public void OnDestroyEntities(DestroyEntities packet) { }
private void InvokeDestroyEntities(DestroyEntities packet) { packetListener.OnDestroyEntities(packet); }