Exemple #1
0
 private void toolsBatch_Click(object sender, RoutedEventArgs e)
 {
     if (toolsBatch.IsEnabled)
     {
         //Opens a folder dialog and then imports all files in the selected folder
         if (ChooseFolderDialog.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
         {
             int    commandCount = 0;
             string directory    = ChooseFolderDialog.SelectedPath;
             foreach (string file in Directory.GetFiles(directory))
             {
                 if (file.EndsWith(".mccbl"))
                 {
                     string         fileName    = System.IO.Path.GetFileName(file);
                     CBLInterpreter interpreter = new CBLInterpreter(this, fileName, false, "@e[type=ArmorStand,name=" + System.IO.Path.GetFileName(file).Replace(' ', '_').Trim() + "]");
                     ConsoleWindow.AppendText("Importing " + fileName);
                     SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.gold, TellrawColor.aqua }, new string[] { "Importing ", fileName }));
                     CBLFile importer = interpreter.Interpret(file);
                     if (importer != null && importer.Import(this))
                     {
                         commandCount += importer.Commands.Count;
                     }
                     else
                     {
                         SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "[ERROR] Import was cancelled or failed for file " + file));
                     }
                 }
             }
             SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.green, TellrawColor.yellow, TellrawColor.green }, new string[] { "Imported ", commandCount.ToString(), " commands" }));
             ConsoleWindow.AppendText("Successfully imported " + commandCount + " commands");
             SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Don't forget to enable the first command block of each section"));
         }
         else
         {
             SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "[ERROR] Import was cancelled or failed"));
         }
     }
 }
Exemple #2
0
        public CBLFile Interpret(string filePath)
        {
            int totalCommands = 0;

            string[] fileLines = new string[] { };
            if (!webLink)
            {
                fileLines = System.IO.File.ReadAllLines(filePath);
            }
            else
            {
                if (filePath.StartsWith("http"))
                {
                    new System.Net.WebClient().DownloadFile(filePath, ServerManager.MinecraftServer.StartInfo.WorkingDirectory + "/Remote Import.mccbl");
                    fileLines = System.IO.File.ReadAllLines(ServerManager.MinecraftServer.StartInfo.WorkingDirectory + "/Remote Import.mccbl");
                }
                else
                {
                    try
                    {
                        fileLines = System.IO.File.ReadAllLines(filePath);
                    }
                    catch
                    {
                        return(null);
                    }
                }
            }

            MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
            sc.Language = "VBScript";

            Dictionary <string, string> constants = new Dictionary <string, string>();
            Dictionary <string, string> atTags    = new Dictionary <string, string>();

            foreach (string line in fileLines)
            {
                if (line.Trim().StartsWith("@") && line.Trim()[1] != '!')
                {
                    string key = line.Trim().Split(' ')[0].Substring(1);
                    string val = string.Join(" ", line.Trim().Split(' ').Skip(1));

                    atTags.Add(key, val);
                }
                else if (line.Trim().StartsWith("#define"))
                {
                    string key = line.Trim().Split(' ')[1];
                    string val = string.Join(" ", line.Trim().Split(' ').Skip(2));

                    if (constants.ContainsKey(key))
                    {
                        constants.Remove(key);
                        constants.Add(key, val);
                    }
                    else
                    {
                        constants.Add(key, val);
                    }
                }
                else if (!line.Trim().StartsWith("//") && !line.Trim().StartsWith("@") && !line.Trim().StartsWith("::") && !line.Trim().StartsWith(";;") && line.Trim() != "")
                {
                    totalCommands++;

                    string input = line.TrimStart();
                    string output;
                    if (input.Contains("([") && input.Contains("])"))
                    {
                        string expression = input.Split(new string[] { "([", "])" }, StringSplitOptions.None)[1];
                        output = input;
                        Regex           r = new Regex(@"\(\[.+?\]\)");
                        MatchCollection m = r.Matches(input);
                        try
                        {
                            for (int i = 0; i < m.Count; i++)
                            {
                                object result = sc.Eval(m[i].Value.Replace("([", "").Replace("])", ""));
                                output = r.Replace(output, result.ToString(), 1);
                            }
                        }
                        catch (Exception ex)
                        {
                            output = input;
                            ServerManager.MinecraftServer.StandardInput.WriteLine(ChatTools.Tellraw("@a", TellrawColor.red, $"[ERROR] Failed to interpret math statement ({expression}): {ex.ToString()}"));
                            ServerManager.MinecraftServer.StandardInput.FlushAsync();
                        }
                    }
                    else
                    {
                        output = input;
                    }

                    foreach (string constant in constants.Keys)
                    {
                        if (output.Contains("#" + constant + "#"))
                        {
                            output.Replace("#" + constant + "#", constants[constant]);
                        }
                    }

                    if (line.Trim().StartsWith("??"))
                    {
                        commands.Add(new Command(output.Trim().Substring(2).Replace("@!", ""), Command.Type.RepeatingConditional, commands.Count));
                    }
                    else if (line.Trim().StartsWith("?"))
                    {
                        commands.Add(new Command(output.Trim().Substring(1).Replace("@!", ""), Command.Type.Conditional, commands.Count));
                    }
                    else
                    {
                        commands.Add(new Command(output.Replace("@!", ""), Command.Type.Normal, commands.Count));
                    }
                }
            }


            return(new CBLFile(commands, atTags, FileName, fileLines, Selector, webLink));
        }
