Page 1 of 1

Core command editer

PostPosted: 08 Aug 2013, 19:25
by mariomalachi
I'm not sure if you can.. but it would be really nice if someone would make a plugin to make it easier to delete or edit core commands. for example, I had a custom mymap command that my friend made that is now replaced with the new core command and I would rather have just the one he made, and get rid of the new mymap and that pesky home command. Thanks.

Re: Core command editer

PostPosted: 10 Aug 2013, 20:35
by ane200055
Not a bad idea, I think you can make commands to remove old core commands, but if there was a Add-on like that it will make things much more easier. :)

Re: Core command editer

PostPosted: 10 Aug 2013, 21:15
by ismellike
You can try giving this command a try.
It has the same mechanics as cmdautoload.
All you have to do is load it in once and then you just put the name of the commands you don't want.

Code: Select all
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");
        }
    }
}


In the text file

remove_name - add_name

So it removes the command and loads in the other command
ex: tp-tp

Re: Core command editer

PostPosted: 11 Aug 2013, 14:49
by lucasds12
I'll introduce this magnificent element to deleting core commands, it simply does what you expect it to do.
Code: Select all
Command.all.Remove(Command.all.Find(" the command");

Credit to ismellike.

Re: Core command editer

PostPosted: 11 Aug 2013, 14:52
by Breakdown901
Also lucas, you can use this similiar piece of code.

Code: Select all
string Command = message;
Command.all.Remove(Command.all.Find(Command)


This way you could do "/deletecommand [command]."

Re: Core command editer

PostPosted: 11 Aug 2013, 20:47
by Conor
Don't forget to avoid errors guys ;)

Example:
Code: Select all
Command cmd = Command.all.Find(message);
if (cmd != null)
{
   Command.all.Remove(cmd);
}
else
{
   Player.SendMessage(p, "Command could not be found.");
}


- Or you can just try { } catch { } as Ismellike did.

Re: Core command editer

PostPosted: 15 Aug 2013, 10:45
by ane200055
Ok, this is what I would do is do this command.
Just change the bit that says CommandInHere to whatever command you would like to remove in the following line.....
Code: Select all
Command.all.Remove(Command.all.Find("CommandInHere"));

The command itself below vvv
Code: Select all
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");
        }
    }
}

[The command is called /delcorecmd]
Once that is done try to use that command you tried to remove to see if it worked.

Also this should work because I tried this on a local server.

Re: Core command editer

PostPosted: 15 Aug 2013, 18:14
by Breakdown901
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.

Re: Core command editer

PostPosted: 15 Aug 2013, 18:38
by ane200055
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.

Well, I tried the one I did and it did work, also I was talking to Mario on his server and he said nothing on here worked (for him) and this is something you would not need more then few times anyway.

This was kind of just a suggestion.