diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java index 7de04d3..cbcf778 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -21,6 +21,7 @@ public class Configuration { public Core core = new Core(); public Discord discord = new Discord(); + public Music music = new Music(); public ColorPalette colorPalette = new ColorPalette(); @@ -91,6 +92,15 @@ public class Configuration { public String inviteLink = "https://discord.gg/xdgCkUyaA4"; } + public static class Music { + public URLRatelimit urlRatelimit = new URLRatelimit(); + + public static class URLRatelimit { + public int seconds = 15; + public int limit = 7; + } + } + public static class EmbedColors { public String normal = "#FFFF00"; public String error = "#FF0000"; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java index 01617c7..a7af3fb 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java @@ -37,8 +37,6 @@ public class MusicPlayerPlugin extends Bot.Listener { } } - public int loadings = 0; - public Song currentSong; public final List songQueue = new ArrayList<>(); public SongLoaderRunnable loaderThread; @@ -54,6 +52,8 @@ public class MusicPlayerPlugin extends Bot.Listener { private int notesPerSecond = 0; + private int limit = 0; + private final String bossbarName = "music"; public MusicPlayerPlugin (Bot bot) { @@ -62,7 +62,8 @@ public class MusicPlayerPlugin extends Bot.Listener { bot.core.addListener(new CorePlugin.Listener() { public void ready () { coreReady(); } }); - bot.executor.scheduleAtFixedRate(() -> notesPerSecond = 0, 0, 10, TimeUnit.SECONDS); + bot.executor.scheduleAtFixedRate(() -> notesPerSecond = 0, 0, 1, TimeUnit.SECONDS); + bot.executor.scheduleAtFixedRate(() -> limit = 0, 0, bot.config.music.urlRatelimit.seconds, TimeUnit.SECONDS); } public void loadSong (Path location) { @@ -81,13 +82,13 @@ public class MusicPlayerPlugin extends Bot.Listener { } public void loadSong (URL location) { - if (loadings > 7) { + limit++; + + if (limit > bot.config.music.urlRatelimit.limit) { bot.chat.tellraw(Component.text("ohio").color(NamedTextColor.RED)); return; } - loadings++; - final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot); bot.chat.tellraw( @@ -290,7 +291,7 @@ public class MusicPlayerPlugin extends Bot.Listener { while (currentSong.reachedNextNote()) { final Note note = currentSong.getNextNote(); - if (notesPerSecond > 2048 && bot.core.hasRateLimit()) continue; + if (notesPerSecond > 700) continue; float key = note.pitch; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java index 0bcd1fc..445a5e5 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java @@ -71,8 +71,6 @@ public class SongLoaderRunnable implements Runnable { if (isUrl) { bytes = DownloadUtilities.DownloadToByteArray(songUrl, 5 * 1024 * 1024); name = Paths.get(songUrl.toURI().getPath()).getFileName().toString(); - - bot.music.loadings--; } else { bytes = Files.readAllBytes(songPath); name = !isFolder ? fileName : songPath.getFileName().toString(); @@ -131,7 +129,5 @@ public class SongLoaderRunnable implements Runnable { exception.printStackTrace(); bot.chat.tellraw(Component.translatable("Failed to load song: %s", exception.message).color(NamedTextColor.RED)); bot.music.loaderThread = null; - - if (isUrl) bot.music.loadings--; } } \ No newline at end of file diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 315ebed..f09f849 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -34,6 +34,11 @@ discord: servers: localhost:25565: 'channel id' +music: + URLRatelimit: + seconds: 15 + limit: 7 + colorPalette: primary: 'yellow' secondary: 'gold'