diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java index dcd4ab9..72f8d53 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java @@ -7,6 +7,8 @@ import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal; import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument; import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; +import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; @@ -35,6 +37,15 @@ public class MusicCommand extends Command { .then(literal("stop").executes(this::stop)) .then(literal("pause").executes(this::pause)) .then(literal("list").executes(this::list)) + + .then( + literal("loop") + .executes(this::toggleLoop) + .then( + argument("count", integer()) + .executes(this::loop) + ) + ) ); } @@ -90,4 +101,35 @@ public class MusicCommand extends Command { return 1; } + + public int toggleLoop (CommandContext context) throws CommandSyntaxException { + final CommandSource source = context.getSource(); + final SongPlayer songPlayer = source.client().songPlayer(); + final Song currentSong = songPlayer.currentSong(); + + if (currentSong == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create(); + + currentSong.looping = !currentSong.looping; + + source.sendOutput(Component.translatable(currentSong.looping ? "Enabled looping" : "Disabled looping")); + + return 1; + } + + + public int loop (CommandContext context) throws CommandSyntaxException { + final CommandSource source = context.getSource(); + final SongPlayer songPlayer = source.client().songPlayer(); + final Song currentSong = songPlayer.currentSong(); + final int count = getInteger(context, "count"); + + if (currentSong == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create(); + + currentSong.looping = true; + currentSong.loopCount = count; + + source.sendOutput(Component.translatable("Enabled looping for %s times", Component.text(count))); + + return 1; + } } diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java index c728b8a..66d1ee2 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java @@ -110,6 +110,18 @@ public class SongPlayer extends SessionAdapter { .append(Component.translatable("Paused", NamedTextColor.DARK_GREEN)); } + if (currentSong.looping) { + if (currentSong.loopCount > 0) { + return component + .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) + .append(Component.translatable("Looping (%s/%s)", Component.text(currentSong.currentLoop), Component.text(currentSong.loopCount)).color(NamedTextColor.DARK_GREEN)); + } + + return component + .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) + .append(Component.translatable("Looping", NamedTextColor.DARK_GREEN)); + } + return component; }