Add skip phase command to bypass game phases
Introduced a new `/ctf skipphase` command allowing admins to skip the current game phase. Updated relevant classes to handle phase-skipping logic and ensure proper game state transitions. Added corresponding message configuration and subcommand registration.
This commit is contained in:
parent
aad63f174e
commit
9563e9641f
|
|
@ -35,6 +35,7 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
|
||||
subCommands = Arrays.asList(
|
||||
new ChangeTeam(gameManager),
|
||||
new SkipPhase(gameManager),
|
||||
new Start(gameManager, flag),
|
||||
new CreateTeam(main, gameManager),
|
||||
new SelectClass(gameManager, worldBorderApi),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.alttd.ctf.commands.subcommands;
|
||||
|
||||
import com.alttd.ctf.commands.SubCommand;
|
||||
import com.alttd.ctf.config.Messages;
|
||||
import com.alttd.ctf.game.GameManager;
|
||||
import com.alttd.ctf.team.Team;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class SkipPhase extends SubCommand {
|
||||
|
||||
private final GameManager gameManager;
|
||||
|
||||
@Override
|
||||
public int onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!gameManager.skipPhase()) {
|
||||
commandSender.sendRichMessage("<red>The phase was not skipped because there is no running game or there is no next phase</red>");
|
||||
return 0;
|
||||
}
|
||||
commandSender.sendRichMessage("<green>The current phase was skipped!</green>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "skipphase";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Messages.HELP.SKIP_PHASE;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String CREATE_TEAM = "<green>Create a team: <gold>/ctf createteam <team_name> <hex_color></gold></green>";
|
||||
public static String START = "<green>Start a new game: <gold>/ctf start <time_in_minutes></gold></green>";
|
||||
public static String SELECT_CLASS = "<green>Open class selection: <gold>/ctf selectclass</gold></green>";
|
||||
public static String SKIP_PHASE = "<green>Skip the current phase: <gold>/ctf skipphase</gold></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -37,6 +38,7 @@ public class Messages extends AbstractConfig {
|
|||
CREATE_TEAM = config.getString(prefix, "create-team", CREATE_TEAM);
|
||||
START = config.getString(prefix, "start", START);
|
||||
SELECT_CLASS = config.getString(prefix, "select-class", SELECT_CLASS);
|
||||
SKIP_PHASE = config.getString(prefix, "skip-phase", SKIP_PHASE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,4 +99,11 @@ public class GameManager {
|
|||
.max()
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
public boolean skipPhase() {
|
||||
if (runningGame == null) {
|
||||
return false;
|
||||
}
|
||||
return runningGame.skipCurrentPhase();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,13 +87,14 @@ public class RunningGame implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
public void skipCurrentPhase() {
|
||||
public boolean skipCurrentPhase() {
|
||||
GamePhase nextPhase = (currentPhase.ordinal() + 1 < GamePhase.values().length) ? GamePhase.values()[currentPhase.ordinal() + 1] : null;
|
||||
if (nextPhase == null) {
|
||||
log.warn("Tried to skip phase {} but there is no next phase", currentPhase);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
nextPhaseActions(currentPhase, nextPhase);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void end() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
#Sat Feb 08 23:31:55 CET 2025
|
||||
buildNumber=33
|
||||
#Tue Feb 11 21:41:29 CET 2025
|
||||
buildNumber=37
|
||||
version=0.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user