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

44 lines
1.4 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
2013-07-14 12:00:03 +00:00
import com.earth2me.essentials.api.IWarps;
2013-06-08 21:31:19 +00:00
import com.earth2me.essentials.utils.NumberUtil;
2013-10-11 02:44:41 +00:00
import com.earth2me.essentials.utils.StringUtil;
import net.ess3.api.InvalidWorldException;
2011-11-18 17:42:26 +00:00
import org.bukkit.Location;
import org.bukkit.Server;
2015-04-15 04:06:16 +00:00
import static com.earth2me.essentials.I18n.tl;
public class Commandsetwarp extends EssentialsCommand {
public Commandsetwarp() {
super("setwarp");
}
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length == 0) {
2015-04-15 04:06:16 +00:00
throw new NotEnoughArgumentsException();
}
if (NumberUtil.isInt(args[0]) || args[0].isEmpty()) {
throw new Exception(tl("invalidWarpName"));
2015-04-15 04:06:16 +00:00
}
final IWarps warps = ess.getWarps();
Location warpLoc = null;
try {
warpLoc = warps.getWarp(args[0]);
2020-10-03 17:46:05 +00:00
} catch (final WarpNotFoundException | InvalidWorldException ignored) {
2015-04-15 04:06:16 +00:00
}
if (warpLoc == null || user.isAuthorized("essentials.warp.overwrite." + StringUtil.safeString(args[0]))) {
warps.setWarp(user, args[0], user.getLocation());
2015-04-15 04:06:16 +00:00
} else {
throw new Exception(tl("warpOverwrite"));
}
user.sendMessage(tl("warpSet", args[0]));
}
}