/autoload

/autoload

Postby Clowny » 22 Jul 2013, 21:59

I thought this command would be really useful for owners who don't have access to console or to just do it in-game instead of having to go into the files.
Code: Select all
//Based On MCForge Command, Created by Clowny
using System;
using System.IO;
using System.Collections.Generic;
namespace MCDzienny
{
    class CmdAutoload : Command
    {
        public override string name { get { return "autoload"; } }
        public override string shortcut { get { return "al"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }//default rank may be edited, this is the highest rank on my testing server
        public CmdAutoload() { }
 
        public override void Use(Player p, string message)
        {
            List<string> cmdautoload = new List<string>();
            string msg1 = String.Empty;
            string msg2 = String.Empty;
            int number;
            if (message == "")
            {
                Help(p);
                return;
            }
            try
            {
                number = message.Split(' ').Length;
                msg1 = message.Split(' ')[0];
                if (number == 2)
                {
                    msg2 = message.Split(' ')[1];
                }
            }
            catch { }
            if (msg1.ToLower() == "del")
            {
                if (!File.Exists("text/cmdautoload.txt"))
                {
                    Player.SendMessage(p, msg2 + " does not exist!");
                    return;
                }
                bool foundone = false;
                string[] lines = File.ReadAllLines("text/cmdautoload.txt");
                foreach (string line in lines)
                {
                    if (line[0] != ' ')
                    {
                        cmdautoload.Add(line);
                    }
                }
                foreach (string item in cmdautoload)
                {
                    if (item == msg2)
                    {
                        foundone = true;
                    }
                }
                if (foundone == false)
                {
                    Player.SendMessage(p, "Could not find " + msg2 + ".");
                    return;
                }
                cmdautoload.Remove(msg2);
                File.Delete("text/cmdautoload.txt");
                File.WriteAllLines("text/cmdautoload.txt", cmdautoload.ToArray());
                Player.SendMessage(p, msg2 + " has sucessfully been deleted from command autoloads!");
                return;
            }
            if (!Directory.Exists("extra"))
            {
                Player.SendMessage(p, "Custom command not found!");
                return;
            }
            if (!Directory.Exists("extra/commands"))
            {
                Player.SendMessage(p, "Custom command not found!");
                return;
            }
            if (!Directory.Exists("extra/commands/dll"))
            {
                Player.SendMessage(p, "Custom command not found!");
                return;
            }
            if (!File.Exists("extra/commands/dll/Cmd" + msg1 + ".dll"))
            {
                Player.SendMessage(p, "Custom command not found!");
                return;
            }
            if (!File.Exists("text/cmdautoload.txt"))
            {
                File.WriteAllText("text/cmdautoload.txt", msg1);
            }
            else
            {
                File.AppendAllText("text/cmdautoload.txt", Environment.NewLine + msg1);
            }
            Player.SendMessage(p, "Sucessfully added: " + msg1);
            return;
        }
              public override void Help(Player p)
              {
            Player.SendMessage(p, "/cmdautoload [CmdName] - Places the command name in cmdautoload.txt");
            Player.SendMessage(p, "/cmdautoload del [CmdName] - Deletes the command name from cmdautoload.txt");
            Player.SendMessage(p, "Note: The command DLL MUST exist for this to work!");
       }
    }
}
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron