2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2024-02-03 21:38:14 +01:00
|
|
|
import net.ess3.api.TranslatableException;
|
2021-01-08 21:20:03 +01:00
|
|
|
import net.essentialsx.api.v2.events.WarpModifyEvent;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
2011-03-19 23:39:51 +01:00
|
|
|
import org.bukkit.Server;
|
|
|
|
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public class Commanddelwarp extends EssentialsCommand {
|
|
|
|
public Commanddelwarp() {
|
|
|
|
super("delwarp");
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
2020-08-11 20:09:22 +02:00
|
|
|
if (args.length == 0) {
|
2015-04-15 06:06:16 +02:00
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2021-01-08 21:20:03 +01:00
|
|
|
//Check if warp exists before calling the event
|
2021-10-24 16:05:10 +02:00
|
|
|
if (ess.getWarps().isWarp(args[0])) {
|
|
|
|
Location location;
|
|
|
|
try {
|
|
|
|
location = ess.getWarps().getWarp(args[0]);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
// World is unloaded/deleted
|
|
|
|
location = null;
|
|
|
|
}
|
2024-02-03 21:38:14 +01:00
|
|
|
final WarpModifyEvent event = new WarpModifyEvent(sender.getUser(), args[0], location, null, WarpModifyEvent.WarpModifyCause.DELETE);
|
2021-01-08 21:20:03 +01:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ess.getWarps().removeWarp(args[0]);
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("deleteWarp", args[0]);
|
2021-01-08 21:20:03 +01:00
|
|
|
} else {
|
2024-02-03 21:38:14 +01:00
|
|
|
throw new TranslatableException("warpNotExist");
|
2021-01-08 21:20:03 +01:00
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2017-06-11 02:17:43 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
return new ArrayList<>(ess.getWarps().getList());
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|