Skip to content

Commit 9c5d800

Browse files
v1.5.0
- allow disabling of main chat - allow customization of messages if the player is vanished
1 parent 4e33a24 commit 9c5d800

File tree

6 files changed

+72
-19
lines changed

6 files changed

+72
-19
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ settings:
2727
debug: false
2828
relay_cancelled_messages: true
2929
messages:
30+
chat: true
3031
join: true
3132
leave: true
3233
death: false
34+
if_vanished:
35+
chat: false
36+
join: false
37+
leave: false
38+
death: false
3339
templates:
3440
discord:
3541
chat_message: '<%u> %m'
@@ -48,6 +54,7 @@ settings:
4854
* `debug` enables more verbose logging
4955
* `relay_cancelled_messages` will relay chat messages even if they are cancelled
5056
* `messages` enables or disables certain kinds of messages
57+
* `if_vanished` enables or disables messages if the user is vanished (applies after `messages`)
5158
* `templates` - customize the message text
5259
5360
**Templates**

Diff for: build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323
apply plugin: 'kotlin'
2424

2525
group = 'gg.obsidian'
26-
version = '1.4.5'
26+
version = '1.5.0'
2727
description = """Bridge chat between Minecraft and Discord"""
2828
ext.url = 'https://github.com/the-obsidian/DiscordBridge'
2929

Diff for: gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun Feb 21 08:29:55 CST 2016
1+
#Mon Feb 29 09:29:16 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip

Diff for: src/main/kotlin/gg/obsidian/discordbridge/Configuration.kt

