/cmdremove [Command] - Ultimatly removes a command.

/cmdremove [Command] - Ultimatly removes a command.

Postby Leeizazombie » 19 Feb 2014, 17:04

Hello, just decided to make this command for lazy people, or those like myself who has their server(s) hosted by another person, so what this command will do it Delete the Source, unload it, delete the, DLL and remove it from cmdautoload.txt
(Few commands like chat filters require server restart)

Here you go:
Code: Select all
using System;
using System.IO;

namespace MCDzienny
{
    public class CmdCmdRemove : Command
    {
        public override string name { get { return "removecommand"; } }
        public override string shortcut { get { return "cmdremove"; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }

        public override void Use(Player p, string message)
        {
            string text = File.ReadAllText("text\\cmdautoload.txt");
            string command = message;
            string dll = "";
            string source = "";
            string autoload = command + " wasn't in the cmdautoload.txt file.";
            try
            {
                text = text.Replace(command, "");
                File.WriteAllText("text\\cmdautoload.txt", text);
                autoload = "removed " + command + " from cmdautoload.txt";
            }
            catch
            {
                Player.SendMessage(p, "%cError: %fCommand not found in cmdautoload.txt");
            }
           
                if (File.Exists("extra/commands/source/" + "Cmd" + command + ".cs"))
                {
                    File.Delete("extra/commands/source/" + "Cmd" + command + ".cs");
                    source = "Cmd" + command + ".cs";
                }
                else
                {
                    Player.SendMessage(p, "%cError: %fCommand not found in Source Folder");
                }
                try
                {
                    Command.all.Find("cmdunload").Use(null, " " + command);
                }
                catch
                {
                    Player.SendMessage(p, "%cError: %fCould not unload command.");
                }
                if (File.Exists("extra/commands/dll/" + "Cmd" + command + ".dll"))
                {
                    File.Delete("extra/commands/dll/" + "Cmd" + command + ".dll");
                    dll = "Cmd" + command + ".dll";
                }
                else
                {
                    Player.SendMessage(p, "%cError: %fCommand not found in DLL Folder");
                }
           
            Player.SendMessage(p, "%0----------%2Operation complete%0----------");
            Player.SendMessage(p, "%fYou've removed %7" + source + ", " + dll + " %fand %7" + autoload);
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/cmdremoved [command] - Completely remove a command from the server. (Few commands require a restart)");
        }
    }
}


Tell if you have any problems or suggestions! <ok>
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron