summaryrefslogtreecommitdiffstats
path: root/Essentials/src/net/ess3/commands/Commandsetwarp.java
blob: 401aa8ca9e49afefc2f671b03df53f827a5f9a9f (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
package net.ess3.commands;

import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.api.IWarps;
import net.ess3.permissions.Permissions;
import net.ess3.utils.Util;
import org.bukkit.Location;


public class Commandsetwarp extends EssentialsCommand
{
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}

		if (Util.isInt(args[0]))
		{
			throw new NoSuchFieldException(_("invalidWarpName"));
		}

		final Location loc = user.getPlayer().getLocation();
		final IWarps warps = ess.getWarps();
		Location warpLoc = null;

		try
		{
			warpLoc = warps.getWarp(args[0]);
		}
		catch (WarpNotFoundException ex)
		{
		}

		if (warpLoc == null || Permissions.WARP_OVERWRITE.isAuthorized(user, args[0]))

		{
			warps.setWarp(args[0], loc);
		}
		else
		{
			throw new Exception(_("warpOverwrite"));
		}

		user.sendMessage(_("warpSet", args[0]));
	}
}