Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safeguard to cycle command #1439

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions core/src/main/java/tc/oc/pgm/command/CycleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ public void cycle(
MapOrder mapOrder,
@Argument("duration") Duration duration,
@Argument("map") @FlagYielding MapInfo map,
@Flag(value = "force", aliases = "f") boolean force) {
if (match.isRunning() && !force) {
throw exception("admin.matchRunning.cycle");
@Flag(value = "force", aliases = "f") boolean force,
@Flag(value = "override") boolean override) {
if (match.isRunning()) {
if (!force) throw exception("admin.matchRunning.cycle");
if (needsOverride(match) && !override) {
throw exception("admin.matchRunning.cycle.override");
}
}

if (map != null && mapOrder.getNextMap() != map) {
Expand All @@ -56,7 +60,12 @@ public void recycle(
Match match,
MapOrder mapOrder,
@Argument("duration") Duration duration,
@Flag(value = "force", aliases = "f") boolean force) {
cycle(sender, match, mapOrder, duration, match.getMap(), force);
@Flag(value = "force", aliases = "f") boolean force,
@Flag(value = "override") boolean override) {
cycle(sender, match, mapOrder, duration, match.getMap(), force, override);
}

private boolean needsOverride(Match match) {
return match.getPlayers().size() >= 8 && match.getDuration().toMinutes() >= 5;
}
}
2 changes: 2 additions & 0 deletions util/src/main/i18n/templates/match.properties
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ admin.matchRunning.restart = You may not restart during a match. Use -f to overr

admin.matchRunning.cycle = You may not cycle during a match. Use -f to override.

admin.matchRunning.cycle.override = The match is running for long, are you sure about this? Use --override.

admin.queueRestart.restartingNow = Server will restart now.

admin.queueRestart.restartQueued = Server will restart at the next available opportunity.
Expand Down