📝 Add delete commands

This commit is contained in:
Maxlego08 2024-02-22 17:00:05 +01:00
parent f440bdf9d4
commit 8762b3c63e
6 changed files with 49 additions and 3 deletions

View File

@ -243,14 +243,13 @@ public class KothManager extends ZUtils implements Savable {
private void buildKothMessage(Player player, Koth koth) { private void buildKothMessage(Player player, Koth koth) {
TextComponent component = buildTextComponent("§f§l» §7" + koth.getName() + " "); TextComponent component = buildTextComponent("§7§l» §f" + koth.getName() + " ");
Cuboid cuboid = koth.getCuboid(); Cuboid cuboid = koth.getCuboid();
Location center = cuboid.getCenter(); Location center = cuboid.getCenter();
String location = center.getWorld().getName() + ", " + center.getBlockX() + ", " + center.getBlockY() + ", " + center.getBlockZ(); String location = center.getWorld().getName() + ", " + center.getBlockX() + ", " + center.getBlockY() + ", " + center.getBlockZ();
setHoverMessage(component, "§7Location: §f" + location); setHoverMessage(component, "§7Location: §f" + location);
setClickAction(component, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth info " + koth.getName());
TextComponent spawn = buildTextComponent("§8(§aSpawn§8)"); TextComponent spawn = buildTextComponent("§8(§aSpawn§8)");
setClickAction(spawn, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth spawn " + koth.getName()); setClickAction(spawn, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth spawn " + koth.getName());
@ -272,4 +271,19 @@ public class KothManager extends ZUtils implements Savable {
} }
public void deleteKoth(CommandSender sender, String name) {
Optional<Koth> optional = getKoth(name);
if (!optional.isPresent()) {
message(sender, Message.DOESNT_EXIST, "%name%", name);
return;
}
Koth koth = optional.get();
koths.remove(koth);
message(sender, Message.DELETE_SUCCESS, "%name%", name);
File file = new File(folder, koth.getFileName() + ".yml");
file.delete();
}
} }

View File

@ -19,6 +19,7 @@ public class CommandKoth extends VCommand {
this.addSubCommand(new CommandKothMove(plugin)); this.addSubCommand(new CommandKothMove(plugin));
this.addSubCommand(new CommandKothVersion(plugin)); this.addSubCommand(new CommandKothVersion(plugin));
this.addSubCommand(new CommandKothList(plugin)); this.addSubCommand(new CommandKothList(plugin));
this.addSubCommand(new CommandKothDelete(plugin));
} }
@Override @Override

View File

@ -0,0 +1,28 @@
package fr.maxlego08.koth.command.commands;
import fr.maxlego08.koth.KothPlugin;
import fr.maxlego08.koth.command.VCommand;
import fr.maxlego08.koth.zcore.enums.Message;
import fr.maxlego08.koth.zcore.enums.Permission;
import fr.maxlego08.koth.zcore.utils.commands.CommandType;
public class CommandKothDelete extends VCommand {
public CommandKothDelete(KothPlugin plugin) {
super(plugin);
this.setPermission(Permission.ZKOTH_DELETE);
this.addSubCommand("spawn");
this.setDescription(Message.DESCRIPTION_SPAWN);
this.addRequireArg("name", (a,b) -> plugin.getKothManager().getNameKoths());
}
@Override
protected CommandType perform(KothPlugin plugin) {
String name = argAsString(0);
this.manager.deleteKoth(sender, name);
return CommandType.SUCCESS;
}
}

View File

@ -46,6 +46,7 @@ public enum Message {
DESCRIPTION_RELOAD("Reload configuration files"), DESCRIPTION_RELOAD("Reload configuration files"),
DESCRIPTION_NOW("Spawn a koth without cooldown"), DESCRIPTION_NOW("Spawn a koth without cooldown"),
DESCRIPTION_SPAWN("Spawn a koth with cooldown"), DESCRIPTION_SPAWN("Spawn a koth with cooldown"),
DESCRIPTION_DELETE("Delete a koth"),
DESCRIPTION_VERSION("Show plugin version"), DESCRIPTION_VERSION("Show plugin version"),
DESCRIPTION_STOP("Stop a koth"), DESCRIPTION_STOP("Stop a koth"),
DESCRIPTION_MOVE("Move a koth"), DESCRIPTION_MOVE("Move a koth"),
@ -129,6 +130,7 @@ public enum Message {
LIST_PLAYER("§fKoths§8: §8(§7Use your mouse)"), LIST_PLAYER("§fKoths§8: §8(§7Use your mouse)"),
LIST_EMPTY("§fKoths§8: §cempty"), LIST_EMPTY("§fKoths§8: §cempty"),
DELETE_SUCCESS("§7You just deleted the koth §f%name%§7."),
; ;

View File

@ -7,7 +7,7 @@ public enum Permission {
ZKOTH_NOW, ZKOTH_NOW,
ZKOTH_AXE, ZKOTH_AXE,
ZKOTH_LIST, ZKOTH_LIST,
ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE; ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE, ZKOTH_DELETE;
private String permission; private String permission;

View File

@ -16,6 +16,7 @@
# /zkoth spawn <koth name> - zkoth.spawn - Spawn a koth # /zkoth spawn <koth name> - zkoth.spawn - Spawn a koth
# /zkoth stop <koth name> - zkoth.stop - Stop a koth # /zkoth stop <koth name> - zkoth.stop - Stop a koth
# /zkoth move <koth name> - zkoth.stop - Move a koth # /zkoth move <koth name> - zkoth.stop - Move a koth
# /zkoth delete <koth name> - zkoth.delete - Delete a koth
# /zkoth version - no permission - Show plugin version # /zkoth version - no permission - Show plugin version
# /zkoth list - zkoth.list - Get koth list # /zkoth list - zkoth.list - Get koth list
# #