summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java
blob: aa60c91680c5db74be05c442dfc68268a60e7a81 (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
package com.earth2me.essentials.commands;

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


public class Commanddelhome extends EssentialsCommand
{
	public Commanddelhome()
	{
		super("delhome");
	}

	@Override
	public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
	{
		//Allowing both formats /delhome khobbits house | /delhome khobbits:house
		final String[] nameParts = args[0].split(":");
		if (nameParts[0].length() != args[0].length())
		{
			args = nameParts;
		}

		User user = ess.getUser(sender);
		String name;
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		else if (args.length > 1 && (user == null || user.isAuthorized("essentials.delhome.others")))
		{
			user = getPlayer(server, args, 0);
			name = args[1];
		}
		else
		{
			if (user == null)
			{
				throw new NotEnoughArgumentsException();
			}
			name = args[0];
		}
		user.delHome(name.toLowerCase());
		sender.sendMessage(Util.format("deleteHome", name));
	}
}