/DownloadCommand V1.1

/DownloadCommand V1.1

Postby Leeizazombie » 17 Dec 2013, 22:29

*Update - It now adds the command to the cmdautoload.txt so that you don't have to /cmdload them after every restart.
I hope to update this more where it also auto compiles and loads itself, along with options to delete and maybe rename the commands, just need some time, tell me what you think! ;)

Code: Select all
using System;
using System.IO;
using System.Net;
namespace MCDzienny
{
    public class CmdDownloadCommand : Command
    {
        public override string name { get { return "downloadcommand"; } }
        public override string shortcut { get { return "dlc"; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
        public override void Use(Player p, string message)
        {
            string[] a = message.Split(' ');
            if (a.Length != 2)
            {
                Help(p);
                return;
            }
            string name = "Cmd" + a[0] + ".cs"; // CmdTestCommand.cs
            string cmdname = a[0];              // TestCommand (for cmdautoload).
            try
            {

                using (WebClient web = new WebClient())
                {
                    if (a[0].Substring(0, 4) != "http")
                    {
                        message = "http://" + a[1];
                    }


                    if (System.IO.File.Exists("extra/commands/source/" + name))
                    {
                        Player.SendMessage(p, "You already have a command with that name, please choose another name.");
                        return;
                    }
                    Player.SendMessage(p, "Downloading file from: &f" + a[0] + Server.DefaultColor + ", please wait.");

                    web.DownloadFile(a[1], "extra/commands/source/" + name);
                }
                Player.SendMessage(p, "Download complete. Command name :%3" + name);
                File.AppendAllText("text/cmdautoload.txt", string.Format("{0}{1}", cmdname, Environment.NewLine));

            }
            catch
            {
                Player.SendMessage(p, "%cDownload failed.");
            }
        }

        public override void Help(Player p)
        {
            Player.SendMessage(p, "/DownloadCommand (name for command) (URl)- Dowload Command.");
        }
    }
}

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