summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java
blob: c180ed7084cd4de24c78e3f9799f3a3c24d4225c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.earth2me.essentials.commands;

import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;


public class Commandtogglejail extends EssentialsCommand
{
	public Commandtogglejail()
	{
		super("togglejail");
	}

	@Override
	public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}

		User p = getPlayer(server, args, 0);

		if (p.isAuthorized("essentials.jail.exempt"))
		{
			sender.sendMessage("§cYou may not jail that person");
			return;
		}

		if (args.length >= 2 && !p.isJailed())
		{
			charge(sender);
			p.setJailed(true);
			p.sendMessage("§7You have been jailed");
			p.setJail(null);
			Essentials.getJail().sendToJail(p, args[1]);
			p.setJail(args[1]);
			long timeDiff = 0;
			if (args.length > 2)
			{
				String time = getFinalArg(args, 2);
				timeDiff = Util.parseDateDiff(time, true);
				p.setJailTimeout(timeDiff);
			}
			sender.sendMessage("§7Player " + p.getName() + " jailed" + (timeDiff > 0 ? " for" + Util.formatDateDiff(timeDiff) : "") + ".");
			return;
		}

		if (args.length == 2 && p.isJailed() && !args[1].equalsIgnoreCase(p.getJail()))
		{
			sender.sendMessage("§cPerson is already in jail " + p.getJail());
			return;
		}

		if (args.length >= 2 && p.isJailed() && !args[1].equalsIgnoreCase(p.getJail()))
		{
			String time = getFinalArg(args, 2);
			long timeDiff = Util.parseDateDiff(time, true);
			p.setJailTimeout(timeDiff);
			sender.sendMessage("Jail time extend to " + Util.formatDateDiff(timeDiff));
			return;
		}

		if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(p.getJail())))
		{
			if (!p.isJailed())
			{
				throw new NotEnoughArgumentsException();
			}
			p.setJailed(false);
			p.setJailTimeout(0);
			p.sendMessage("§7You have been released");
			p.setJail(null);
			p.getTeleport().back();
			sender.sendMessage("§7Player " + p.getName() + " unjailed.");
		}
	}
}