forked from ChomeNS/chomens-bot-java
Loop enum
This commit is contained in:
parent
105802ef48
commit
cdc4ab05e7
5 changed files with 21 additions and 68 deletions
|
@ -4,6 +4,7 @@ import me.chayapak1.chomens_bot.Bot;
|
|||
import me.chayapak1.chomens_bot.command.Command;
|
||||
import me.chayapak1.chomens_bot.command.CommandContext;
|
||||
import me.chayapak1.chomens_bot.plugins.MusicPlayerPlugin;
|
||||
import me.chayapak1.chomens_bot.song.Loop;
|
||||
import me.chayapak1.chomens_bot.song.Song;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
|
@ -115,10 +116,10 @@ public class MusicCommand implements Command {
|
|||
public Component loop (CommandContext context, String[] args) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
int loop;
|
||||
Loop loop;
|
||||
switch (args[1]) {
|
||||
case "off" -> {
|
||||
loop = 0;
|
||||
loop = Loop.OFF;
|
||||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("Looping is now "))
|
||||
|
@ -126,7 +127,7 @@ public class MusicCommand implements Command {
|
|||
);
|
||||
}
|
||||
case "current" -> {
|
||||
loop = 1;
|
||||
loop = Loop.CURRENT;
|
||||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("Now looping "))
|
||||
|
@ -134,7 +135,7 @@ public class MusicCommand implements Command {
|
|||
);
|
||||
}
|
||||
case "all" -> {
|
||||
loop = 2;
|
||||
loop = Loop.ALL;
|
||||
context.sendOutput(Component.text("Now looping every song"));
|
||||
}
|
||||
default -> {
|
||||
|
|
|
@ -5,10 +5,7 @@ import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.song.Note;
|
||||
import me.chayapak1.chomens_bot.song.Song;
|
||||
import me.chayapak1.chomens_bot.song.SongLoaderException;
|
||||
import me.chayapak1.chomens_bot.song.SongLoaderThread;
|
||||
import me.chayapak1.chomens_bot.song.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
@ -37,7 +34,7 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
@Getter @Setter private Song currentSong;
|
||||
@Getter @Setter private LinkedList<Song> songQueue = new LinkedList<>();
|
||||
@Getter @Setter private SongLoaderThread loaderThread;
|
||||
@Getter @Setter private int loop = 0;
|
||||
@Getter @Setter private Loop loop = Loop.OFF;
|
||||
private int ticksUntilPausedBossbar = 20;
|
||||
private final String bossbarName = "chomens_bot:music"; // maybe make this in the config?
|
||||
|
||||
|
@ -126,11 +123,11 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
removeBossbar();
|
||||
bot.chat().tellraw(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
|
||||
|
||||
if (loop == 1) {
|
||||
if (loop == Loop.CURRENT) {
|
||||
currentSong.setTime(0);
|
||||
return;
|
||||
}
|
||||
if (loop == 2) {
|
||||
if (loop == Loop.ALL) {
|
||||
skip();
|
||||
return;
|
||||
}
|
||||
|
@ -158,7 +155,7 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
}
|
||||
|
||||
public void skip () {
|
||||
if (loop == 2) {
|
||||
if (loop == Loop.ALL) {
|
||||
songQueue.add(songQueue.remove()); // bot.music.queue.push(bot.music.queue.shift()) in js
|
||||
} else {
|
||||
songQueue.remove();
|
||||
|
@ -196,10 +193,10 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
.append(Component.text("Paused", NamedTextColor.LIGHT_PURPLE));
|
||||
}
|
||||
|
||||
if (loop > 0) {
|
||||
if (loop != Loop.OFF) {
|
||||
return component
|
||||
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
|
||||
.append(Component.translatable("Looping " + ((loop == 1) ? "current" : "all"), NamedTextColor.LIGHT_PURPLE));
|
||||
.append(Component.translatable("Looping " + ((loop == Loop.CURRENT) ? "current" : "all"), NamedTextColor.LIGHT_PURPLE));
|
||||
}
|
||||
|
||||
return component;
|
||||
|
|
7
src/main/java/me/chayapak1/chomens_bot/song/Loop.java
Normal file
7
src/main/java/me/chayapak1/chomens_bot/song/Loop.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package me.chayapak1.chomens_bot.song;
|
||||
|
||||
public enum Loop {
|
||||
OFF,
|
||||
CURRENT,
|
||||
ALL
|
||||
}
|
|
@ -152,7 +152,6 @@ public class NBSConverter {
|
|||
|
||||
Song song = new Song(songName.trim().length() > 0 ? songName : fileName, bot);
|
||||
if (loop > 0) {
|
||||
song.looping = 1;
|
||||
song.loopPosition = getMilliTime(loopStartTick, tempo);
|
||||
// song.loopCount = maxLoopCount;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ public class Song {
|
|||
public ArrayList<Note> notes = new ArrayList<>();
|
||||
public Component name;
|
||||
public int position = 0; // Current note index
|
||||
public int looping = 0; // 0 for no looping, 1 for current loop, 2 for all loops
|
||||
public boolean paused = true;
|
||||
public long startTime = 0; // Start time in millis since unix epoch
|
||||
public long length = 0; // Milliseconds in the song
|
||||
|
@ -65,14 +64,11 @@ public class Song {
|
|||
|
||||
public void setTime (long t) {
|
||||
time = t;
|
||||
// System.out.println("time is " + time);
|
||||
startTime = System.currentTimeMillis() - time;
|
||||
// System.out.println("start time is " + startTime);
|
||||
position = 0;
|
||||
while (position < notes.size() && notes.get(position).time < t) {
|
||||
position++;
|
||||
}
|
||||
// System.out.println("position is " + position);
|
||||
}
|
||||
|
||||
public void advanceTime () {
|
||||
|
@ -83,7 +79,7 @@ public class Song {
|
|||
if (position < notes.size()) {
|
||||
return notes.get(position).time <= time;
|
||||
} else {
|
||||
if (finished() && bot.music().loop() > 0) {
|
||||
if (finished() && bot.music().loop() != Loop.OFF) {
|
||||
if (position < notes.size()) {
|
||||
return notes.get(position).time <= time;
|
||||
} else {
|
||||
|
@ -97,7 +93,7 @@ public class Song {
|
|||
|
||||
public Note getNextNote () {
|
||||
if (position >= notes.size()) {
|
||||
if (bot.music().loop() == 0) return null;
|
||||
if (bot.music().loop() == Loop.OFF) return null;
|
||||
}
|
||||
return notes.get(position++);
|
||||
}
|
||||
|
@ -106,53 +102,6 @@ public class Song {
|
|||
return time > length;
|
||||
}
|
||||
|
||||
// private void loop () {
|
||||
// if (looping == 2) {
|
||||
// System.out.println("before adding any single shit length " + bot.music().songQueue().size());
|
||||
// System.out.println("looping is 2 position " + position);
|
||||
// final Song toAdd = bot.music().songQueue().remove();
|
||||
// System.out.println("TO ADD " + toAdd.name);
|
||||
// bot.music().songQueue().add(toAdd);
|
||||
// try {
|
||||
// for (Song song : bot.music().songQueue()) {
|
||||
// System.out.println("song in list here " + song.name);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// System.out.println("BOT SONG QUEUEUE SIZE IS " + bot.music().songQueue().size());
|
||||
// }
|
||||
//
|
||||
// System.out.println("now doing the position and the shits to reset the shit TIME");
|
||||
//
|
||||
// position = 0;
|
||||
// startTime += length - loopPosition;
|
||||
// time -= length - loopPosition;
|
||||
// while (position < notes.size() && notes.get(position).time < loopPosition) {
|
||||
// position++;
|
||||
// }
|
||||
//// currentLoop++;
|
||||
// }
|
||||
|
||||
// private boolean shouldLoop () {
|
||||
//// if (looping) {
|
||||
//// if (loopCount == 0) {
|
||||
//// return true;
|
||||
//// } else {
|
||||
//// return currentLoop < loopCount;
|
||||
//// }
|
||||
//// } else {
|
||||
//// return false;
|
||||
//// }
|
||||
// if (looping == 1) {
|
||||
// if (loopCount == 0) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return currentLoop < loopCount;
|
||||
// }
|
||||
// } else return looping == 2;
|
||||
// }
|
||||
|
||||
public int size () {
|
||||
return notes.size();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue