async void doStop(CommandArgs e) { if (e.Parameters.Count == 0) { e.Player.SendErrorMessage($"Invalid syntax! Proper syntax: {Commands.Specifier}timeline stop <name>"); return; } string name = e.Parameters[0]; if (!Running.Exists(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase))) { e.Player.SendErrorMessage($"'{name}' isn't running."); } else { if (!e.Player.CanUseTimeline(Path.Combine(TShock.SavePath, name.EndsWith(".txt") ? name : $"{name}.txt"))) { e.Player.SendErrorMessage("You don't have access to this timeline."); return; } Timeline timeline = Running.Find(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); e.Player.SendInfoMessage($"Stopping {timeline.Name}..."); await timeline.Stop(); e.Player.SendSuccessMessage($"{timeline.Name} stopped."); } }
async void doStart(CommandArgs e) { if (e.Parameters.Count == 0) { e.Player.SendErrorMessage($"Invalid syntax! Proper syntax: {Commands.Specifier}timeline start <file> [params...]"); return; } string filePath = e.Parameters[0]; if (!e.Player.CanUseTimeline(filePath)) { e.Player.SendErrorMessage("You don't have access to this timeline."); return; } string path = Path.Combine(TShock.SavePath, filePath.EndsWith(".txt") ? filePath : $"{filePath}.txt"); if (!File.Exists(path)) { e.Player.SendErrorMessage($"'{filePath}' doesn't exist."); return; } string name = Path.GetFileNameWithoutExtension(filePath); if (Running.Exists(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase))) { e.Player.SendErrorMessage($"'{name}' is already running."); return; } string data; try { data = File.ReadAllText(path); } catch (Exception ex) { e.Player.SendErrorMessage($"Timeline loading failed: {ex.Message}"); return; } // Remove the file name e.Parameters.RemoveAt(0); Timeline timeline = new Timeline(name, data, e.Parameters); try { // Process the timeline and handle all exceptions e.Player.SendInfoMessage("Processing timeline..."); await timeline.Start(); timeline.Finished += (o, a) => Running.Remove(timeline); Running.Add(timeline); e.Player.SendSuccessMessage($"{name} started."); } catch (EmptyTimelineException) { e.Player.SendErrorMessage($"'{name}' must contain at least one command."); } catch (MissingParameterException ex) { e.Player.SendInfoMessage($"'{name}' syntax: {Commands.Specifier}timeline start {name} {ex.Message}"); } catch (CannotRunException ex) { e.Player.SendErrorMessage( $"Error processing timeline '{name}' at line {ex.Line}: Cannot run {Commands.Specifier}{ex.Command} as the server."); } catch (TimelineException ex) { e.Player.SendErrorMessage($"Error processing timeline '{name}' at line {ex.Line}: {ex.Message}"); } }