forked from chipmunkmc/chipmunkbot
Improve looping support
This commit is contained in:
parent
0e195c2299
commit
eb122b21e6
2 changed files with 54 additions and 0 deletions
|
@ -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<CommandSource> 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<CommandSource> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue