Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
- allow disabling of main chat
- allow customization of messages if the player is vanished
  • Loading branch information
jacobwgillespie committed Feb 29, 2016
1 parent 4e33a24 commit 9c5d800
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 19 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions src/main/kotlin/gg/obsidian/discordbridge/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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")
Expand Down
59 changes: 43 additions & 16 deletions src/main/kotlin/gg/obsidian/discordbridge/EventListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)

Expand All @@ -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")

Expand All @@ -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")

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 9c5d800

Please sign in to comment.