Page 1 of 2

Command Add

PostPosted: 21 Jun 2013, 23:05
by ismellike
This plugin is to add commands easier :)!

Picture at the bottom

The code also has the method _x and _y which I found extremely useful in making the gui.

The plugin is pretty self explanatory so not much else to talk about.

Code: Select all
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace MCDzienny.Plugins
{
    public class LevelShare : Plugin
    {
        // The name of the plugin.
        string name = "Command Add";

        // A relatively short description of the plugin.
        string description = "Add a command easily.";

        // A name or names of the authors of the plugin.
        string author = "ismellike";

        // A version number that is displayed to the end users.
        string version = "1.0";

        // A version number that is used for update checking. It's an absolute number that
        // represents a release number. It should be incremented by 1 each time the new version
        // is released.
        int versionNumber = 1;

        // A user control that contains graphical user interface of the plugin.
        UserControl gui = new GuiExample();

        public override string Description
        {
            get { return description; }
        }

        public override string Author
        {
            get { return author; }
        }
        public override string Name
        {
            get { return name; }
        }

        public override UserControl MainInterface
        {
            get { return gui; }
        }

        public override string Version
        {
            get { return version; }
        }

        public override int VersionNumber
        {
            get { return versionNumber; }
        }

        public override void Initialize()
        {
        }

        public override void Terminate()
        {
        }
    }
}



namespace MCDzienny.Plugins
{
    public partial class GuiExample : UserControl
    {
        public GuiExample()
        {
            InitializeComponent();
        }
    }
}

