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.