2011-03-19 22:39:51 +00:00
|
|
|
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;
|
2013-11-07 02:22:32 +00:00
|
|
|
import net.ess3.api.InvalidWorldException;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
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 {
|
2020-08-11 18:09:22 +00:00
|
|
|
if (args.length == 0) {
|
2015-04-15 04:06:16 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumberUtil.isInt(args[0]) || args[0].isEmpty()) {
|
2020-08-11 18:09:22 +00:00
|
|
|
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]))) {
|
2020-08-11 18:09:22 +00:00
|
|
|
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]));
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|