namespace MCDzienny.Plugins
{
    partial class GuiExample
    {
        private string cmdname;
        private System.ComponentModel.IContainer components = null;
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code
        private void Add_Command(object sender, EventArgs e)
        {
            try
            {
                if (commandname.Text.Length == 0)
                {
                    MessageBox.Show("Command name cannot be left blank");
                    return;
                }
                cmdname = commandname.Text;
                if (code.Text.Length == 0)
                {
                    MessageBox.Show("Code cannot be left blank");
                    return;
                }
                if (File.Exists(@"extra\\commands\\source\\Cmd" + cmdname + ".cs") && Override.Checked != true)
                {
                    MessageBox.Show("Command already exists");
                    return;
                }
                //transfer code to a code file
                File.WriteAllText(@"extra\\commands\\source\\Cmd" + cmdname + ".cs", code.Text);
                string done = "";
                if (compile.Checked)
                {
                    Command.all.Find("compile").Use(null, cmdname);
                    done += "+compile ";
                }
                if (unload.Checked)
                {
                    Command.all.Find("cmdunload").Use(null, cmdname);
                    done += "+unload ";
                }
                if (load.Checked)
                {
                    Command.all.Find("cmdload").Use(null, cmdname);
                    done += "+load ";
                }
                if (cmdautoload.Checked)
                {
                    if (!File.ReadAllText("text/cmdautoload.txt").Contains(cmdname))
                    {
                        File.AppendAllText("text/cmdautoload.txt", Environment.NewLine + cmdname);
                        done += "+auto ";
                    }
                    else
                    {
                        MessageBox.Show(cmdname + " is already on the autoload list");
                    }
                }
                MessageBox.Show("Command added " + done);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Clear_Click(object sender, EventArgs e)
        {
            code.Text = "";
            commandname.Text = "";
        }
        private int _x(Control x)
        {
            return Convert.ToInt32(x.Size.Width + x.Location.X + 10);
        }
        private int _y(Control y)
        {
            return Convert.ToInt32(y.Height + y.Location.Y + 10);
        }
        private void InitializeComponent()
        {
            try
            {
                lcode = new Label();
                lname = new Label();
                lcs = new Label();
                Clear = new Button();
                Override = new CheckBox();
                compile = new CheckBox();
                unload = new CheckBox();
                load = new CheckBox();
                cmdautoload = new CheckBox();
                code = new TextBox();
                commandname = new TextBox();
                Cmdadd = new Button();
                SuspendLayout();
                //Top Labels
                lcode.AutoSize = lcs.AutoSize = lname.AutoSize = true;
                lcode.TabIndex = lcs.TabIndex = lname.TabIndex = 0;
                lcode.ForeColor = lcs.ForeColor = lname.ForeColor = Color.Black;
                lcode.Location = new Point(10, 10);
                lcode.Name = "label1";
                lcode.Size = new Size(40, 20);
                lcode.Text = "Code:";
                lcode.Font = lcs.Font = lname.Font = new Font("Courier New", 12F);
                //
                // code : TextBox
                //
                code.Location = new Point(10, _y(lcode) - 10);
                code.Name = "code";
                code.Size = new Size(480, 500);
                code.TabIndex = 0;
                code.Multiline = true;
                code.ScrollBars = ScrollBars.Vertical;
                //
                // CHECKBOXES
                //
                this.compile.AutoSize = unload.AutoSize = load.AutoSize = cmdautoload.AutoSize = Override.AutoSize = true;
                this.compile.Size = unload.Size = load.Size = cmdautoload.Size = Override.Size = new Size(80, 20);
                this.compile.TabIndex = unload.TabIndex = load.TabIndex = cmdautoload.TabIndex = Override.TabIndex = 0;
                this.compile.UseVisualStyleBackColor = unload.UseVisualStyleBackColor = load.UseVisualStyleBackColor = cmdautoload.UseVisualStyleBackColor = Override.UseVisualStyleBackColor = false;
                //^same for all checkboxes
                this.compile.Text = compile.Name = "Compile";
                this.compile.Location = new Point(10, _y(code));
                unload.Text = unload.Name = "Unload";
                unload.Location = new Point(_x(compile), compile.Location.Y);
                load.Text = load.Name = "load";
                load.Location = new Point(_x(unload), compile.Location.Y);
                cmdautoload.Text = cmdautoload.Name = "cmdautoload";
                cmdautoload.Location = new Point(_x(load), compile.Location.Y);
                Override.Text = Override.Name = "override";
                Override.Location = new Point(_x(cmdautoload), compile.Location.Y);
                //
                // Cmdadd : Button
                //
                Cmdadd.BackColor = Clear.BackColor = Color.Black;
                Cmdadd.ForeColor = Clear.ForeColor = Color.Yellow;
                Cmdadd.Location = new Point(10, _y(compile));
                Cmdadd.Name = "download";
                Cmdadd.Size = new Size(480, 25);
                Cmdadd.TabIndex = 0;
                Cmdadd.Text = "Add!";
                Cmdadd.UseVisualStyleBackColor = Clear.UseVisualStyleBackColor = false;
                Cmdadd.Click += new EventHandler(Add_Command);
                //Cmd label
                lname.Location = new Point(10, _y(Cmdadd)+3);
                lname.Name = "Cmd";
                lname.Size = new Size(40, 40);
                lname.Text = "Cmd";
                // Command name : Textbox
                commandname.Location = new Point(_x(lname) - 15, _y(Cmdadd));
                commandname.Name = "cmdname";
                commandname.Size = new Size(50, 30);
                commandname.TabIndex = 0;
                //.cs label
                lcs.Location = new Point(_x(commandname) - 15, _y(Cmdadd) + 3);
                lcs.Name = ".cs";
                lcs.Size = new Size(40, 40);
                lcs.Text = ".cs";
                // clear : Button
                Clear.Location = new Point(_x(lcs)+10, commandname.Location.Y);
                Clear.Name = "clear text";
                Clear.Size = new Size(340, 30);
                Clear.TabIndex = 0;
                Clear.Text = "Clear Text";
                Clear.Click += new EventHandler(Clear_Click);
                //
                // Gui
                //
                AutoScaleDimensions = new SizeF(6F, 13F);
                AutoScaleMode = AutoScaleMode.Font;
                BackColor = Color.LightSlateGray;
                Name = "Gui";
                Size = new Size(465, 378);
                Controls.Add(Cmdadd);
                Controls.Add(code);
                Controls.Add(compile);
                Controls.Add(unload);
                Controls.Add(load);
                Controls.Add(cmdautoload);
                Controls.Add(Override);
                Controls.Add(commandname);
                Controls.Add(Clear);
                Controls.Add(lcode);
                Controls.Add(lcs);
                Controls.Add(lname);
                ResumeLayout(false);
                PerformLayout();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion
        private Label lcode, lname, lcs;
        private Button Cmdadd, Clear;
        private TextBox code, commandname;
        private CheckBox compile, unload, load, cmdautoload, Override;
    }
}


screen.PNG
screen.PNG (6.65 KiB) Viewed 3998 times

Re: Command Add

PostPosted: 22 Jun 2013, 10:58
by joppiesaus
Usefull and awsome!
Really great work

Re: Command Add

PostPosted: 22 Jun 2013, 12:37
by dzienny
It's really sweet. If there were a must-have list of the plugins, it would be somewhere on top :)

Re: Command Add

PostPosted: 24 Jul 2013, 12:56
by jacobdynomite
when in consol how do i scroll down to see like the add button and all that?

Re: Command Add

PostPosted: 24 Jul 2013, 13:44
by HETAL
You have to do full screen with the console

Re: Command Add

PostPosted: 27 Jul 2013, 13:03
by D3athdog
when i add this plugin it doesn't show the "add command" part and when i go full screen it still won't show. how do i fix this :?:

Re: Command Add

PostPosted: 27 Jul 2013, 14:46
by joppiesaus
D3athdog wrote:when i add this plugin it doesn't show the "add command" part and when i go full screen it still won't show. how do i fix this :?:

Did you selected it in the listbox? (The thing on the side where command add is displayed in a list)

Re: Command Add

PostPosted: 07 May 2014, 06:25
by asdfmovie2121
This plugin doesn't work anymore take a look at the errors
-------------------------

Error #CS0006
Message: Metadata file 'Mono.Data.Sqlite.dll' could not be found
Line: 0

-------------------------

Error #CS0006
Message: Metadata file 'SuperWebSocket.dll' could not be found
Line: 0

-------------------------

Error #CS0006
Message: Metadata file 'SuperSocket.SocketBase.dll' could not be found
Line: 0

Re: Command Add

PostPosted: 07 May 2014, 08:51
by _Retaliate_
It's because of the update, dzienny, you should make the updater.exe download any new dlls that you've started using as well.

Re: Command Add

PostPosted: 08 May 2014, 20:15
by dzienny
I added a websocket library to support the new remote client. The library was embedded into MCDzienny_.dll. And it seems that the compiler can't find it. It will be fixed in the release. Thank you for the information.

Also, if you wonder why it's embedded instead of being provided as a separate library. I would have to rewrite the updater to make it possible because currently it can only update three files: MCDzienny.exe, MCDzienny_.dll and changelog.txt.