From e576ef829db8f3d3dc0222d4b6c0f82e75da3313 Mon Sep 17 00:00:00 2001 From: Maxlego08 Date: Thu, 22 Feb 2024 16:26:43 +0100 Subject: [PATCH] :construction: Add stop command --- src/fr/maxlego08/koth/KothManager.java | 15 ++++++++++ src/fr/maxlego08/koth/ZKoth.java | 19 ++++++++----- src/fr/maxlego08/koth/api/Koth.java | 2 ++ .../koth/command/commands/CommandKoth.java | 1 + .../command/commands/CommandKothStop.java | 28 +++++++++++++++++++ .../maxlego08/koth/zcore/enums/Message.java | 1 + .../koth/zcore/enums/Permission.java | 2 +- src/main/resources/config.yml | 3 +- 8 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 src/fr/maxlego08/koth/command/commands/CommandKothStop.java diff --git a/src/fr/maxlego08/koth/KothManager.java b/src/fr/maxlego08/koth/KothManager.java index 38509d6..f7cec09 100644 --- a/src/fr/maxlego08/koth/KothManager.java +++ b/src/fr/maxlego08/koth/KothManager.java @@ -57,12 +57,15 @@ public class KothManager extends ZUtils implements Savable { @Override public void save(Persist persist) { + this.koths.forEach(Koth::stop); this.selections.values().forEach(Selection::clear); } @Override public void load(Persist persist) { + this.koths.forEach(Koth::stop); + File[] files = this.folder.listFiles((dir, name) -> name.endsWith(".yml")); if (files == null) return; @@ -173,4 +176,16 @@ public class KothManager extends ZUtils implements Savable { Koth koth = optional.get(); koth.spawn(sender, now); } + + public void stopKoth(CommandSender sender, String name) { + + Optional optional = getKoth(name); + if (!optional.isPresent()) { + message(sender, Message.DOESNT_EXIST, "%name%", name); + return; + } + + Koth koth = optional.get(); + koth.stop(sender); + } } diff --git a/src/fr/maxlego08/koth/ZKoth.java b/src/fr/maxlego08/koth/ZKoth.java index eb7f9c1..708217d 100644 --- a/src/fr/maxlego08/koth/ZKoth.java +++ b/src/fr/maxlego08/koth/ZKoth.java @@ -229,13 +229,7 @@ public class ZKoth extends ZUtils implements Koth { } @Override - public void stop(CommandSender sender) { - - if (this.kothStatus != KothStatus.START) { - message(sender, Message.EVENT_DISABLE); - return; - } - + public void stop() { KothStopEvent event = new KothStopEvent(this); event.call(); @@ -259,6 +253,17 @@ public class ZKoth extends ZUtils implements Koth { // this.plugin.getHologram().end(this); } + @Override + public void stop(CommandSender sender) { + + if (this.kothStatus != KothStatus.START) { + message(sender, Message.EVENT_DISABLE); + return; + } + + this.stop(); + } + private void spawn() { this.resetData(); diff --git a/src/fr/maxlego08/koth/api/Koth.java b/src/fr/maxlego08/koth/api/Koth.java index 889189b..596482d 100644 --- a/src/fr/maxlego08/koth/api/Koth.java +++ b/src/fr/maxlego08/koth/api/Koth.java @@ -50,6 +50,8 @@ public interface Koth { void stop(CommandSender sender); + void stop(); + void playerMove(Player player, KothTeam kothTeam); int getCooldownStart(); diff --git a/src/fr/maxlego08/koth/command/commands/CommandKoth.java b/src/fr/maxlego08/koth/command/commands/CommandKoth.java index 8d9f584..d04d23a 100644 --- a/src/fr/maxlego08/koth/command/commands/CommandKoth.java +++ b/src/fr/maxlego08/koth/command/commands/CommandKoth.java @@ -15,6 +15,7 @@ public class CommandKoth extends VCommand { this.addSubCommand(new CommandKothCreate(plugin)); this.addSubCommand(new CommandKothNow(plugin)); this.addSubCommand(new CommandKothSpawn(plugin)); + this.addSubCommand(new CommandKothStop(plugin)); } @Override diff --git a/src/fr/maxlego08/koth/command/commands/CommandKothStop.java b/src/fr/maxlego08/koth/command/commands/CommandKothStop.java new file mode 100644 index 0000000..72002eb --- /dev/null +++ b/src/fr/maxlego08/koth/command/commands/CommandKothStop.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 CommandKothStop extends VCommand { + + public CommandKothStop(KothPlugin plugin) { + super(plugin); + this.setPermission(Permission.ZKOTH_STOP); + this.addSubCommand("stop"); + 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.stopKoth(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 52104af..e51820f 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_STOP("Stop a koth"), DESCRIPTION_AXE("Getting the selection axe"), DESCRIPTION_CREATE("Create new koth"), diff --git a/src/fr/maxlego08/koth/zcore/enums/Permission.java b/src/fr/maxlego08/koth/zcore/enums/Permission.java index 3573677..2a1d49f 100644 --- a/src/fr/maxlego08/koth/zcore/enums/Permission.java +++ b/src/fr/maxlego08/koth/zcore/enums/Permission.java @@ -6,7 +6,7 @@ public enum Permission { ZKOTH_RELOAD, ZKOTH_NOW, ZKOTH_AXE, - ZKOTH_CREATE, ZKOTH_SPAWN; + ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP; private String permission; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index bfc4c41..f44fa0c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,7 +13,8 @@ # /zkoth axe - zkoth.axe - Getting the selection axe # /zkoth create [] [ - zkoth.now - Spawn a koth without cooldown -# /zkoth spawn - zkoth.now - Spawn a koth +# /zkoth spawn - zkoth.spawn - Spawn a koth +# /zkoth stop - zkoth.stop - Stop a koth # # Placeholders: #