Skip to content

Commit

Permalink
Add safeguard to cycle command
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <pabloherrerapalacio@gmail.com>
  • Loading branch information
Pablete1234 committed Nov 25, 2024
1 parent 782f675 commit 74905b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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

0 comments on commit 74905b3

Please sign in to comment.