using System.IO;
namespace MCDzienny
{
public class CmdAutoremove : Command
{
const string path = "text/autoremove.txt";
public override string name { get { return "autoremove"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return ""; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
const string textContent = "*To add commands to be removed, just add a new line with its command name\r\n*This command will automatically be added to your cmdautoload textfile\r\n*Do /help autoremove for more options\r\n*Command example: ban-dishonor";
public override void Init()
{
if (!File.Exists(path))
{
File.WriteAllText(path, textContent);
string @string = File.ReadAllText("text/cmdautoload.txt");
File.WriteAllText("text/cmdautoload.txt", "autoremove\r\n" + @string);
}
else{
Remove();
Reload();
}
}
public void Remove()
{
using (var sr = new StreamReader(path))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line[0] == '*')
continue;
try
{
Command.all.Remove(Command.all.Find(line.Split('-')[0]));
}
catch { }
}
}
}
public void Reload()
{
using (var sr = new StreamReader(path))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line[0] == '*')
continue;
if (line.Contains("-"))
Command.all.Find("cmdload").Use(null, line.Split('-')[1]);
}
}
}
public override void Use(Player p, string message)
{
switch (message.ToLower())
{
case "remove":
Remove();
Player.SendMessage(p, "Removed");
break;
case "reload":
Reload();
Player.SendMessage(p, "Reloaded");
break;
default:
Help(p);
break;
}
}
public override void Help(Player p)
{
Player.SendMessage(p, "/autoremove remove/reload -- removes/reloads every command in the autoremove file");
}
}
}
Command.all.Remove(Command.all.Find(" the command");
string Command = message;
Command.all.Remove(Command.all.Find(Command)
Command cmd = Command.all.Find(message);
if (cmd != null)
{
Command.all.Remove(cmd);
}
else
{
Player.SendMessage(p, "Command could not be found.");
}
Command.all.Remove(Command.all.Find("CommandInHere"));
using System;
namespace MCDzienny
{
public class CmdDelcorecmd : Command
{
public override string name { get { return "delcorecmd"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return ""; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } }
public override bool ConsoleAccess { get { return false; } }
public override void Init()
{
Command.all.Remove(Command.all.Find("CommandInHere"));
}
public override void Use(Player p, string message)
{
}
public override void Help(Player p)
{
Player.SendMessage(p, "/delcorecmd CommandName - Removes the command you put in the CmdDelcorecmd.cs file");
}
}
}
Breakdown901 wrote:Ane, why not incorporate both pieces of code me and Conor provided? That way, you dont have to do it manually as you can just do /delcorecommand [command], and with Conor's bit of code it will be error proof.
Users browsing this forum: No registered users and 3 guests