|
8 | 8 | import net.dv8tion.jda.api.OnlineStatus; |
9 | 9 | import net.dv8tion.jda.api.entities.Activity; |
10 | 10 | import net.dv8tion.jda.api.entities.Activity.ActivityType; |
| 11 | +import net.dv8tion.jda.api.events.ReadyEvent; |
| 12 | +import net.dv8tion.jda.api.events.ReconnectedEvent; |
| 13 | +import net.dv8tion.jda.api.events.StatusChangeEvent; |
11 | 14 | import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
12 | 15 | import net.dv8tion.jda.api.hooks.ListenerAdapter; |
13 | 16 | import org.bukkit.Server; |
14 | 17 |
|
15 | 18 | import java.util.logging.Logger; |
16 | 19 |
|
17 | | -public class DiscordCommunication extends ListenerAdapter implements Runnable { |
| 20 | +public class DiscordCommunication extends ListenerAdapter { |
18 | 21 | static JDA MCD; |
19 | 22 | private String channelId; |
20 | 23 | private Logger lg; |
@@ -52,25 +55,19 @@ public void onMessageReceived(MessageReceivedEvent event) { |
52 | 55 | if(event.getChannel().getId().equals(channelId) && !event.getAuthor().isBot()) |
53 | 56 | server.broadcastMessage("[Discord] " + event.getAuthor().getName() + " : " + event.getMessage().getContentRaw()); |
54 | 57 | } |
| 58 | + private boolean first = true; |
| 59 | + @Override |
| 60 | + public void onReady(ReadyEvent event) { |
| 61 | + if(first) { |
| 62 | + MCD.getTextChannelById(channelId).sendMessage(serverStartMessage).queue(); |
| 63 | + first = false; |
| 64 | + } |
| 65 | + } |
55 | 66 |
|
56 | 67 | public void sendMessageToDiscord(String message) { |
57 | 68 | MCD.getTextChannelById(channelId).sendMessage(message).queue(); |
58 | 69 | } |
59 | 70 |
|
60 | | - @Override |
61 | | - public void run() { |
62 | | - while (true) { |
63 | | - try { |
64 | | - MCD.getTextChannelById(channelId).sendMessage(serverStartMessage).queue(); |
65 | | - //IF YOU REALLY MODIFIED THE PROJECT YOU CAN DELETE THIS MESSAGE. OTHERWISE, YOU ARE NOT ALLOWED TO! |
66 | | - //MCD.getTextChannelById(channelId).sendMessage("```css\n'Minecraft Connects Discord'\n Made by Mahmut H. Kocas \n https://www.thedoctorone.github.io```").queue(); |
67 | | - break; |
68 | | - } catch (NullPointerException | IllegalMonitorStateException e) { |
69 | | - continue; |
70 | | - } |
71 | | - } |
72 | | - } |
73 | | - |
74 | 71 | public void setChannelId(String channelId) { |
75 | 72 | this.channelId = channelId; |
76 | 73 | } |
|
0 commit comments