From 4ba78b843b4b155bc93d6f0000db922624d2d1ac Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:40:46 +0700 Subject: [PATCH] refactor,fix: music stuff, and add music locking (servereval only) --- .../chomens_bot/commands/MusicCommand.java | 13 +++---------- .../chomens_bot/plugins/MusicPlayerPlugin.java | 14 ++++++-------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java index bedbe59..91dac06 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java @@ -12,7 +12,6 @@ import me.chayapak1.chomens_bot.song.Loop; import me.chayapak1.chomens_bot.song.Note; import me.chayapak1.chomens_bot.song.Song; import me.chayapak1.chomens_bot.util.*; -import me.chayapak1.chomens_bot.util.*; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.TranslatableComponent; @@ -36,8 +35,6 @@ import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank public class MusicCommand extends Command { private Path root; - private int ratelimit = 0; - public MusicCommand () { super( "music", @@ -63,15 +60,11 @@ public class MusicCommand extends Command { TrustLevel.PUBLIC, false ); - - Main.executor.scheduleAtFixedRate(() -> ratelimit = 0, 0, 5, TimeUnit.SECONDS); } @Override public Component execute(CommandContext context) throws CommandException { - ratelimit++; - - if (ratelimit > 10) return null; + if (context.bot.music.locked) throw new CommandException(Component.text("Managing music is currently locked")); final String action = context.getString(false, true, true); @@ -264,7 +257,7 @@ public class MusicCommand extends Command { final CompletableFuture future = bot.core.runTracked( "minecraft:data get entity " + UUIDUtilities.selector(context.sender.profile.getId()) + - " SelectedItem.tag.SongItemData.SongData" + " SelectedItem.components.minecraft:custom_data.SongItemData.SongData" ); if (future == null) { @@ -281,7 +274,7 @@ public class MusicCommand extends Command { .key() .equals("arguments.nbtpath.nothing_found") ) { - context.sendOutput(Component.text("Player has no SongItemData -> SongData NBT tag in the selected item").color(NamedTextColor.RED)); + context.sendOutput(Component.text("Player has no SongItemData -> SongData NBT tag in their selected item's minecraft:custom_data").color(NamedTextColor.RED)); return output; } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java index 5cc853b..a1a11ce 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java @@ -56,6 +56,8 @@ public class MusicPlayerPlugin extends Bot.Listener { private int limit = 0; + public boolean locked = false; // this can be set through servereval + private final String bossbarName = "music"; public BossBarColor bossBarColor; @@ -73,7 +75,7 @@ public class MusicPlayerPlugin extends Bot.Listener { } public void loadSong (Path location, PlayerEntry sender) { - if (songQueue.size() > 100) return; + if (songQueue.size() > 500) return; loaderThread = new SongLoaderThread(location, bot, sender.profile.getName()); @@ -90,7 +92,7 @@ public class MusicPlayerPlugin extends Bot.Listener { } public void loadSong (URL location, PlayerEntry sender) { - if (songQueue.size() > 100) return; + if (songQueue.size() > 500) return; limit++; @@ -114,7 +116,7 @@ public class MusicPlayerPlugin extends Bot.Listener { } public void loadSong (byte[] data, PlayerEntry sender) { - if (songQueue.size() > 100) return; + if (songQueue.size() > 500) return; loaderThread = new SongLoaderThread(data, bot, sender.profile.getName()); @@ -194,13 +196,9 @@ public class MusicPlayerPlugin extends Bot.Listener { if (songQueue.isEmpty()) { stopPlaying(); removeBossBar(); - bot.chat.tellraw( - Component - .text("Finished playing every song in the queue") - .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)) - ); return; } + if (currentSong.size() > 0) { currentSong = songQueue.get(0); currentSong.setTime(0);