🚧 Add stop command

This commit is contained in:
Maxlego08 2024-02-22 16:26:43 +01:00
parent b074d81b9d
commit e576ef829d
8 changed files with 62 additions and 9 deletions

View File

@ -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<Koth> optional = getKoth(name);
if (!optional.isPresent()) {
message(sender, Message.DOESNT_EXIST, "%name%", name);
return;
}
Koth koth = optional.get();
koth.stop(sender);
}
}

View File

@ -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();

View File

@ -50,6 +50,8 @@ public interface Koth {
void stop(CommandSender sender);
void stop();
void playerMove(Player player, KothTeam kothTeam);
int getCooldownStart();

View File

@ -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

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 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;
}
}

View File

@ -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"),

View File

@ -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;

View File

@ -13,7 +13,8 @@
# /zkoth axe - zkoth.axe - Getting the selection axe
# /zkoth create <koth name> [<koth type>] [<capture/score] - zkoth.create - Create koth
# /zkoth now <koth name> - zkoth.now - Spawn a koth without cooldown
# /zkoth spawn <koth name> - zkoth.now - Spawn a koth
# /zkoth spawn <koth name> - zkoth.spawn - Spawn a koth
# /zkoth stop <koth name> - zkoth.stop - Stop a koth
#
# Placeholders:
#