Exemple #3
0
 /// <summary>
 /// Imports a MCCBL file
 /// </summary>
 /// <param name="reimport">Whether or not to reimport the last import</param>
 /// <param name="selector">Selector at which to import</param>
 private void ImportFile(bool reimport = false, string selector = null)
 {
     if (!reimport)
     {
         //Opens a file dialog and then imports the selected file
         ChooseFileDialog.Filter = "CommandBlock Language Files (*.mccbl)|*.mccbl";
         if (ChooseFileDialog.ShowDialog() == true)
         {
             CBLInterpreter interpreter = new CBLInterpreter(this, ChooseFileDialog.SafeFileName);
             ConsoleWindow.AppendText("Importing " + ChooseFileDialog.SafeFileName);
             SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.gold, TellrawColor.aqua }, new string[] { "Importing ", ChooseFileDialog.SafeFileName }));
             //SendCommand("say §6Importing §b§l" + ChooseFileDialog.SafeFileName);
             CBLFile importer = interpreter.Interpret(ChooseFileDialog.FileName);
             if (importer != null && importer.Import(this))
             {
                 SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.green, TellrawColor.yellow, TellrawColor.green }, new string[] { "Imported ", importer.Commands.Count.ToString(), " commands" }));
                 ConsoleWindow.AppendText("Imported " + importer.Commands.Count + " commands");
                 SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Don't forget to enable the first command block"));
                 //SendCommand("say §aSuccessfully §aimported §e§l" + importer.Commands.Count + " §acommands");
                 //SendCommand("say §c§l§nDon't §c§l§nforget §cto §cenable §cthe §cfirst §cCommand §cBlock §cif §cnecessary");
             }
             else
             {
                 SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Import was cancelled or failed"));
             }
         }
         else
         {
             SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Import was cancelled or failed"));
         }
     }
     else
     {
         //Reimports the previously imported commands
         if (ChooseFileDialog.SafeFileName.EndsWith(".mccbl"))
         {
             CBLInterpreter interpreter = new CBLInterpreter(this, ChooseFileDialog.SafeFileName, false, selector ?? Settings.Default.LastSelector);
             ConsoleWindow.AppendText("Reimporting " + ChooseFileDialog.SafeFileName);
             SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.gold, TellrawColor.aqua }, new string[] { "Reimporting ", ChooseFileDialog.SafeFileName }));
             //SendCommand("say §6Reimporting §b§l" + ChooseFileDialog.SafeFileName);
             CBLFile importer = interpreter.Interpret(ChooseFileDialog.FileName);
             if (importer != null && importer.Import(this))
             {
                 ConsoleWindow.AppendText("Imported " + importer.Commands.Count + " commands");
                 SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.green, TellrawColor.yellow, TellrawColor.green }, new string[] { "Imported ", importer.Commands.Count.ToString(), " commands" }));
                 SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Don't forget to enable the first command block"));
                 //SendCommand("say §aSuccessfully §areimported §e§l" + importer.Commands.Count + " §acommands");
                 //SendCommand("say §c§l§nDon't §c§l§nforget §cto §cenable §cthe §cfirst §cCommand §cBlock §cif §cnecessary");
             }
             else
             {
                 SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Reimport was cancelled or failed"));
             }
         }
         else
         {
             SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.red, TellrawColor.aqua, TellrawColor.red }, new string[] { "Reimporting ", ChooseFileDialog.SafeFileName, " failed" }));
             //SendCommand("say §cReimporting §b§l" + ChooseFileDialog.SafeFileName + " §cFailed!");
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Called when error data is recieved from the server
        /// However, most error data is sent through standard output
        /// </summary>
        /// <param name="recievedCommand">The recieved error message</param>
        public void ErrorDataRecieved(string recievedCommand)
        {
            ServerManager.LastRecievedMessage = recievedCommand;

            try
            {
                Dispatcher.Invoke(delegate
                {
                    if (ServerManager.LastRecievedMessage != null && ServerManager.LastRecievedMessage.Trim() != "")
                    {
                        string timestring = DateTime.Now.ToString("M/d HH:mm:ss");
                        ConsoleWindow.AppendColoredText(string.Format("\r[{0}]: {1}", timestring, ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Trim()), new SolidColorBrush(Color.FromRgb(244, 67, 54)));
                        ConsoleWindow.ScrollToEnd();
                    }
                });
            }
            catch
            {
            }
        }
