diff --git a/src/fr/maxlego08/koth/KothManager.java b/src/fr/maxlego08/koth/KothManager.java index 78ea324..1cc3824 100644 --- a/src/fr/maxlego08/koth/KothManager.java +++ b/src/fr/maxlego08/koth/KothManager.java @@ -243,14 +243,13 @@ public class KothManager extends ZUtils implements Savable { 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(); Location center = cuboid.getCenter(); String location = center.getWorld().getName() + ", " + center.getBlockX() + ", " + center.getBlockY() + ", " + center.getBlockZ(); setHoverMessage(component, "§7Location: §f" + location); - setClickAction(component, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth info " + koth.getName()); TextComponent spawn = buildTextComponent("§8(§aSpawn§8)"); 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 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(); + } } diff --git a/src/fr/maxlego08/koth/command/commands/CommandKoth.java b/src/fr/maxlego08/koth/command/commands/CommandKoth.java index 4d6f6b2..4b7e7dc 100644 --- a/src/fr/maxlego08/koth/command/commands/CommandKoth.java +++ b/src/fr/maxlego08/koth/command/commands/CommandKoth.java @@ -19,6 +19,7 @@ public class CommandKoth extends VCommand { this.addSubCommand(new CommandKothMove(plugin)); this.addSubCommand(new CommandKothVersion(plugin)); this.addSubCommand(new CommandKothList(plugin)); + this.addSubCommand(new CommandKothDelete(plugin)); } @Override diff --git a/src/fr/maxlego08/koth/command/commands/CommandKothDelete.java b/src/fr/maxlego08/koth/command/commands/CommandKothDelete.java new file mode 100644 index 0000000..9499481 --- /dev/null +++ b/src/fr/maxlego08/koth/command/commands/CommandKothDelete.java @@ -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; + } + +} diff --git a/src/fr/maxlego08/koth/zcore/enums/Message.java b/src/fr/maxlego08/koth/zcore/enums/Message.java index caa7a70..a249f60 100644 --- a/src/fr/maxlego08/koth/zcore/enums/Message.java +++ b/src/fr/maxlego08/koth/zcore/enums/Message.java @@ -46,6 +46,7 @@ public enum Message { DESCRIPTION_RELOAD("Reload configuration files"), DESCRIPTION_NOW("Spawn a koth without cooldown"), DESCRIPTION_SPAWN("Spawn a koth with cooldown"), + DESCRIPTION_DELETE("Delete a koth"), DESCRIPTION_VERSION("Show plugin version"), DESCRIPTION_STOP("Stop a koth"), DESCRIPTION_MOVE("Move a koth"), @@ -129,6 +130,7 @@ public enum Message { LIST_PLAYER("§fKoths§8: §8(§7Use your mouse)"), LIST_EMPTY("§fKoths§8: §cempty"), + DELETE_SUCCESS("§7You just deleted the koth §f%name%§7."), ; diff --git a/src/fr/maxlego08/koth/zcore/enums/Permission.java b/src/fr/maxlego08/koth/zcore/enums/Permission.java index 148a578..21c88db 100644 --- a/src/fr/maxlego08/koth/zcore/enums/Permission.java +++ b/src/fr/maxlego08/koth/zcore/enums/Permission.java @@ -7,7 +7,7 @@ public enum Permission { ZKOTH_NOW, ZKOTH_AXE, ZKOTH_LIST, - ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE; + ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE, ZKOTH_DELETE; private String permission; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6cccba9..370c8ff 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -16,6 +16,7 @@ # /zkoth spawn - zkoth.spawn - Spawn a koth # /zkoth stop - zkoth.stop - Stop a koth # /zkoth move - zkoth.stop - Move a koth +# /zkoth delete - zkoth.delete - Delete a koth # /zkoth version - no permission - Show plugin version # /zkoth list - zkoth.list - Get koth list #