From 9c5d800dfcb186022c76fd67e0151421191d9d65 Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Mon, 29 Feb 2016 09:30:49 -0600 Subject: [PATCH] v1.5.0 - allow disabling of main chat - allow customization of messages if the player is vanished --- README.md | 7 +++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- .../obsidian/discordbridge/Configuration.kt | 13 ++++ .../obsidian/discordbridge/EventListener.kt | 59 ++++++++++++++----- src/main/resources/config.yml | 6 ++ 6 files changed, 72 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a58e3f1..ce8c9fd 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,15 @@ settings: debug: false relay_cancelled_messages: true messages: + chat: true join: true leave: true death: false + if_vanished: + chat: false + join: false + leave: false + death: false templates: discord: chat_message: '<%u> %m' @@ -48,6 +54,7 @@ settings: * `debug` enables more verbose logging * `relay_cancelled_messages` will relay chat messages even if they are cancelled * `messages` enables or disables certain kinds of messages +* `if_vanished` enables or disables messages if the user is vanished (applies after `messages`) * `templates` - customize the message text **Templates** diff --git a/build.gradle b/build.gradle index 8589b02..176ad82 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ plugins { apply plugin: 'kotlin' group = 'gg.obsidian' -version = '1.4.5' +version = '1.5.0' description = """Bridge chat between Minecraft and Discord""" ext.url = 'https://github.com/the-obsidian/DiscordBridge' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3607e49..b9b5eaa 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Feb 21 08:29:55 CST 2016 +#Mon Feb 29 09:29:16 CST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip diff --git a/src/main/kotlin/gg/obsidian/discordbridge/Configuration.kt b/src/main/kotlin/gg/obsidian/discordbridge/Configuration.kt index 7609f8e..b1d812f 100644 --- a/src/main/kotlin/gg/obsidian/discordbridge/Configuration.kt +++ b/src/main/kotlin/gg/obsidian/discordbridge/Configuration.kt @@ -11,10 +11,17 @@ class Configuration(val plugin: Plugin) { var RELAY_CANCELLED_MESSAGES = true // Toggle message types + var MESSAGES_CHAT = true var MESSAGES_JOIN = true var MESSAGES_LEAVE = true var MESSAGES_DEATH = false + // What to do if player is vanished + var IF_VANISHED_CHAT = false + var IF_VANISHED_JOIN = false + var IF_VANISHED_LEAVE = false + var IF_VANISHED_DEATH = false + // Discord message templates var TEMPLATES_DISCORD_CHAT_MESSAGE = "" var TEMPLATES_DISCORD_PLAYER_JOIN = "" @@ -35,10 +42,16 @@ class Configuration(val plugin: Plugin) { DEBUG = plugin.config.getBoolean("settings.debug", false) RELAY_CANCELLED_MESSAGES = plugin.config.getBoolean("settings.relay_cancelled_messages", true) + MESSAGES_CHAT = plugin.config.getBoolean("settings.messages.chat", true) MESSAGES_JOIN = plugin.config.getBoolean("settings.messages.join", true) MESSAGES_LEAVE = plugin.config.getBoolean("settings.messages.leave", true) MESSAGES_DEATH = plugin.config.getBoolean("settings.messages.death", false) + IF_VANISHED_CHAT = plugin.config.getBoolean("settings.if_vanished.chat", false) + IF_VANISHED_JOIN = plugin.config.getBoolean("settings.if_vanished.join", false) + IF_VANISHED_LEAVE = plugin.config.getBoolean("settings.if_vanished.leave", false) + IF_VANISHED_DEATH = plugin.config.getBoolean("settings.if_vanished.death", false) + TEMPLATES_DISCORD_CHAT_MESSAGE = plugin.config.getString("settings.templates.discord.chat_message", "<%u> %m") TEMPLATES_DISCORD_PLAYER_JOIN = plugin.config.getString("settings.templates.discord.player_join", "%u joined the server") TEMPLATES_DISCORD_PLAYER_LEAVE = plugin.config.getString("settings.templates.discord.player_leave", "%u left the server") diff --git a/src/main/kotlin/gg/obsidian/discordbridge/EventListener.kt b/src/main/kotlin/gg/obsidian/discordbridge/EventListener.kt index 797c681..37078d8 100644 --- a/src/main/kotlin/gg/obsidian/discordbridge/EventListener.kt +++ b/src/main/kotlin/gg/obsidian/discordbridge/EventListener.kt @@ -14,34 +14,49 @@ class EventListener(val plugin: Plugin): Listener { @EventHandler(priority = EventPriority.MONITOR) fun onChat(event: AsyncPlayerChatEvent) { plugin.logDebug("Received a chat event from ${event.player.name}: ${event.message}") - if (!event.isCancelled || plugin.configuration.RELAY_CANCELLED_MESSAGES) { - val username = ChatColor.stripColor(event.player.name) - val formattedMessage = Util.formatMessage( - plugin.configuration.TEMPLATES_DISCORD_CHAT_MESSAGE, - mapOf( - "%u" to username, - "%m" to ChatColor.stripColor(event.message), - "%d" to ChatColor.stripColor(event.player.displayName), - "%w" to event.player.world.name - ) - ) - - plugin.sendToDiscord(formattedMessage) - } + + + if (!plugin.configuration.MESSAGES_CHAT) return + if (event.isCancelled && !plugin.configuration.RELAY_CANCELLED_MESSAGES) return + + // Check for vanished + val player = event.player; + if (player.hasMetadata("vanished") && + player.getMetadata("vanished")[0].asBoolean() && + !plugin.configuration.IF_VANISHED_CHAT) return + + val username = ChatColor.stripColor(event.player.name) + val formattedMessage = Util.formatMessage( + plugin.configuration.TEMPLATES_DISCORD_CHAT_MESSAGE, + mapOf( + "%u" to username, + "%m" to ChatColor.stripColor(event.message), + "%d" to ChatColor.stripColor(player.displayName), + "%w" to player.world.name + ) + ) + + plugin.sendToDiscord(formattedMessage) } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) fun onPlayerJoin(event: PlayerJoinEvent) { if (!plugin.configuration.MESSAGES_JOIN) return - val username = ChatColor.stripColor(event.player.name) + // Check for vanished + val player = event.player; + if (player.hasMetadata("vanished") && + player.getMetadata("vanished")[0].asBoolean() && + !plugin.configuration.IF_VANISHED_JOIN) return + + val username = ChatColor.stripColor(player.name) plugin.logDebug("Received a join event for $username") val formattedMessage = Util.formatMessage( plugin.configuration.TEMPLATES_DISCORD_PLAYER_JOIN, mapOf( "%u" to username, - "%d" to ChatColor.stripColor(event.player.displayName) + "%d" to ChatColor.stripColor(player.displayName) ) ) @@ -52,6 +67,12 @@ class EventListener(val plugin: Plugin): Listener { fun onPlayerQuit(event: PlayerQuitEvent) { if (!plugin.configuration.MESSAGES_LEAVE) return + // Check for vanished + val player = event.player; + if (player.hasMetadata("vanished") && + player.getMetadata("vanished")[0].asBoolean() && + !plugin.configuration.IF_VANISHED_LEAVE) return + val username = ChatColor.stripColor(event.player.name) plugin.logDebug("Received a leave event for $username") @@ -70,6 +91,12 @@ class EventListener(val plugin: Plugin): Listener { fun onPlayerDeath(event: PlayerDeathEvent) { if (!plugin.configuration.MESSAGES_DEATH) return + // Check for vanished + val player = event.entity; + if (player.hasMetadata("vanished") && + player.getMetadata("vanished")[0].asBoolean() && + !plugin.configuration.IF_VANISHED_DEATH) return + val username = ChatColor.stripColor(event.entity.name) plugin.logDebug("Received a death event for $username") diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 851d4aa..c6297a0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -7,9 +7,15 @@ settings: debug: false relay_cancelled_messages: true messages: + chat: true join: true leave: true death: false + if_vanished: + chat: false + join: false + leave: false + death: false templates: discord: chat_message: '<%u> %m'