Add a flag to allow objective modes to be advanced (#59)

* Add a flag to allow objective modes to be advanced

* Fix constants and modify the messages
This commit is contained in:
Potato 2018-01-04 14:52:58 +08:00 committed by cswhite2000
parent 33156debf6
commit e3cd39ad39
4 changed files with 27 additions and 4 deletions

View File

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

View File

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

View File

@ -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<Pair<ObjectiveMode, Duration>> 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));
}
}

View File

@ -92,6 +92,14 @@ public class ObjectiveModeManager implements Listener {
return modes.keySet().stream().collect(Collectors.mappingTo(this::timeUntilMode));
}
public void advance(ObjectiveMode mode) {
Set<ObjectiveMode> 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()));