+13
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ class Configuration(val plugin: Plugin) {
1111
var RELAY_CANCELLED_MESSAGES = true
1212

1313
// Toggle message types
14+
var MESSAGES_CHAT = true
1415
var MESSAGES_JOIN = true
1516
var MESSAGES_LEAVE = true
1617
var MESSAGES_DEATH = false
1718

19+
// What to do if player is vanished
20+
var IF_VANISHED_CHAT = false
21+
var IF_VANISHED_JOIN = false
22+
var IF_VANISHED_LEAVE = false
23+
var IF_VANISHED_DEATH = false
24+
1825
// Discord message templates
1926
var TEMPLATES_DISCORD_CHAT_MESSAGE = ""
2027
var TEMPLATES_DISCORD_PLAYER_JOIN = ""
@@ -35,10 +42,16 @@ class Configuration(val plugin: Plugin) {
3542
DEBUG = plugin.config.getBoolean("settings.debug", false)
3643
RELAY_CANCELLED_MESSAGES = plugin.config.getBoolean("settings.relay_cancelled_messages", true)
3744

45+
MESSAGES_CHAT = plugin.config.getBoolean("settings.messages.chat", true)
3846
MESSAGES_JOIN = plugin.config.getBoolean("settings.messages.join", true)
3947
MESSAGES_LEAVE = plugin.config.getBoolean("settings.messages.leave", true)
4048
MESSAGES_DEATH = plugin.config.getBoolean("settings.messages.death", false)
4149

50+
IF_VANISHED_CHAT = plugin.config.getBoolean("settings.if_vanished.chat", false)
51+
IF_VANISHED_JOIN = plugin.config.getBoolean("settings.if_vanished.join", false)
52+
IF_VANISHED_LEAVE = plugin.config.getBoolean("settings.if_vanished.leave", false)
53+
IF_VANISHED_DEATH = plugin.config.getBoolean("settings.if_vanished.death", false)
54+
4255
TEMPLATES_DISCORD_CHAT_MESSAGE = plugin.config.getString("settings.templates.discord.chat_message", "<%u> %m")
4356
TEMPLATES_DISCORD_PLAYER_JOIN = plugin.config.getString("settings.templates.discord.player_join", "%u joined the server")
4457
TEMPLATES_DISCORD_PLAYER_LEAVE = plugin.config.getString("settings.templates.discord.player_leave", "%u left the server")

Diff for: src/main/kotlin/gg/obsidian/discordbridge/EventListener.kt

+43-16
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,49 @@ class EventListener(val plugin: Plugin): Listener {
1414
@EventHandler(priority = EventPriority.MONITOR)
1515
fun onChat(event: AsyncPlayerChatEvent) {
1616
plugin.logDebug("Received a chat event from ${event.player.name}: ${event.message}")
17-
if (!event.isCancelled || plugin.configuration.RELAY_CANCELLED_MESSAGES) {
18-
val username = ChatColor.stripColor(event.player.name)
19-
val formattedMessage = Util.formatMessage(
20-
plugin.configuration.TEMPLATES_DISCORD_CHAT_MESSAGE,
21-
mapOf(
22-
"%u" to username,
23-
"%m" to ChatColor.stripColor(event.message),
24-
"%d" to ChatColor.stripColor(event.player.displayName),
25-
"%w" to event.player.world.name
26-
)
27-
)
28-
29-
plugin.sendToDiscord(formattedMessage)
30-
}
17+
18+
19+
if (!plugin.configuration.MESSAGES_CHAT) return
20+
if (event.isCancelled && !plugin.configuration.RELAY_CANCELLED_MESSAGES) return
21+
22+
// Check for vanished
23+
val player = event.player;
24+
if (player.hasMetadata("vanished") &&
25+
player.getMetadata("vanished")[0].asBoolean() &&
26+
!plugin.configuration.IF_VANISHED_CHAT) return
27+
28+
val username = ChatColor.stripColor(event.player.name)
29+
val formattedMessage = Util.formatMessage(
30+
plugin.configuration.TEMPLATES_DISCORD_CHAT_MESSAGE,
31+
mapOf(
32+
"%u" to username,
33+
"%m" to ChatColor.stripColor(event.message),
34+
"%d" to ChatColor.stripColor(player.displayName),
35+
"%w" to player.world.name
36+
)
37+
)
38+
39+
plugin.sendToDiscord(formattedMessage)
3140
}
3241

3342
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
3443
fun onPlayerJoin(event: PlayerJoinEvent) {
3544
if (!plugin.configuration.MESSAGES_JOIN) return
3645

37-
val username = ChatColor.stripColor(event.player.name)
46+
// Check for vanished
47+
val player = event.player;
48+
if (player.hasMetadata("vanished") &&
49+
player.getMetadata("vanished")[0].asBoolean() &&
50+
!plugin.configuration.IF_VANISHED_JOIN) return
51+
52+
val username = ChatColor.stripColor(player.name)
3853
plugin.logDebug("Received a join event for $username")
3954

4055
val formattedMessage = Util.formatMessage(
4156
plugin.configuration.TEMPLATES_DISCORD_PLAYER_JOIN,
4257
mapOf(
4358
"%u" to username,
44-
"%d" to ChatColor.stripColor(event.player.displayName)
59+
"%d" to ChatColor.stripColor(player.displayName)
4560
)
4661
)
4762

@@ -52,6 +67,12 @@ class EventListener(val plugin: Plugin): Listener {
5267
fun onPlayerQuit(event: PlayerQuitEvent) {
5368
if (!plugin.configuration.MESSAGES_LEAVE) return
5469

70+
// Check for vanished
71+
val player = event.player;
72+
if (player.hasMetadata("vanished") &&
73+
player.getMetadata("vanished")[0].asBoolean() &&
74+
!plugin.configuration.IF_VANISHED_LEAVE) return
75+
5576
val username = ChatColor.stripColor(event.player.name)
5677
plugin.logDebug("Received a leave event for $username")
5778

@@ -70,6 +91,12 @@ class EventListener(val plugin: Plugin): Listener {
7091
fun onPlayerDeath(event: PlayerDeathEvent) {
7192
if (!plugin.configuration.MESSAGES_DEATH) return
7293

94+
// Check for vanished
95+
val player = event.entity;
96+
if (player.hasMetadata("vanished") &&
97+
player.getMetadata("vanished")[0].asBoolean() &&
98+
!plugin.configuration.IF_VANISHED_DEATH) return
99+
73100
val username = ChatColor.stripColor(event.entity.name)
74101
plugin.logDebug("Received a death event for $username")
75102

Diff for: src/main/resources/config.yml

+6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ settings:
77
debug: false
88
relay_cancelled_messages: true
99
messages:
10+
chat: true
1011
join: true
1112
leave: true
1213
death: false
14+
if_vanished:
15+
chat: false
16+
join: false
17+
leave: false
18+
death: false
1319
templates:
1420
discord:
1521
chat_message: '<%u> %m'

0 commit comments

Comments
 (0)