-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99b8ae3
commit 035b56f
Showing
12 changed files
with
291 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 32 additions & 10 deletions
42
src/main/java/com/denizenscript/ddiscordbot/DiscordConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,50 @@ | ||
package com.denizenscript.ddiscordbot; | ||
|
||
import com.denizenscript.ddiscordbot.events.DiscordMessageReceivedScriptEvent; | ||
import com.denizenscript.ddiscordbot.events.*; | ||
import org.bukkit.Bukkit; | ||
import sx.blah.discord.api.IDiscordClient; | ||
import sx.blah.discord.api.events.Event; | ||
import sx.blah.discord.api.events.IListener; | ||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageDeleteEvent; | ||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageEditEvent; | ||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent; | ||
import sx.blah.discord.handle.impl.events.guild.member.UserJoinEvent; | ||
import sx.blah.discord.handle.impl.events.guild.member.UserLeaveEvent; | ||
|
||
public class DiscordConnection implements IListener<MessageReceivedEvent> { | ||
public class DiscordConnection implements IListener { | ||
|
||
public String botID; | ||
|
||
public IDiscordClient client; | ||
|
||
@Override | ||
public void handle(MessageReceivedEvent messageReceivedEvent) { | ||
public void autoHandle(Event event, DiscordScriptEvent scriptEvent) { | ||
Bukkit.getScheduler().runTask(dDiscordBot.instance, () -> { | ||
DiscordMessageReceivedScriptEvent mrse = DiscordMessageReceivedScriptEvent.instance; | ||
if (!mrse.enabled) { | ||
if (!scriptEvent.enabled) { | ||
return; | ||
} | ||
mrse.botID = botID; | ||
mrse.mre = messageReceivedEvent; | ||
mrse.cancelled = false; | ||
mrse.fire(); | ||
scriptEvent.botID = botID; | ||
scriptEvent.event = event; | ||
scriptEvent.cancelled = false; | ||
scriptEvent.fire(); | ||
}); | ||
} | ||
|
||
@Override | ||
public void handle(Event event) { | ||
if (event instanceof MessageReceivedEvent) { | ||
autoHandle(event, DiscordMessageReceivedScriptEvent.instance); | ||
} | ||
else if (event instanceof MessageEditEvent) { | ||
autoHandle(event, DiscordMessageModifiedScriptEvent.instance); | ||
} | ||
else if (event instanceof MessageDeleteEvent) { | ||
autoHandle(event, DiscordMessageDeletedScriptEvent.instance); | ||
} | ||
else if (event instanceof UserJoinEvent) { | ||
autoHandle(event, DiscordUserJoinsScriptEvent.instance); | ||
} | ||
else if (event instanceof UserLeaveEvent) { | ||
autoHandle(event, DiscordUserLeavesScriptEvent.instance); | ||
} | ||
} | ||
} |
Oops, something went wrong.