Exemple #5
0
        /// <summary>
        /// Called when most status messages are recieved from the server
        /// </summary>
        /// <param name="recievedMessage">The recieved message</param>
        public void OutputDataRecieved(string recievedMessage)
        {
            ServerManager.LastRecievedMessage = recievedMessage;

            try
            {
                Dispatcher.Invoke(delegate
                {
                    //Checks if message is not blank or null
                    if (ServerManager.LastRecievedMessage != null && ServerManager.LastRecievedMessage.Trim() != "")
                    {
                        //Checks for players logging in so text can be yellow
                        if (ServerManager.LastRecievedMessage.ContainsAny(new string[] { "logged in with entity id", "UUID of player", "left the game", "lost connection:", "joined the game" }))
                        {
                            textColor = new SolidColorBrush(Color.FromRgb(254, 159, 0));
                            if (ServerManager.LastRecievedMessage.Contains("logged in with entity id"))
                            {
                                string timeString = DateTime.Now.ToString("M/d HH:mm:ss");
                                ServerManager.ChatHistory.Add(ChatTools.FilterCommand(string.Format("\r[{0}]: {1}", timeString, ChatTools.FilterCommand(ServerManager.LastRecievedMessage))));

                                string player = ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Split('[')[0].Trim();
                                ServerManager.LoggedInPlayers.Add(player);
                                ListBoxItem item        = new ListBoxItem();
                                item.Content            = player;
                                item.MouseLeftButtonUp += I_MouseLeftButtonUp;
                                item.FontSize           = 12;
                                item.Height             = 30;
                                listBox1.Items.Add(item);
                                if (listBox1.Items.Count > 1)
                                {
                                    label.Content = listBox1.Items.Count + " players";
                                }
                                else if (listBox1.Items.Count == 1)
                                {
                                    label.Content = "1 player";
                                }
                                else
                                {
                                    label.Content = "No players";
                                }


                                if (File.Exists(ServerManager.MinecraftServer.StartInfo.WorkingDirectory + "\\motd.mccbl"))
                                {
                                    SendCommand(ChatTools.Tellraw("@a[score_motd_min=1]", TellrawColor.white, "Recent chat:"));
                                    for (int i = 11; i > 0; i--)
                                    {
                                        try
                                        {
                                            SendCommand(ChatTools.Tellraw("@a[score_motd_min=1]", TellrawColor.white, ServerManager.ChatHistory[ServerManager.ChatHistory.Count - i].Replace(Environment.NewLine, "")));
                                        }
                                        catch (ArgumentOutOfRangeException)
                                        {
                                        }
                                    }
                                    SendCommand(ChatTools.Tellraw("@a[score_motd_min=1]", TellrawColor.white, "--------------------"));
                                    CBLFile motdFile = new CBLInterpreter(this, "MOTD").Interpret(ServerManager.MinecraftServer.StartInfo.WorkingDirectory + "\\motd.mccbl");
                                    motdFile.Execute(player, "");
                                }
                            }
                            else if (ServerManager.LastRecievedMessage.Contains("lost connection"))
                            {
                                string timeString = DateTime.Now.ToString("M/d HH:mm:ss");
                                ServerManager.ChatHistory.Add(ChatTools.FilterCommand(string.Format("\r[{0}]: {1}", timeString, ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Trim())));

                                string player = ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Split(new string[] { "lost connection" }, StringSplitOptions.None)[0].Trim();
                                ServerManager.LoggedInPlayers.Remove(player);
                                foreach (object item in listBox1.Items)
                                {
                                    try
                                    {
                                        if (((ListBoxItem)item).Content.ToString() == player)
                                        {
                                            listBox1.Items.Remove(item);
                                        }
                                    }
                                    catch { }
                                }
                                if (listBox1.Items.Count > 1)
                                {
                                    label.Content = listBox1.Items.Count + " players";
                                }
                                else if (listBox1.Items.Count == 1)
                                {
                                    label.Content = "1 player";
                                }
                                else
                                {
                                    label.Content = "No players";
                                }
                            }
                        }
                        //Checks for events that make green text
                        else if (ServerManager.LastRecievedMessage.ContainsAny(new string[] { "Done (", "Starting minecraft server", "Starting Minecraft server", "has just earned the achievement" }))
                        {
                            textColor = new SolidColorBrush(Color.FromRgb(76, 175, 80));
                        }
                        //Checks for errors sent through the standard output and colors them red
                        else if (ServerManager.LastRecievedMessage.ContainsAny(new string[] { "moved too quickly!", "with pending removal and duplicate UUID", "change, or is the server overloaded?", "is sending move packets too frequently", "exception was", "FAILED TO BIND", "perhaps a server", "stopping server", "Stopping server", "Stopping the server" }))
                        {
                            textColor = new SolidColorBrush(Color.FromRgb(244, 67, 54));;
                        }
                        //Finds FATAL errors sent through standard output and colors them orange
                        else if (ServerManager.LastRecievedMessage.ContainsAny(new string[] { "A single server tick took", "server will forcibly shutdown", "This crash report has" }))
                        {
                            textColor = new SolidColorBrush(Color.FromRgb(254, 151, 0));
                        }
                        //Checks if the message is a chat message
                        if (ChatTools.FilterCommand(ServerManager.LastRecievedMessage).StartsWith("<"))
                        {
                            string timeString = DateTime.Now.ToString("M/d HH:mm:ss");
                            //Adds the message to the chat history
                            ServerManager.ChatHistory.Add(ChatTools.FilterCommand(string.Format("\r[{0}]: {1}", timeString, ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Trim())));
                            textColor = new SolidColorBrush(Color.FromRgb(155, 38, 175));
                            //Finds the actual chat message portion of the incoming message
                            string chatMessage = ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Split('>')[1];
                            //Gets the username of the player who sent the message
                            string user = ChatTools.FilterUsername(ChatTools.FilterCommand(ServerManager.LastRecievedMessage));
                            //Checks for custom commands
                            bool wasUserMade = false;
                            if (chatMessage.TrimStart().StartsWith("@!"))
                            {
                                Dictionary <string, CBLFile> CustomCommands = new Dictionary <string, CBLFile>();

                                string cmdDir = ServerManager.MinecraftServer.StartInfo.WorkingDirectory + "\\commands";
                                if (Directory.Exists(cmdDir))
                                {
                                    foreach (string file in Directory.GetFileSystemEntries(ServerManager.MinecraftServer.StartInfo.WorkingDirectory + "\\commands"))
                                    {
                                        CustomCommands.Add(System.IO.Path.GetFileName(file), new CBLInterpreter(this, System.IO.Path.GetFileName(file)).Interpret(file));
                                    }
                                }

                                //Checks if the message matches a user-made custom command
                                if (CustomCommands.ContainsKey(chatMessage.TrimStart().Split(' ')[0] + ".mccbl"))
                                {
                                    wasUserMade = true;

                                    CustomCommands[chatMessage.TrimStart().Split(' ')[0] + ".mccbl"].Execute(user, chatMessage.TrimStart().Split(' ').Length > 1 ? string.Join(" ", chatMessage.TrimStart().Split(' ').Skip(1)) : "");
                                }

                                //Checks for premade custom commands
                                //TODO: Allow turning these commands on or off
                                //TODO: Specify which players can use these commands

                                //Imports a MCCBL from the given link or file path at the player who used the command
                                //Examples:
                                //@!import http://example.com/mccblfile.mccbl
                                //@!import http://example.com/textfile.txt
                                //@!import C:\Users\TestUser\Documents\localfile.mccbl
                                if (chatMessage.TrimStart().StartsWith("@!import "))
                                {
                                    string link = chatMessage.CommandArgument("@!import");
                                    CBLInterpreter interpreter = new CBLInterpreter(this, link, true, ChatTools.FilterUsername(ChatTools.FilterCommand(ServerManager.LastRecievedMessage)));
                                    ConsoleWindow.AppendColoredText("\rRemote Importing from " + link, new SolidColorBrush(Color.FromRgb(62, 80, 180)));
                                    SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.gold, TellrawColor.aqua, TellrawColor.gold, TellrawColor.aqua }, new string[] { "Remote importing from ", link, " as ", "Remote Import.mccbl" }));
                                    //SendCommand("say §6Remote §6Importing §6from §b§l" + link + " §6as §b§lRemote §b§lImport.mccbl");
                                    CBLFile importer = interpreter.Interpret(link);
                                    if (importer != null && importer.Import(this))
                                    {
                                        ConsoleWindow.AppendColoredText("\rSuccessfully imported " + interpreter.commands.Count + " commands", new SolidColorBrush(Color.FromRgb(62, 80, 180)));
                                        SendCommand(ChatTools.MultiTellraw("@a", new TellrawColor[] { TellrawColor.green, TellrawColor.yellow, TellrawColor.green }, new string[] { "Successfully imported ", interpreter.commands.Count.ToString(), " commands" }));
                                        //SendCommand("say §aSuccessfully §aimported §e§l" + interpreter.commands.Count + " §acommands");
                                        SendCommand(ChatTools.Tellraw("@a", TellrawColor.red, "Don't forget to enable the first command block if necessary"));
                                        //SendCommand("say §c§l§nDon't §c§l§nforget §cto §cenable §cthe §cfirst §cCommand §cBlock §cif §cnecessary");
                                    }
                                }
                                //Reimports the last locally imported file at the given selector
                                //Does not reimport from a link
                                //Example:
                                //@!reimport @p
                                else if (chatMessage.TrimStart().StartsWith("@!reimport "))
                                {
                                    ImportFile(true, chatMessage.CommandArgument("@!reimport"));
                                }
                                //Restarts the server by sending the 'stop' command and then restarting it
                                //Example:
                                //@!restart
                                else if (chatMessage.TrimStart().StartsWith("@!restart"))
                                {
                                    ServerManager.Restart = true;
                                    Close();
                                }
                                //Adds the specefied text to a text file stored in the server's root directory
                                //Useful to store coordinates or ideas
                                //Example:
                                //@!addline This text will be put in a text file
                                //@!addtext This text will be put in a text file
                                else if (chatMessage.TrimStart().StartsWith("@!addtext ") || chatMessage.TrimStart().StartsWith("@!addline "))
                                {
                                    string textLine = chatMessage.CommandArgument("@!addtext");
                                    timeString      = DateTime.Now.ToString("M/d HH:mm:ss");
                                    try
                                    {
                                        File.AppendAllLines(System.IO.Path.GetDirectoryName(ServerManager.ServerJarPath) + ServerManager.MinecraftServer.StartInfo.WorkingDirectory.Split('\\')[ServerManager.MinecraftServer.StartInfo.WorkingDirectory.Split('\\').Length - 1] + ".txt", new string[] { "[" + timeString + "] <" + user + "> " + textLine });
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.green, "Added line to file successfully"));
                                    }
                                    catch (Exception ex)
                                    {
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.red, "Failed to add line to file" + ex.Message));
                                    }
                                }
                                //Views a page (5 lines) from the text file
                                //Example:
                                //@!viewtext 3
                                //@!viewtext
                                else if (chatMessage.TrimStart().StartsWith("@!viewtext "))
                                {
                                    try
                                    {
                                        int page = 0;
                                        if (!int.TryParse(chatMessage.CommandArgument("@!viewtext"), out page))
                                        {
                                            page = 1;
                                        }
                                        string[] fileLines = File.ReadAllLines(System.IO.Path.GetDirectoryName(ServerManager.ServerJarPath) + ServerManager.MinecraftServer.StartInfo.WorkingDirectory.Split('\\')[ServerManager.MinecraftServer.StartInfo.WorkingDirectory.Split('\\').Length - 1] + ".txt");
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.aqua, "Page " + page + "/" + Math.Ceiling(fileLines.Length / 5f)));
                                        for (int i = 5 * page - 5; i < 5 * page; i++)
                                        {
                                            try
                                            {
                                                SendCommand(ChatTools.Tellraw(user, TellrawColor.aqua, i + 1 + ": " + fileLines[i]));
                                            }
                                            catch
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.red, "Failed to read file: " + ex.Message));
                                    }
                                }
                                //Deletes the specefied line from the text file
                                //Example:
                                //@!delline 2
                                else if (chatMessage.TrimStart().StartsWith("@!delline "))
                                {
                                    try
                                    {
                                        int line                = Convert.ToInt32(chatMessage.CommandArgument("@!delline")) - 1;
                                        string path             = System.IO.Path.GetDirectoryName(ServerManager.ServerJarPath) + ServerManager.MinecraftServer.StartInfo.WorkingDirectory.Split('\\')[ServerManager.MinecraftServer.StartInfo.WorkingDirectory.Split('\\').Length - 1] + ".txt";
                                        List <string> fileLines = File.ReadAllLines(path).ToList();
                                        fileLines.RemoveAt(line);
                                        File.WriteAllLines(path, fileLines);
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.green, "Deleted line " + line));
                                    }
                                    catch (Exception ex)
                                    {
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.red, "Couldn't delete line: " + ex.Message));
                                    }
                                }
                                //Shows all commands, their syntax, and their description
                                //TODO: Allow user-made commands to have a help message
                                //Example:
                                //@!help
                                //TODO: @!help import
                                else if (chatMessage.TrimStart().StartsWith("@!help"))
                                {
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, "@!import [link|filepath]: Imports a remote MCCBL file"));
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, "@!reimport [selector]: Reimports last locally imported file (no links)"));
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, "@!restart: Restarts the server"));
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, "@!addtext | @!addline [text]: Adds a line of text to the server notes"));
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, "@!viewtext [page]: Shows a page of the server notes"));
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, "@!delline [line number]: Deletes a line of text from the server notes"));

                                    foreach (CBLFile customCommand in CustomCommands.Values)
                                    {
                                        string helpText = customCommand.Properties.ContainsKey("HELP") ? customCommand.Properties["HELP"] : "No help text found";
                                        string syntax   = customCommand.Properties.ContainsKey("SYNTAX") ? customCommand.Properties["SYNTAX"] : "";
                                        SendCommand(ChatTools.Tellraw(user, TellrawColor.yellow, customCommand.FileName.Replace(".mccbl", "") + " " + syntax + ": " + helpText));
                                    }
                                }
                                //If no command was found, tell user it doesn't exist
                                else if (!wasUserMade)
                                {
                                    SendCommand(ChatTools.Tellraw(user, TellrawColor.red, "[ERROR] Unknown command or bad syntax, Type @!help for help"));
                                }
                            }

                            //Add chat messages to server console window
                            string timestringa = DateTime.Now.ToString("M/d HH:mm:ss");
                            ConsoleWindow.AppendColoredText(string.Format("\r[{0}]: <{2}> {1}", timestringa, chatMessage.Trim(), ChatTools.FilterUsername(ChatTools.FilterCommand(ServerManager.LastRecievedMessage))), new SolidColorBrush(Color.FromRgb(155, 38, 175)));
                            ConsoleWindow.ScrollToEnd();
                            return;
                        }
                        //Add other messages to server console window
                        string timestring = DateTime.Now.ToString("M/d HH:mm:ss");
                        ConsoleWindow.AppendColoredText(string.Format("\r[{0}]: {1}", timestring, ChatTools.FilterCommand(ServerManager.LastRecievedMessage).Trim()), textColor);
                        ConsoleWindow.ScrollToEnd();
                    }
                });
            }
            catch
            {
            }
        }
