/tempjail

/tempjail

Postby ane200055 » 25 Aug 2013, 20:22

I don't know if this command has been made for MCDzienny before but I made it because I thought it would be useful.
/tempjail PlayerName Seconds - Jails a player for the amount of seconds given, maximum seconds is 120..
Shortcut: /tj
Code: Select all
//Made by ane200055
//Version v0.1
using System;
using System.Threading;
namespace MCDzienny
{
    public class CmdTempjail : Command
    {
      public override string name { get { return "tempjail"; } }
        public override string shortcut { get { return "tj"; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }

        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p);
                return;
            }


            if (p == null)
            {
                Player.SendMessage(p, "This command can only be used in-game, use /jail PlayerName instead.");
                return;
            }


            var split = message.Split(' ');
            Player who = Player.Find(split[0]);
            if (who == null)
            {
                Player.SendMessage(p, "Couldn't find player.");
                return;
            }


            if (p != null && who.group.Permission > p.group.Permission)
            {
                Player.SendMessage(p, "You cannot use this command someone ranked higher than you.");
                return;
            }
            if (p == who)
            {
                Player.SendMessage(p, "You cannot use this command on yourself.");
                return;
            }
            Command.all.Find("jail").Use(p, who.name);


            int time = 120;
            try
            {
                time = Convert.ToInt32(message.Split(' ')[1]);
            }
            catch
            {
                Player.SendMessage(p, "Invalid time given, the maximum amount of time is 120 seconds.");
            }


            Player.GlobalMessage(who.color + who.name + Server.DefaultColor + " has been %8jailed " + Server.DefaultColor + "for " + time + " seconds.");


            Thread.Sleep(time * 1000);


            Command.all.Find("jail").Use(p, who.name);
        }


        public override void Help(Player p)
        {
            Player.SendMessage(p, "%e/tempjail %bPlayerName Seconds %e- Jails a player for the amount seconds given.");
         Player.SendMessage(p, "%eThis also works by doing /tj %bPlayerName%e.");
        }
    }
}
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: /tempjail

Postby Warren1001 » 26 Aug 2013, 02:05

What this does is it makes the player wait the time selected and then it jails them and leaves it that way.
Put a jail command before the thread.sleep as well.
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /tempjail

Postby ane200055 » 26 Aug 2013, 09:25

Warren1001 wrote:What this does is it makes the player wait the time selected and then it jails them and leaves it that way.
Put a jail command before the thread.sleep as well.

Warren, look at the code more close, there is a jail command before Thread.Sleep and I tried this command on my local server and it worked.
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: /tempjail

Postby joppiesaus » 26 Aug 2013, 13:55

Nice command!
Defenetly usefull!
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: /tempjail

Postby Warren1001 » 27 Aug 2013, 03:30

Okay, that's still an error. Putting it there can cause someone to jail someone even if you dont have the right amount of seconds.
I can type /tempjail [player] rjdksfh and it will jail them and it will keep them jailed unless you do it again.
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /tempjail

Postby Conor » 28 Aug 2013, 18:32

Warren1001 wrote:Okay, that's still an error. Putting it there can cause someone to jail someone even if you dont have the right amount of seconds.
I can type /tempjail [player] rjdksfh and it will jail them and it will keep them jailed unless you do it again.


It isn't an error, but it's easily avoidable, he forgot to add the 'return' keyword in the catch statement.

Also, it will eventually free them for jail, after 120 seconds; you don't have to use the command again.

@ane200055, the int.TryParse method could save you some time and will make it less likely that you make this mistake. Also, you haven't checked if the number is greater than 120, or a negative number. Here is an example of how you could lay it out to fix it up.

Code: Select all
    int time = 0;
    if (!int.TryParse(message.Split(' ')[1], out time) || int.Parse(message.Split(' ')[1] > 120 || int.Parse(message.Split(' ')[1] < 1)
    {
         Player.SendMessage(p, "Invalid time given, the maximum amount of time is 120 seconds.");
         return;
    }

    Thread.Sleep(time * 1000);
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /tempjail

Postby Warren1001 » 29 Aug 2013, 01:47

Ah, I see. I always think of return; stopping the code. xD
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /tempjail

Postby ane200055 » 29 Aug 2013, 12:16

Okay guys, I might try and update it at some point. :)
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 Custom Commands

Who is online

Users browsing this forum: No registered users and 3 guests

cron