for example: if you type in $derp, the output will be derpina!
here's the code, it works without restarting the server.
Spoiler:
- Code: Select all
using System;
using System.IO;
using System.Windows.Forms;
using MCDzienny;
namespace MCDzienny.Plugins
{
public class example : Plugin
{
versionInfoPlugin info = new versionInfoPlugin("Chat constant generator", "Adds a chat constant, for example $name!", "joppiesaus", "1.0", 1);
mainControl gui = new mainControl();
public override string Description
{
get { return info.descr; }
}
public override string Author
{
get { return info.auth; }
}
public override string Name
{
get { return info.name; }
}
public override System.Windows.Forms.UserControl MainInterface
{
get { return gui; }
}
public override string Version
{
get { return info.ver; }
}
public override int VersionNumber
{
get { return info.verNumber; }
}
public override void Initialize()
{
}
public override void Terminate()
{
}
}
public class versionInfoPlugin
{
public string name { get; set; }
public string descr { get; set; }
public string auth { get; set; }
public string ver { get; set; }
public int verNumber { get; set; }
public versionInfoPlugin(string nameOfAssembly, string description, string author, string version, int versionNumber)
{
name = nameOfAssembly;
descr = description;
auth = author;
ver = version;
verNumber = versionNumber;
}
}
public partial class mainControl : UserControl
{
public string path = string.Format(@"{0}\text\chat_constant$.txt", Application.StartupPath);
public mainControl()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
generate();
}
}
void generate()
{
try
{
string readed;
using (StreamReader read = new StreamReader(path))
{
readed = read.ReadToEnd();
}
using (StreamWriter write = new StreamWriter(path))
{
string toWrite = textBox1.Text + " : " + textBox2.Text;
write.Write(readed + System.Environment.NewLine + toWrite);
}
Command.all.Find("setlava").Use(null, "reloadtexts");
MessageBox.Show("Chat constant succesfully added!", "Done!");
}
catch (Exception ex)
{
MessageBox.Show("Failed to add the chat constant. Error log:" + System.Environment.NewLine + System.Environment.NewLine + ex);
}
}
}
partial class mainControl
{
/// <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.components = new System.ComponentModel.Container();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(47, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(437, 20);
this.textBox1.TabIndex = 0;
this.toolTip1.SetToolTip(this.textBox1, "The output of the chat. What visible is for the rest of the server.");
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(47, 34);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(437, 20);
this.textBox2.TabIndex = 1;
this.toolTip1.SetToolTip(this.textBox2, "The input in the chat. This is what the user types in.");
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(34, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Input:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(4, 37);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(42, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Output:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(7, 60);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(474, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Generate";
this.toolTip1.SetToolTip(this.button1, "Generate it!");
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// toolTip1
//
this.toolTip1.AutoPopDelay = 5000;
this.toolTip1.InitialDelay = 410;
this.toolTip1.ReshowDelay = 100;
//
// mainControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "mainControl";
this.Size = new System.Drawing.Size(484, 95);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
}
}
Hopefully this will help you. Have fun with it