Exemple #6
0
        /*
         * private int GetFacingDirection(int xmax, int zmax, int x, int y, int z, int index)
         * {
         *  //5 forward
         *  //3 right
         *  //4 backwards
         *  //1 up
         *  //2 left
         *
         *  //WAIT THIS WON'T WORK IF THERE ARE AN EVEN NUMBER OF ROWS/COLUMNS
         *  if (y % 2 == 0)
         *  {
         *      if (z % 2 == 0 && x > 0 && x < xmax) { return 5; }
         *      else if ((z % 2 == 0 && x == xmax) || (z % 2 == 1 && x == 1)) { return 3; }
         *      else if (z == zmax - 1 && x == xmax) { return 1; }
         *  }
         *  else
         *  {
         *      if (z % 2 == 0 && x > 0 && x < xmax) { return 5; }
         *      else if ((z % 2 == 0 && x == xmax) || (z % 2 == 1 && x == 1)) { return 3; }
         *      else if (z == zmax - 1 && x == xmax) { return 1; }
         *  }
         *
         * }
         */

        /// <summary>
        /// Imports the current CBLFile as command blocks using the current ServerManager
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public bool Import(MainWindow window)
        {
            Window = window;

            //Don't know what this bit here does, but I don't want to remove it
            string fileInformation = "";

            foreach (string l in FileLines)
            {
                fileInformation += "\n" + l;
            }
            //*****

            if (Selector != null || webLink || new ScriptLoader(FileName, FileLines, Commands, Properties).ShowDialog() == true)
            {
                bool repeat  = Properties.ContainsKey("TYPE") && Properties["TYPE"] == "REPEAT";
                bool powered = !(!Properties.ContainsKey("CHAIN") || Properties["CHAIN"] == "OFF");

                int loopedCommands = 0;
                int yOffset        = 0;

                #region WIP New Code

                /*
                 * TEMP
                 * int xmax = 5;
                 * int zmax = 5;
                 *
                 * while (loopedCommands < Commands.Count)
                 * {
                 *  for (int z = 0; z < zmax; z++)
                 *  {
                 *      for (int x = 1; x < xmax + 1; x++)
                 *      {
                 *          if (Commands.Count == loopedCommands) { break; };
                 *          string facing = GetFacingDirection(xmax, zmax, x, yOffset, z, loopedCommands).ToString();
                 *
                 *          string commandToSend = BuildCommand(Commands[loopedCommands], x, yOffset, z, facing, repeat, powered);
                 *          ServerManager.MinecraftServer.StandardInput.WriteLine(commandToSend);
                 *          ServerManager.MinecraftServer.StandardInput.Flush();
                 *          loopedCommands++;
                 *      }
                 *  }
                 *  yOffset++;
                 *  for (int z = 0; z < zmax; z++)
                 *  {
                 *      for (int x = 1; x < xmax + 1; x++)
                 *      {
                 *          if (Commands.Count == loopedCommands) { break; };
                 *          string facing = GetFacingDirection(xmax, zmax, xmax - x, yOffset, zmax - z, loopedCommands).ToString();
                 *
                 *          string commandToSend = BuildCommand(Commands[loopedCommands], xmax - x, yOffset, zmax - z, facing, repeat, powered);
                 *          ServerManager.MinecraftServer.StandardInput.WriteLine(commandToSend);
                 *          ServerManager.MinecraftServer.StandardInput.Flush();
                 *          loopedCommands++;
                 *      }
                 *  }
                 *  yOffset++;
                 * }
                 *
                 */
                #endregion

                while (loopedCommands < Commands.Count)
                {
                    for (int i = 0; i < 25; i++)
                    {
                        if (Commands.Count != loopedCommands)
                        {
                            //TODO: Find some way to fix this conditional problem
                            //May not be fixable in the current implementation
                            //See https://github.com/aopell/MCCBL/blob/master/Examples/Conditionals%20Issue.png
                            if (Commands[loopedCommands].CommandType == Command.Type.Conditional && new int[] { 0, 4, 5, 9, 10, 14, 15, 19, 20, 24 }.Contains(i))
                            {
                                ServerManager.MinecraftServer.StandardInput.WriteLine(ChatTools.Tellraw("@a", TellrawColor.red, "[WARNING] Conditional command not supported at height " + yOffset + " command index " + i));
                                ServerManager.MinecraftServer.StandardInput.WriteLine(ChatTools.Tellraw("@a", TellrawColor.red, "[WARNING] Problem command: " + Commands[loopedCommands].CommandText));
                                ServerManager.MinecraftServer.StandardInput.Flush();
                            }

                            //UGLY IF STATEMENTS
                            if (yOffset % 2 == 0)
                            {
                                string commandToSend = "";
                                if (i >= 0 && i < 4)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], i + 1, yOffset, 0, "5", repeat, powered);
                                }
                                else if (i == 4)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 5, yOffset, 0, "3", repeat, powered);
                                }
                                else if (i > 4 && i < 9)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 10 - i, yOffset, 1, "4", repeat, powered);
                                }
                                else if (i == 9)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 1, yOffset, 1, "3", repeat, powered);
                                }
                                else if (i > 9 && i < 14)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], i - 9, yOffset, 2, "5", repeat, powered);
                                }
                                else if (i == 14)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 5, yOffset, 2, "3", repeat, powered);
                                }
                                else if (i > 14 && i < 19)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 20 - i, yOffset, 3, "4", repeat, powered);
                                }
                                else if (i == 19)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 1, yOffset, 3, "3", repeat, powered);
                                }
                                else if (i > 19 && i < 24)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], i - 19, yOffset, 4, "5", repeat, powered);
                                }
                                else if (i == 24)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 5, yOffset, 4, "1", repeat, powered);
                                }
                                ServerManager.MinecraftServer.StandardInput.WriteLine(commandToSend);
                                ServerManager.MinecraftServer.StandardInput.Flush();
                            }
                            //0: down -y 1: up +y 2: north -z 3: south +z 4: west -x 5: east +x
                            else
                            {
                                string commandToSend = "";
                                if (i >= 0 && i < 4)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 5 - i, yOffset, 4, "4", repeat, powered);
                                }
                                else if (i == 4)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 1, yOffset, 4, "2", repeat, powered);
                                }
                                else if (i > 4 && i < 9)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], i - 4, yOffset, 3, "5", repeat, powered);
                                }
                                else if (i == 9)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 5, yOffset, 3, "2", repeat, powered);
                                }
                                else if (i > 9 && i < 14)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 15 - i, yOffset, 2, "4", repeat, powered);
                                }
                                else if (i == 14)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 1, yOffset, 2, "2", repeat, powered);
                                }
                                else if (i > 14 && i < 19)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], i - 14, yOffset, 1, "5", repeat, powered);
                                }
                                else if (i == 19)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 5, yOffset, 1, "2", repeat, powered);
                                }
                                else if (i > 19 && i < 24)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 25 - i, yOffset, 0, "4", repeat, powered);
                                }
                                else if (i == 24)
                                {
                                    commandToSend = BuildCommand(Commands[loopedCommands], 1, yOffset, 0, "1", repeat, powered);
                                }
                                ServerManager.MinecraftServer.StandardInput.WriteLine(commandToSend);
                                ServerManager.MinecraftServer.StandardInput.Flush();
                            }
                            loopedCommands++;
                        }
                    }
                    yOffset++;
                }

                ServerManager.MinecraftServer.StandardInput.WriteLine("execute " + Selector + " ~ ~ ~ setblock ~ ~ ~ minecraft:wall_sign 4 replace");
                ServerManager.MinecraftServer.StandardInput.Flush();
                ServerManager.MinecraftServer.StandardInput.WriteLine("execute " + Selector + " ~ ~ ~ blockdata ~ ~ ~ {Text1:\"[{\\\"text\\\":\\\"" + (!webLink ? FileName.Replace(".mccbl", "") : "Remote Import") + "\\\"}]\"" + ",Text2:\"[{\\\"text\\\":\\\"" + Commands.Count + " Commands" + "\\\"}]\"" + ",Text3:\"[{\\\"text\\\":\\\"" + DateTime.Now.ToString("dd MMM yyyy") + "\\\"}]\"" + ",Text4:\"[{\\\"text\\\":\\\"" + DateTime.Now.ToString("HH:mm:ss") + "\\\"}]\"}");
                ServerManager.MinecraftServer.StandardInput.Flush();
            }
            else
            {
                return(false);
            }

            return(true);
        }