diff --git a/src/main/kotlin/gg/obsidian/discordbridge/DiscordBridge.kt b/src/main/kotlin/gg/obsidian/discordbridge/DiscordBridge.kt index 7435b60..3cf303a 100644 --- a/src/main/kotlin/gg/obsidian/discordbridge/DiscordBridge.kt +++ b/src/main/kotlin/gg/obsidian/discordbridge/DiscordBridge.kt @@ -13,6 +13,7 @@ class DiscordBridge : JavaPlugin(), Listener { var username: String = "" var email: String = "" var password: String = "" + var debug: Boolean = false var connection: DiscordConnection? = null @@ -24,6 +25,7 @@ class DiscordBridge : JavaPlugin(), Listener { this.username = config.getString("settings.username") this.email = config.getString("settings.email") this.password = config.getString("settings.password") + this.debug = config.getBoolean("settings.debug", false) this.connection = DiscordConnection(this) @@ -33,10 +35,12 @@ class DiscordBridge : JavaPlugin(), Listener { @EventHandler(priority = EventPriority.MONITOR) fun onChat(event: AsyncPlayerChatEvent) { + logDebug("Received a chat event from ${event.player.name}: ${event.message}") send(event.player.name, event.message) } fun send(name: String, message: String) { + logDebug("Sending chat message to Discord - $name: $message") connection!!.send(name, message) } @@ -46,4 +50,9 @@ class DiscordBridge : JavaPlugin(), Listener { config.set("version", version) saveConfig() } + + fun logDebug(msg: String) { + if (!debug) return; + logger.info(msg) + } } diff --git a/src/main/kotlin/gg/obsidian/discordbridge/DiscordListener.kt b/src/main/kotlin/gg/obsidian/discordbridge/DiscordListener.kt index c850704..4eae032 100644 --- a/src/main/kotlin/gg/obsidian/discordbridge/DiscordListener.kt +++ b/src/main/kotlin/gg/obsidian/discordbridge/DiscordListener.kt @@ -8,22 +8,28 @@ import org.bukkit.ChatColor class DiscordListener(val plugin: DiscordBridge, val api: DiscordAPI) : EventListener { fun userChat(e: UserChatEvent) { + plugin.logDebug("Received message ${e.msg.id} from Discord") + if (!e.server.id.equals(plugin.serverID)) { + plugin.logDebug("Ignoring message ${e.msg.id} from Discord: server does not match") return } if (!e.group.name.equals(plugin.channel, true)) { + plugin.logDebug("Ignoring message ${e.msg.id} from Discord: channel does not match") return } val username: String = e.user.user.username if (username.equals(plugin.username, true)) { + plugin.logDebug("Ignoring message ${e.msg.id} from Discord: it matches the server's username") return } - val broadcastMessage = "<" + username + ChatColor.AQUA + "(discord)" + ChatColor.RESET + "> " + e.msg.message + plugin.logDebug("Broadcasting message ${e.msg.id} from Discord as user $username") + val broadcastMessage = "<" + username + ChatColor.AQUA + "(discord)" + ChatColor.RESET + "> " + e.msg.message plugin.server.broadcastMessage(broadcastMessage) } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0482afb..2795428 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,4 +3,5 @@ settings: channel: 'test' username: 'username' email: 'email@example.com' - password: 'password' \ No newline at end of file + password: 'password' + debug: false