TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java

54 lines
1.1 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
2012-03-15 02:12:43 +00:00
import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IWarps;
2011-11-18 17:42:26 +00:00
import org.bukkit.Location;
import org.bukkit.Server;
public class Commandsetwarp extends EssentialsCommand
{
public Commandsetwarp()
{
super("setwarp");
}
@Override
2011-12-01 13:42:39 +00:00
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
2012-10-01 19:28:09 +00:00
2013-02-26 17:07:10 +00:00
if (Util.isInt(args[0]) || args[0].isEmpty())
2012-10-01 19:28:09 +00:00
{
throw new NoSuchFieldException(_("invalidWarpName"));
}
2011-12-01 13:42:39 +00:00
final Location loc = user.getLocation();
final IWarps warps = ess.getWarps();
Location warpLoc = null;
try
{
warpLoc = warps.getWarp(args[0]);
}
2012-03-15 02:12:43 +00:00
catch (Exception ex)
{
}
2012-10-01 23:19:42 +00:00
if (warpLoc == null || user.isAuthorized("essentials.warp.overwrite." + Util.safeString(args[0])))
{
warps.setWarp(args[0], loc);
}
else
{
throw new Exception(_("warpOverwrite"));
}
user.sendMessage(_("warpSet", args[0]));
}
}