Don't expect any updates, because it is a simple plugin that allows you to enter a message and broadcast it in a specific time in milisecons.(this is actually also in the properties of mcdzienny)
So here is the code!
Normal one(with comments):
Spoiler:
- Code: Select all
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace MCDzienny.Plugins
{
public class Plgn : Plugin
{
public string path = string.Format(@"{0}\Plugins\Repeater.ini", Application.StartupPath);
public IniFile ini;
public string message = "(Repeater Plugin)Error: Message is not defined.";
public int interval = 10000;
public event EventHandler msgTextBoxChanged;
public event EventHandler intervalTextBoxChanged;
public event EventHandler startButtonEvent;
public event EventHandler stopButtonEvent;
public event EventHandler timerTickEvent;
versionInfoPlugin info = new versionInfoPlugin("Repeater", "A simple text repeater for all your daily messages.(test plugin)", "joppiesaus", "1.1", 2);
defaultGUI mainGui = new defaultGUI();
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 mainGui; }
}
public override string Version
{
get { return info.ver; }
}
public override int VersionNumber
{
get { return info.verNumber; }
}
public override void Initialize()
{
mainGui.msgTextBox.TextChanged += this.HandleMsgStuff;
mainGui.intervalTextBox.TextChanged += this.HandleIntervalStuff;
mainGui.startButton.Click += this.HandleStartButtonStuff;
mainGui.stopButton.Click += this.HandleStopButtonStuff;
mainGui.timer.Tick += this.HandleTimerStuff;
load();
}
#region eventHandlerStuff
private void HandleMsgStuff(object sender, EventArgs e)
{
this.msgTextBoxTextChanged(EventArgs.Empty);
}
private void HandleIntervalStuff(object sender, EventArgs e)
{
intervalTextBoxTextChanged(EventArgs.Empty);
}
private void HandleStartButtonStuff(object sender, EventArgs e)
{
this.startButtonClicked(EventArgs.Empty);
}
private void HandleStopButtonStuff(object sender, EventArgs e)
{
stopButtonClicked(EventArgs.Empty);
}
private void HandleTimerStuff(object sender, EventArgs e)
{
this.timerTick(EventArgs.Empty);
}
protected virtual void msgTextBoxTextChanged(EventArgs e)
{
EventHandler hand = this.msgTextBoxChanged;
if (hand != null)
{
hand(this, e);
}
message = mainGui.msgTextBox.Text;
}
protected virtual void intervalTextBoxTextChanged(EventArgs e)
{
EventHandler hand = this.intervalTextBoxChanged;
if (hand != null)
{
hand(this, e);
}
try
{
interval = Convert.ToInt32(mainGui.intervalTextBox.Text);
}
catch (Exception ex)
{
interval = 10000;
MessageBox.Show("-======ERROR======-" + System.Environment.NewLine + System.Environment.NewLine + ex, "ERROR");
}
}
protected virtual void startButtonClicked(EventArgs e)
{
EventHandler hand = this.startButtonEvent;
if (hand != null)
{
hand(this, e);
}
mainGui.timer.Enabled = true;
}
protected virtual void stopButtonClicked(EventArgs e)
{
EventHandler hand = this.stopButtonEvent;
if (hand != null)
{
hand(this, e);
}
mainGui.timer.Enabled = false;
}
protected virtual void timerTick(EventArgs e)
{
EventHandler hand = this.timerTickEvent;
if (hand != null)
{
hand(this, e);
}
mainGui.timer.Interval = interval;
Player.GlobalMessage(message);
}
#endregion
public override void Terminate()
{
mainGui.timer.Enabled = false;
save();
}
public void checkPath()
{
if (!File.Exists(path))
{
using (File.Create(path, 1024)) { }
}
}
public void save()
{
checkPath();
ini = new IniFile(path);
ini.WriteValue("Plugin", "Message", mainGui.msgTextBox.Text);
ini.WriteValue("Plugin", "Interval", mainGui.intervalTextBox.Text);
}
public void load()
{
checkPath();
ini = new IniFile(path);
mainGui.msgTextBox.Text = ini.ReadValue("Plugin", "Message");
mainGui.intervalTextBox.Text = ini.ReadValue("Plugin", "Interval");
}
}
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;
}
}
#region gui
public partial class defaultGUI
{
public defaultGUI()
{
InitializeComponent();
}
}
partial class defaultGUI : UserControl
{
/// <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.msgTextBox = new System.Windows.Forms.TextBox();
this.intervalTextBox = new System.Windows.Forms.TextBox();
this.timer = new System.Windows.Forms.Timer(this.components);
this.lbl1 = new System.Windows.Forms.Label();
this.lbl2 = new System.Windows.Forms.Label();
this.startButton = new System.Windows.Forms.Button();
this.stopButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// msgTextBox
//
this.msgTextBox.Location = new System.Drawing.Point(62, 8);
this.msgTextBox.Name = "msgTextBox";
this.msgTextBox.Size = new System.Drawing.Size(239, 20);
this.msgTextBox.TabIndex = 0;
//
// intervalTextBox
//
this.intervalTextBox.Location = new System.Drawing.Point(62, 31);
this.intervalTextBox.Name = "intervalTextBox";
this.intervalTextBox.Size = new System.Drawing.Size(239, 20);
this.intervalTextBox.TabIndex = 1;
//
// timer
//
this.timer.Interval = 1000;
//
// lbl1
//
this.lbl1.AutoSize = true;
this.lbl1.Location = new System.Drawing.Point(3, 11);
this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(53, 13);
this.lbl1.TabIndex = 2;
this.lbl1.Text = "Message:";
//
// lbl2
//
this.lbl2.AutoSize = true;
this.lbl2.Location = new System.Drawing.Point(3, 34);
this.lbl2.Name = "lbl2";
this.lbl2.Size = new System.Drawing.Size(45, 13);
this.lbl2.TabIndex = 3;
this.lbl2.Text = "Interval:";
//
// startButton
//
this.startButton.Location = new System.Drawing.Point(6, 57);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(139, 23);
this.startButton.TabIndex = 4;
this.startButton.Text = "Start";
this.startButton.UseVisualStyleBackColor = true;
//
// stopButton
//
this.stopButton.Location = new System.Drawing.Point(162, 57);
this.stopButton.Name = "stopButton";
this.stopButton.Size = new System.Drawing.Size(139, 23);
this.stopButton.TabIndex = 5;
this.stopButton.Text = "Stop";
this.stopButton.UseVisualStyleBackColor = true;
//
// defaultGUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.stopButton);
this.Controls.Add(this.startButton);
this.Controls.Add(this.lbl2);
this.Controls.Add(this.lbl1);
this.Controls.Add(this.intervalTextBox);
this.Controls.Add(this.msgTextBox);
this.Name = "defaultGUI";
this.Size = new System.Drawing.Size(304, 86);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.TextBox msgTextBox;
public System.Windows.Forms.TextBox intervalTextBox;
public System.Windows.Forms.Timer timer;
public System.Windows.Forms.Label lbl1;
public System.Windows.Forms.Label lbl2;
public System.Windows.Forms.Button startButton;
public System.Windows.Forms.Button stopButton;
}
#endregion
public class IniFile
{
public string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
public IniFile(string INIPath)
{
path = INIPath;
}
public void WriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
public string ReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp,
255, this.path);
return temp.ToString();
}
}
}
Minimal one(comments and some enters are removed for file size reducing):
Spoiler:
- Code: Select all
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace MCDzienny.Plugins
{
public class Plgn : Plugin
{
public string path = string.Format(@"{0}\Plugins\Repeater.ini", Application.StartupPath);
public IniFile ini;
public string message = "(Repeater Plugin)Error: Message is not defined.";
public int interval = 10000;
public event EventHandler msgTextBoxChanged;
public event EventHandler intervalTextBoxChanged;
public event EventHandler startButtonEvent;
public event EventHandler stopButtonEvent;
public event EventHandler timerTickEvent;
versionInfoPlugin info = new versionInfoPlugin("Repeater", "A simple text repeater for all your daily messages.(test plugin)", "joppiesaus", "1.1", 2);
defaultGUI mainGui = new defaultGUI();
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 mainGui; }
}
public override string Version
{
get { return info.ver; }
}
public override int VersionNumber
{
get { return info.verNumber; }
}
public override void Initialize()
{
mainGui.msgTextBox.TextChanged += this.HandleMsgStuff;
mainGui.intervalTextBox.TextChanged += this.HandleIntervalStuff;
mainGui.startButton.Click += this.HandleStartButtonStuff;
mainGui.stopButton.Click += this.HandleStopButtonStuff;
mainGui.timer.Tick += this.HandleTimerStuff;
load();
}
private void HandleMsgStuff(object sender, EventArgs e)
{
this.msgTextBoxTextChanged(EventArgs.Empty);
}
private void HandleIntervalStuff(object sender, EventArgs e)
{
intervalTextBoxTextChanged(EventArgs.Empty);
}
private void HandleStartButtonStuff(object sender, EventArgs e)
{
this.startButtonClicked(EventArgs.Empty);
}
private void HandleStopButtonStuff(object sender, EventArgs e)
{
stopButtonClicked(EventArgs.Empty);
}
private void HandleTimerStuff(object sender, EventArgs e)
{
this.timerTick(EventArgs.Empty);
}
protected virtual void msgTextBoxTextChanged(EventArgs e)
{
EventHandler hand = this.msgTextBoxChanged;
if (hand != null)
{
hand(this, e);
}
message = mainGui.msgTextBox.Text;
}
protected virtual void intervalTextBoxTextChanged(EventArgs e)
{
EventHandler hand = this.intervalTextBoxChanged;
if (hand != null)
{
hand(this, e);
}
try
{
interval = Convert.ToInt32(mainGui.intervalTextBox.Text);
}
catch (Exception ex)
{
interval = 10000;
MessageBox.Show("-======ERROR======-" + System.Environment.NewLine + System.Environment.NewLine + ex, "ERROR");
}
}
protected virtual void startButtonClicked(EventArgs e)
{
EventHandler hand = this.startButtonEvent;
if (hand != null)
{
hand(this, e);
}
mainGui.timer.Enabled = true;
}
protected virtual void stopButtonClicked(EventArgs e)
{
EventHandler hand = this.stopButtonEvent;
if (hand != null)
{
hand(this, e);
}
mainGui.timer.Enabled = false;
}
protected virtual void timerTick(EventArgs e)
{
EventHandler hand = this.timerTickEvent;
if (hand != null)
{
hand(this, e);
}
mainGui.timer.Interval = interval;
Player.GlobalMessage(message);
}
public override void Terminate()
{
mainGui.timer.Enabled = false;
save();
}
public void checkPath()
{
if (!File.Exists(path))
{
using (File.Create(path, 1024)) { }
}
}
public void save()
{
checkPath();
ini = new IniFile(path);
ini.WriteValue("Plugin", "Message", mainGui.msgTextBox.Text);
ini.WriteValue("Plugin", "Interval", mainGui.intervalTextBox.Text);
}
public void load()
{
checkPath();
ini = new IniFile(path);
mainGui.msgTextBox.Text = ini.ReadValue("Plugin", "Message");
mainGui.intervalTextBox.Text = ini.ReadValue("Plugin", "Interval");
}
}
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 defaultGUI
{
public defaultGUI()
{
InitializeComponent();
}
}
partial class defaultGUI : UserControl
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.msgTextBox = new System.Windows.Forms.TextBox();
this.intervalTextBox = new System.Windows.Forms.TextBox();
this.timer = new System.Windows.Forms.Timer(this.components);
this.lbl1 = new System.Windows.Forms.Label();
this.lbl2 = new System.Windows.Forms.Label();
this.startButton = new System.Windows.Forms.Button();
this.stopButton = new System.Windows.Forms.Button();
this.SuspendLayout();
this.msgTextBox.Location = new System.Drawing.Point(62, 8);
this.msgTextBox.Name = "msgTextBox";
this.msgTextBox.Size = new System.Drawing.Size(239, 20);
this.msgTextBox.TabIndex = 0;
this.intervalTextBox.Location = new System.Drawing.Point(62, 31);
this.intervalTextBox.Name = "intervalTextBox";
this.intervalTextBox.Size = new System.Drawing.Size(239, 20);
this.intervalTextBox.TabIndex = 1;
this.timer.Interval = 1000;
this.lbl1.AutoSize = true;
this.lbl1.Location = new System.Drawing.Point(3, 11);
this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(53, 13);
this.lbl1.TabIndex = 2;
this.lbl1.Text = "Message:";
this.lbl2.AutoSize = true;
this.lbl2.Location = new System.Drawing.Point(3, 34);
this.lbl2.Name = "lbl2";
this.lbl2.Size = new System.Drawing.Size(45, 13);
this.lbl2.TabIndex = 3;
this.lbl2.Text = "Interval:";
this.startButton.Location = new System.Drawing.Point(6, 57);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(139, 23);
this.startButton.TabIndex = 4;
this.startButton.Text = "Start";
this.startButton.UseVisualStyleBackColor = true;
this.stopButton.Location = new System.Drawing.Point(162, 57);
this.stopButton.Name = "stopButton";
this.stopButton.Size = new System.Drawing.Size(139, 23);
this.stopButton.TabIndex = 5;
this.stopButton.Text = "Stop";
this.stopButton.UseVisualStyleBackColor = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.stopButton);
this.Controls.Add(this.startButton);
this.Controls.Add(this.lbl2);
this.Controls.Add(this.lbl1);
this.Controls.Add(this.intervalTextBox);
this.Controls.Add(this.msgTextBox);
this.Name = "defaultGUI";
this.Size = new System.Drawing.Size(304, 86);
this.ResumeLayout(false);
this.PerformLayout();
}
public System.Windows.Forms.TextBox msgTextBox;
public System.Windows.Forms.TextBox intervalTextBox;
public System.Windows.Forms.Timer timer;
public System.Windows.Forms.Label lbl1;
public System.Windows.Forms.Label lbl2;
public System.Windows.Forms.Button startButton;
public System.Windows.Forms.Button stopButton;
}
public class IniFile
{
public string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
public IniFile(string INIPath)
{
path = INIPath;
}
public void WriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
public string ReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp,
255, this.path);
return temp.ToString();
}
}
}
Have fun with it!
![Uśmiech :)](./images/smilies/icon_e_smile.gif)