From c50216132981a993fb827315c7c4d6fb3d5857a1 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Sun, 27 Oct 2019 00:38:52 -0400 Subject: Starting work to update libraries JDA v4 has many breaking changes that will need to be checked Lavaplayer shouldn't have any major changes, but needs version bump to continue working with various sites --- .../java/soundchan/AudioPlayerSendHandler.java | 11 ++++---- .../java/soundchan/BotListener/BotListener.java | 32 ++++++++++------------ .../soundchan/BotListener/BotListenerHelpers.java | 6 ++-- src/main/java/soundchan/LocalAudioManager.java | 2 +- src/main/java/soundchan/Main.java | 13 ++++----- 5 files changed, 30 insertions(+), 34 deletions(-) (limited to 'src/main/java/soundchan') diff --git a/src/main/java/soundchan/AudioPlayerSendHandler.java b/src/main/java/soundchan/AudioPlayerSendHandler.java index 5e174ca..fdd9774 100644 --- a/src/main/java/soundchan/AudioPlayerSendHandler.java +++ b/src/main/java/soundchan/AudioPlayerSendHandler.java @@ -2,7 +2,9 @@ package soundchan; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; -import net.dv8tion.jda.core.audio.AudioSendHandler; +import net.dv8tion.jda.api.audio.AudioSendHandler; + +import java.nio.ByteBuffer; /** * This is a wrapper around AudioPlayer which makes it behave as an AudioSendHandler for JDA. As JDA calls canProvide @@ -30,15 +32,12 @@ public class AudioPlayerSendHandler implements AudioSendHandler { } @Override - public byte[] provide20MsAudio() { + public ByteBuffer provide20MsAudio() { if (lastFrame == null) { lastFrame = audioPlayer.provide(); } - byte[] data = lastFrame != null ? lastFrame.getData() : null; - lastFrame = null; - - return data; + return ByteBuffer.wrap(lastFrame.getData()); } @Override diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 4864ae2..0bd920d 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -7,17 +7,17 @@ import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import com.sun.istack.internal.NotNull; -import net.dv8tion.jda.client.events.call.voice.CallVoiceJoinEvent; -import net.dv8tion.jda.core.entities.Guild; -import net.dv8tion.jda.core.entities.MessageChannel; -import net.dv8tion.jda.core.entities.VoiceChannel; -import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent; -import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent; -import net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent; -import net.dv8tion.jda.core.events.message.MessageReceivedEvent; -import net.dv8tion.jda.core.hooks.ListenerAdapter; -import net.dv8tion.jda.core.managers.AudioManager; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.managers.AudioManager; +import org.jetbrains.annotations.NotNull; import soundchan.*; import java.nio.file.WatchEvent; @@ -109,11 +109,6 @@ public class BotListener extends ListenerAdapter{ return musicManager; } - @Override - public void onCallVoiceJoin(CallVoiceJoinEvent event){ - super.onCallVoiceJoin(event); - } - /** * Plays an audio clip when a user connects to the voice channel if enabled in the config file. For the sound to play, * there needs to be a sound file with the same name as the user, otherwise it won't play anything. @@ -195,7 +190,10 @@ public class BotListener extends ListenerAdapter{ public void onMessageReceived(MessageReceivedEvent event) { String[] command = event.getMessage().getContentRaw().split(" ", 2); - Guild guild = event.getGuild(); + Guild guild = null; + if(event.isFromGuild()) { + guild = event.getGuild(); + } MessageChannel channel = helper.GetReplyChannel(event); // If we haven't set the Monitored Guild yet, set the value diff --git a/src/main/java/soundchan/BotListener/BotListenerHelpers.java b/src/main/java/soundchan/BotListener/BotListenerHelpers.java index 98ad31a..4c589a3 100644 --- a/src/main/java/soundchan/BotListener/BotListenerHelpers.java +++ b/src/main/java/soundchan/BotListener/BotListenerHelpers.java @@ -1,8 +1,8 @@ package soundchan.BotListener; -import net.dv8tion.jda.core.entities.Guild; -import net.dv8tion.jda.core.entities.MessageChannel; -import net.dv8tion.jda.core.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public class BotListenerHelpers { diff --git a/src/main/java/soundchan/LocalAudioManager.java b/src/main/java/soundchan/LocalAudioManager.java index ea5b317..4db7010 100644 --- a/src/main/java/soundchan/LocalAudioManager.java +++ b/src/main/java/soundchan/LocalAudioManager.java @@ -1,6 +1,6 @@ package soundchan; -import net.dv8tion.jda.core.entities.MessageChannel; +import net.dv8tion.jda.api.entities.MessageChannel; import java.io.File; import java.io.FileInputStream; diff --git a/src/main/java/soundchan/Main.java b/src/main/java/soundchan/Main.java index a7aa6a3..587c7e9 100644 --- a/src/main/java/soundchan/Main.java +++ b/src/main/java/soundchan/Main.java @@ -1,8 +1,8 @@ package soundchan; -import net.dv8tion.jda.core.AccountType; -import net.dv8tion.jda.core.JDA; -import net.dv8tion.jda.core.JDABuilder; +import net.dv8tion.jda.api.AccountType; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; import soundchan.BotListener.*; import java.io.FileInputStream; @@ -17,10 +17,9 @@ public class Main { JDA jda = new JDABuilder(AccountType.BOT) .setToken(properties.getProperty("botToken")) - .buildBlocking(); - - - jda.addEventListener(new BotListener(properties)); + .addEventListeners(new BotListener(properties)) + .build(); + jda.awaitReady(); } private static Properties LoadProperties(){ -- cgit v1.2.3