Now you don't have to add every plugin when you load server.
There is a slight drawback which makes the plugins appear 2x, idk why it happens either :S.
But, it's a better alternative than nothing.
- Code: Select all
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace MCDzienny.Plugins
{
public class AutoIt : Plugin
{
// The name of the plugin.
string name = "AutoIt";
// A relatively short description of the plugin.
string description = "Manage the automacity of your plugins";
// 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 AutoIt_GUI();
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()
{
if (!Directory.Exists("extra/plugins"))
Directory.CreateDirectory("extra/plugins");
if (!Directory.Exists("extra/plugins/appdata"))
Directory.CreateDirectory("extra/plugins/appdata");
if (!Directory.Exists("extra/plugins/source"))
Directory.CreateDirectory("extra/plugins/source");
if (!File.Exists("text/autoplug.txt"))
File.Create("text/autoplug.txt");
if (!File.Exists("extra/commands/source/Cmdautoplug.cs"))
{
StreamWriter sw = new StreamWriter(File.Create("extra/commands/source/Cmdautoplug.cs"));
sw.Write(
"using System;" + Environment.NewLine +
"using System.IO;" + Environment.NewLine +
"namespace MCDzienny" + Environment.NewLine +
"{" + Environment.NewLine +
"\tpublic class Cmdautoplug : Command" + Environment.NewLine +
"\t{" + Environment.NewLine +
"\t\tpublic override string name { get { return \" autoplug\"; } }" + Environment.NewLine +
"\t\tpublic override string shortcut { get { return \"\"; } }" + Environment.NewLine +
"\t\tpublic override string type { get { return \"other\"; } }" + Environment.NewLine +
"\t\tpublic override bool museumUsable { get { return false; } }" + Environment.NewLine +
"\t\tpublic override LevelPermission defaultRank { get { return LevelPermission.Banned; } }" +
Environment.NewLine +
"\t\tpublic override void Init()" + Environment.NewLine +
"\t\t{" + Environment.NewLine +
" Server.Plugins.ClosePlugins();" + Environment.NewLine +
"\t\t\tforeach(string line in File.ReadAllLines(\"text/autoplug.txt\")){if(File.Exists(\"extra/plugins/source/\"+line+\".cs\")){Server.Plugins.AddPluginFromString(File.ReadAllText(\"extra/plugins/source/\"+line+\".cs\"));Player.SendMessage(null, line + \" (plugin) loaded.\");}}" + Environment.NewLine +
"\t\t}" + Environment.NewLine +
"\t\tpublic override void Use(Player p, string message)" + Environment.NewLine +
"\t\t{" + Environment.NewLine +
"\t\t}" +
Environment.NewLine +
"\t\tpublic override void Help(Player p)" + Environment.NewLine +
"\t\t{" + Environment.NewLine +
"\t\t\tPlayer.SendMessage(p, \"/autoplug -- Autoloads plugins.\");" + Environment.NewLine +
"\t\t}" + Environment.NewLine +
"\t}" + Environment.NewLine +
"}");
sw.Dispose();
Command.all.Find("compile").Use(null, "autoplug");
Command.all.Find("cmdload").Use(null, "autoplug");
File.AppendAllText("text/cmdautoload.txt", Environment.NewLine + "autoplug");
}
if (!File.Exists("extra/plugins/source/AutoIt.cs"))
{
MessageBox.Show("Try it out! Copy this plugin's source code in to the textbox!");
}
}
public override void Terminate()
{
}
}
}
namespace MCDzienny.Plugins
{
public partial class AutoIt_GUI : UserControl
{
public AutoIt_GUI()
{
InitializeComponent();
}
}
}
namespace MCDzienny.Plugins
{
partial class AutoIt_GUI
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void addit_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text == "")
{
MessageBox.Show("Code cannot be left blank!");
return;
}
List<string> after = new List<string>();
AddList(after, false);
Server.Plugins.AddPluginFromString(textBox1.Text);
AddList(after, true);
string path = "extra/plugins/source/" + name + ".cs";
if (File.Exists(path))
{
MessageBox.Show("Plugin already exists.");
return;
}
File.WriteAllText(path, textBox1.Text);
File.AppendAllText("text/autoplug.txt", Environment.NewLine + name);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private string name = "AutoIt";
void AddList(List<string> list, bool check)
{
Server.Plugins.AvailablePlugins.ForEach(ap =>
{
if (!list.Contains(ap.Instance.Name))
{
list.Add(ap.Instance.Name);
if (check)
name = ap.Instance.Name;
}
});
}
private void comboBox1_Click(object sender, EventArgs e)
{
try
{
string content = File.ReadAllText("text/autoplug.txt");
Server.Plugins.AvailablePlugins.ForEach(ap =>
{
if (content.Contains(ap.Instance.Name))
if (!comboBox1.Items.Contains(ap.Instance.Name))
comboBox1.Items.Add(ap.Instance.Name);
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void removeit_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "")
MessageBox.Show("No plugin chosen");
AvailablePlugin p = null;
Server.Plugins.AvailablePlugins.ForEach(ap =>
{
if (comboBox1.Text == ap.Instance.Name)
{
p = ap;
}
});
if (p == null)
{
MessageBox.Show("Plugin not found");
return;
}
File.Delete("extra/plugins/source/" + p.Instance.Name + ".cs");
using (var sr = new StreamReader("text/autoplug.txt"))
{
using (var sw = new StreamWriter("text/autoplug1.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (!line.Contains(p.Instance.Name))
sw.WriteLine(line);
}
}
}
File.Delete("text/autoplug.txt");
File.Move("text/autoplug1.txt", "text/autoplug.txt");
}
void textBox1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}
private void InitializeComponent()
{
this.addit = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.removeit = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// addit
//
this.addit.BackColor = System.Drawing.Color.White;
this.addit.Location = new System.Drawing.Point(12, 611);
this.addit.Name = "addit";
this.addit.Size = new System.Drawing.Size(480, 23);
this.addit.TabIndex = 0;
this.addit.Text = "AutoAdd";
this.addit.UseVisualStyleBackColor = false;
this.addit.Click += new System.EventHandler(this.addit_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 88);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(480, 517);
this.textBox1.TabIndex = 1;
textBox1.Click+=new EventHandler(textBox1_Click);
//
// removeit
//
this.removeit.BackColor = System.Drawing.Color.White;
this.removeit.Location = new System.Drawing.Point(12, 59);
this.removeit.Name = "removeit";
this.removeit.Size = new System.Drawing.Size(480, 23);
this.removeit.TabIndex = 2;
this.removeit.Text = "RemoveAuto";
this.removeit.UseVisualStyleBackColor = false;
this.removeit.Click += new System.EventHandler(this.removeit_Click);
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(12, 31);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(480, 22);
this.comboBox1.TabIndex = 3;
this.comboBox1.Click += new System.EventHandler(this.comboBox1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(231, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(39, 14);
this.label1.TabIndex = 4;
this.label1.Text = "AutoIt";
//
// GUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Honeydew;
this.ClientSize = new System.Drawing.Size(504, 646);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.removeit);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.addit);
this.Font = new System.Drawing.Font("Miramonte", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ForeColor = System.Drawing.Color.Black;
this.Name = "GUI";
this.Text = "GUI";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button addit;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button removeit;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
}
}