diff --git a/Commons/core/src/main/i18n/templates/pgm/PGMErrors.properties b/Commons/core/src/main/i18n/templates/pgm/PGMErrors.properties index d290853..b906a0e 100644 --- a/Commons/core/src/main/i18n/templates/pgm/PGMErrors.properties +++ b/Commons/core/src/main/i18n/templates/pgm/PGMErrors.properties @@ -23,6 +23,8 @@ command.class.restricted = The {0} class is restricted command.class.stickyClass = You may not change classes because your current class is sticky. command.class.notEnabled = Classes are not enabled on this map. +command.modes.advance.matchNotStarted = Objective modes may not be advanced before the match starts. + command.gameplay.myteam.notOnTeam = You are not on a team. command.gameplay.leave.alreadyOnObservers = You are already on the observing team. command.gameplay.leave.leaveDenied = You are not allowed to observe this match diff --git a/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties b/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties index 83723d6..c8d2578 100644 --- a/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties +++ b/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties @@ -45,6 +45,8 @@ command.map.update.backupFailed = Failed to backup regions # {0} = file name command.map.update.deleteFailed = Failed to delete {0} +command.modes.advanced = Objective mode advanced to {0}. + # {0} = rotation name command.rotation.set.success = Current rotation set to {0} diff --git a/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeCommands.java b/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeCommands.java index 1782149..57ae083 100644 --- a/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeCommands.java +++ b/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeCommands.java @@ -15,17 +15,21 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TranslatableComponent; import org.bukkit.command.CommandSender; +import org.bukkit.permissions.Permission; import tc.oc.commons.bukkit.chat.Audiences; import tc.oc.commons.bukkit.chat.HeaderComponent; import tc.oc.commons.core.chat.Audience; import tc.oc.commons.core.chat.Component; import tc.oc.commons.core.commands.Commands; import tc.oc.commons.core.commands.NestedCommands; +import tc.oc.commons.core.commands.TranslatableCommandException; import tc.oc.commons.core.formatting.PeriodFormats; import tc.oc.commons.core.util.Pair; +import tc.oc.pgm.commands.CommandUtils; @Singleton public class ObjectiveModeCommands implements NestedCommands { + public static final String ADVANCE_PERMISSION = "pgm.modes.advance"; @Singleton public static class Parent implements Commands { @@ -69,17 +73,24 @@ public class ObjectiveModeCommands implements NestedCommands { @Command( aliases = "next", - desc = "Shows information about the next mode" + flags = "f", + desc = "Shows information about the next mode, or advance to the next mode with -f" ) public void next(CommandContext args, CommandSender sender) throws CommandException { final ObjectiveModeManager manager = this.manager.get(); final Audience audience = audiences.get(sender); final Optional> next = manager.nextMode(); - if(next.isPresent()) { - audience.sendMessage(formatMode(next.get().first, next.get().second)); + if(!next.isPresent()) sendNoModes(audience); + + if(args.hasFlag('f') && sender.hasPermission(ADVANCE_PERMISSION)) { + if(!CommandUtils.getMatch(sender).hasStarted()) { + throw new TranslatableCommandException("command.modes.advance.matchNotStarted"); + } + manager.advance(next.get().first); + audience.sendMessage(new Component(ChatColor.GREEN).translate("command.modes.advanced", new Component(manager.name(next.get().first)).bold(true))); } else { - sendNoModes(audience); + audience.sendMessage(formatMode(next.get().first, next.get().second)); } } diff --git a/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeManager.java b/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeManager.java index 017a5a5..920d165 100644 --- a/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeManager.java +++ b/PGM/src/main/java/tc/oc/pgm/modes/ObjectiveModeManager.java @@ -92,6 +92,14 @@ public class ObjectiveModeManager implements Listener { return modes.keySet().stream().collect(Collectors.mappingTo(this::timeUntilMode)); } + public void advance(ObjectiveMode mode) { + Set currentModes = modes().keySet(); + if(currentModes.contains(mode)) { + goals.forEach(goal -> goal.replaceBlocks(mode.material())); + countdowns.getAll(ModeChangeCountdown.class).stream().findFirst().ifPresent(countdowns::cancel); + } + } + @EventHandler private void start(MatchBeginEvent event) { modes.forEach((mode, countdown) -> countdowns.start(countdown, mode.after()));