Plugins

Plugins

Postby dzienny » 19 Jun 2013, 01:00

Plugins are components that extend the functionality of MCDzienny. They can be created by anyone who knows how to program in C# language and has a basic knowledge of MCDzienny API.

MCDzienny has already many addons in the form of Custom Commands. But Custom Commands don't support a graphical user interface (GUI). Plugins by design have to provide a GUI and the GUI is in the form of the System.Windows.Forms.UserControl object. The UserControl is included on the MCDzienny's GUI "Plugins" tab in the allocated space.

The graphical plugins were suggested by Conor some time ago. I thought that it was a good idea, because it allows capable programmers to create a very advanced addons for MCDzienny that unlock a new level of interaction between the addon, the addon creator and the server owner.

Currently the plugin environment and API are still in development. However, owners can already add a new plugin to their servers. But the plugin won't be auto-loaded on a server restart, hence the owner has to add the plugin each time he or she starts a server.

The process of adding plugins is simple. The server owner has to paste the plugin code into a text box in AddPlugin Plugin and then click the button "Add Plugin". The code will be then compiled and if there's no error it will be initialized and added to the plugins list.

The plugins consist of two parts. One is a code that is responsible for what the plugin does and its description, the other is a code that contains graphical user interface elements.

An example of a plugin (part 1 of 2):
Code: Select all
using System;

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

        // A relatively short description of the plugin.
        string description = "It displays "Hello World" message in GUI.";

        // A name or names of the authors of the plugin.
        string author = "Dzienny";
       
        // 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.
        System.Windows.Forms.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 System.Windows.Forms.UserControl MainInterface
        {
            get { return gui; }
        }

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

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

        public override void Initialize()
        {
            // The code that is run when the plugin is added.
        }

        public override void Terminate()
        {
            // The clean up code. It may be include closing timers, ending threads, disposing
            // unmanaged resources, also, saving changes to a database or a config file.
        }
    }
}


Gui (part 2 of 2):
Code: Select all
using System.Windows.Forms;

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

namespace MCDzienny.Plugins
{
    partial class GuiExample
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.labelMessage = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // labelMessage
            //
            this.labelMessage.AutoSize = true;
            this.labelMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F,

System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.labelMessage.ForeColor = System.Drawing.Color.Brown;
            this.labelMessage.Location = new System.Drawing.Point(173, 163);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(106, 20);
            this.labelMessage.TabIndex = 0;
            this.labelMessage.Text = "Hello World!";
            //
            // GuiExample
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.Controls.Add(this.labelMessage);
            this.Name = "GuiExample";
            this.Size = new System.Drawing.Size(465, 378);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label labelMessage;
    }
}


To run the above plugin, you have to paste the both source codes into an Add Plugin text box. Then move "using System.Windows.Forms;" to the first line and click "Add Plugin" button.

Spoiler:


Due to the complexity of UserControl you have to use a free tool called Visual Studio C# Express Edition. It allows you to easily create a UserControl object.

If you have any suggestions that regard the plugins environment, they are very welcome. The API is not final yet, so it's still possible to change it.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Plugins

Postby ismellike » 19 Jun 2013, 01:07

This is really cool, will definitely try making one.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Plugins

Postby joppiesaus » 19 Jun 2013, 09:30

Awsome.
Wouldn't it be cool if you can just generate a skeleton class for a plugin(like cmdcreate)?
Also, if the Plugin system is complete, a section for new plugins(in the cusom commands section plugins)? :D
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Plugins

Postby dzienny » 19 Jun 2013, 20:20

joppiesaus wrote:Wouldn't it be cool if you can just generate a skeleton class for a plugin(like cmdcreate)?

At this point I don't plan to add a skeleton class generator, because plugins are more complicated than custom commands and should be created only in Visual Studio C#.

joppiesaus wrote:Also, if the Plugin system is complete, a section for new plugins(in the cusom commands section plugins)? :D

Yes, there will be a new section :)
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Plugins

Postby Conor » 19 Jun 2013, 20:24

This is really really cool, I can't wait to learn from it and try to create some simple things.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Knowledge Base

Who is online

Users browsing this forum: No registered users and 2 guests

cron