Skip to content

Commit 31506b7

Browse files
committed
Added /loop skip command and MANUAL loop type.
1 parent b9dedf2 commit 31506b7

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

common/src/main/java/com/vltno/timeloop/LoopTypes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ public enum LoopTypes implements StringRepresentable {
77
TICKS,
88
TIME_OF_DAY,
99
SLEEP,
10-
DEATH;
10+
DEATH,
11+
MANUAL;
1112

1213
@Override
1314
public @NotNull String getSerializedName() {

common/src/main/java/com/vltno/timeloop/commands/BaseCommands.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public static void register(LiteralArgumentBuilder<CommandSourceStack> parentBui
2121
.executes(BaseCommands::start)
2222
.requires(source -> source.hasPermission(2)));
2323

24+
parentBuilder.then(Commands.literal("skip")
25+
.executes(BaseCommands::skip)
26+
.requires(source -> source.hasPermission(2)));
27+
2428
parentBuilder.then(Commands.literal("stop")
2529
.executes(BaseCommands::stop)
2630
.requires(source -> source.hasPermission(2)));
@@ -46,13 +50,31 @@ private static int start(CommandContext<CommandSourceStack> context) {
4650
TimeLoop.startLoop();
4751

4852
source.sendSuccess(() -> Component.literal("Loop started!"), true);
49-
LoopCommands.LOOP_COMMANDS_LOGGER.info("loop started");
53+
LoopCommands.LOOP_COMMANDS_LOGGER.info("Loop started");
5054
return 1;
5155
}
5256
source.sendFailure(Component.literal("Loop already running!"));
5357
return 0;
5458
}
5559

60+
private static int skip(CommandContext<CommandSourceStack> context) {
61+
CommandSourceStack source = context.getSource();
62+
if (TimeLoop.isLooping) {
63+
if (TimeLoop.serverLevel == null) {
64+
source.sendFailure(Component.literal("Error: Server world not available yet."));
65+
return 0;
66+
}
67+
68+
TimeLoop.runLoopIteration();
69+
70+
source.sendSuccess(() -> Component.literal("Loop skipped!"), true);
71+
LoopCommands.LOOP_COMMANDS_LOGGER.info("Loop skipped");
72+
return 1;
73+
}
74+
source.sendFailure(Component.literal("Loop not running"));
75+
return 0;
76+
}
77+
5678
private static int stop(CommandContext<CommandSourceStack> context) {
5779
CommandSourceStack source = context.getSource();
5880
if (TimeLoop.isLooping) {

common/src/main/java/com/vltno/timeloop/commands/SettingsCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void register(LiteralArgumentBuilder<CommandSourceStack> parentBui
2424
return 1;
2525
})
2626
.then(Commands.argument("loopType", StringArgumentType.word())
27-
.suggests((context, builder) -> SharedSuggestionProvider.suggest(new String[]{"TICKS", "TIME_OF_DAY", "SLEEP", "DEATH"}, builder))
27+
.suggests((context, builder) -> SharedSuggestionProvider.suggest(new String[]{"TICKS", "TIME_OF_DAY", "SLEEP", "DEATH", "MANUAL"}, builder))
2828
.executes(SettingsCommands::setLoopType)));
2929

3030
settingsNode.then(Commands.literal("setLength")
@@ -75,7 +75,8 @@ private static int setLoopType(CommandContext<CommandSourceStack> context) {
7575
TimeLoop.loopBossBar.visible(newLoopType.equals(LoopTypes.TICKS) || newLoopType.equals(LoopTypes.TIME_OF_DAY));
7676
}
7777

78-
source.sendSuccess(() -> Component.literal("Looping type is set to: " + newLoopType), true);
78+
String extra = (newLoopType == LoopTypes.MANUAL) ? ". Use '/loop skip' to advance to the next iteration." : "";
79+
source.sendSuccess(() -> Component.literal("Loop type is set to: " + newLoopType + extra), true);
7980
LoopCommands.LOOP_COMMANDS_LOGGER.info("Loop type set to {}", newLoopType);
8081
return 1;
8182
} catch (IllegalArgumentException e) {

0 commit comments

Comments
 (0)