From 350e6c314e23de861d50b55c3f39e1b2bde49bb8 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Fri, 24 Mar 2023 15:07:39 +0700 Subject: [PATCH] fix core to make music work + fix other stuff --- src/main/java/me/chayapak1/chomens_bot/Bot.java | 2 +- .../me/chayapak1/chomens_bot/plugins/CorePlugin.java | 9 +++++++++ .../chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java | 2 +- .../me/chayapak1/chomens_bot/song/SongLoaderThread.java | 5 +---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/Bot.java b/src/main/java/me/chayapak1/chomens_bot/Bot.java index 40d710f..83a77b1 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Bot.java +++ b/src/main/java/me/chayapak1/chomens_bot/Bot.java @@ -126,7 +126,7 @@ public class Bot { public void run() { reconnect(); } - }, 1, reconnectDelay); + }, reconnectDelay); } }); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java index 04f0a48..fe32b35 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java @@ -14,6 +14,8 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.event.session.DisconnectedEvent; +import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.nukkitx.math.vector.Vector3i; import lombok.Getter; import me.chayapak1.chomens_bot.Bot; @@ -38,6 +40,13 @@ public class CorePlugin extends PositionPlugin.PositionListener { this.bot = bot; bot.position().addListener(this); + + bot.addListener(new SessionAdapter() { + @Override + public void disconnected (DisconnectedEvent event) { + ready = false; + } + }); } public void run (String command) { 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 d866491..bf9c902 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java @@ -69,7 +69,7 @@ public class MusicPlayerPlugin extends SessionAdapter { public void loadSong (URL location) { if (loaderThread != null) { - bot.chat().tellraw(Component.translatable("Already loading a song, can't load another", NamedTextColor.RED)); + bot.chat().tellraw(Component.translatable("Already loading a song", NamedTextColor.RED)); return; } diff --git a/src/main/java/me/chayapak1/chomens_bot/song/SongLoaderThread.java b/src/main/java/me/chayapak1/chomens_bot/song/SongLoaderThread.java index 3740dcb..e0ff942 100644 --- a/src/main/java/me/chayapak1/chomens_bot/song/SongLoaderThread.java +++ b/src/main/java/me/chayapak1/chomens_bot/song/SongLoaderThread.java @@ -24,14 +24,12 @@ public class SongLoaderThread extends Thread { public SongLoaderThread (URL location, Bot bot) throws SongLoaderException { this.bot = bot; isUrl = true; - System.out.println("its url"); songUrl = location; } public SongLoaderThread (Path location, Bot bot) throws SongLoaderException { this.bot = bot; isUrl = false; - System.out.println("its path"); songPath = location.toFile(); } @@ -47,7 +45,6 @@ public class SongLoaderThread extends Thread { name = songPath.getName(); } } catch (Exception e) { - System.out.println("WHAT THE SUS EXCEPTION YUP ! !! %@%$"); e.printStackTrace(); exception = new SongLoaderException(Component.text(e.getMessage()), e); return; @@ -66,7 +63,7 @@ public class SongLoaderThread extends Thread { } if (song == null) { - exception = new SongLoaderException(Component.translatable("Invalid song format")); + exception = new SongLoaderException(Component.translatable("Invalid format")); } }