Core command editer

Core command editer

Postby mariomalachi » 08 Aug 2013, 19:25

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.
User avatar
mariomalachi
 
Posts: 4
Joined: 23 Dec 2012, 12:52

Re: Core command editer

Postby ane200055 » 10 Aug 2013, 20:35

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. :)
Website: http://ane200055.co.vu
The Developer of The XtraIRC IRC Client: http://xtrairc.tk
C# coder.
User avatar
ane200055
 
Posts: 98
Joined: 30 Jun 2013, 09:07
Location: United Kingdom

Re: Core command editer

Postby ismellike » 10 Aug 2013, 21:15

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
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Core command editer

Postby lucasds12 » 11 Aug 2013, 14:49

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.
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.

Re: Core command editer

Postby Breakdown901 » 11 Aug 2013, 14:52

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]."
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: Core command editer

Postby Conor » 11 Aug 2013, 20:47

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.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Core command editer

Postby ane200055 » 15 Aug 2013, 10:45

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.
Website: http://ane200055.co.vu
The Developer of The XtraIRC IRC Client: http://xtrairc.tk
C# coder.
User avatar
ane200055
 
Posts: 98
Joined: 30 Jun 2013, 09:07
Location: United Kingdom

Re: Core command editer

Postby Breakdown901 » 15 Aug 2013, 18:14

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.
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: Core command editer

Postby ane200055 » 15 Aug 2013, 18:38

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.
Website: http://ane200055.co.vu
The Developer of The XtraIRC IRC Client: http://xtrairc.tk
C# coder.
User avatar
ane200055
 
Posts: 98
Joined: 30 Jun 2013, 09:07
Location: United Kingdom


Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 2 guests

cron