public async Task Handle(ServerCrashedEvent notification, CancellationToken cancellationToken) { _state.Running = false; _state.CurrentPlayers.Clear(); _state.StartTime = null; await _mediator.Publish(new MinecraftStateNotification { CurrentState = _state }); }
public async Task Handle(ServerCrashedEvent notification, CancellationToken cancellationToken) { foreach (var plugin in _pluginLoader.Enabled) { try { await plugin.OnCrash(notification); } catch (Exception ex) { await _mediator.Publish(new PluginLogNotification { Exception = ex, Message = $"Error in {nameof(plugin.OnCrash)} for plugin {plugin.Name}" }); } } }
public override async Task OnCrash(ServerCrashedEvent crashedEvent) { if (CrashRecoveryQueue.Count != 0) { await _minecraftDiscordClient.SendMessageAsync("Was unable to successfully start the minecraft server"); CrashRecoveryQueue.Clear(); return; } await _minecraftDiscordClient.SendMessageAsync("The minecraft server crashed with an unhandled exception - attempting to restart the server"); CrashRecoveryQueue.Enqueue(crashedEvent.Timestamp); var timeout = TimeSpan.FromSeconds(10).TotalMilliseconds; var elapsed = 0; while (PluginContext.MinecraftServer.Running || elapsed > timeout) { await Task.Delay(250); elapsed += 250; } await PluginContext.MinecraftServer.StartAsync(); }
public virtual Task OnCrash(ServerCrashedEvent crashedEvent) { return(Task.CompletedTask); }