Skip to content

Commit

Permalink
Add new config
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlgo committed Mar 1, 2023
1 parent ab765ee commit 44ad9da
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ interface IConfig {
* This is the template which is used to replace `:player_to:` part in [privateTemplate] and [consoleTemplate].
*/
var toTemplate: String

/**
* Cancel all [org.bukkit.event.player.AsyncPlayerChatEvent] and rely solely on [dev.mikchan.mcnp.chat.contract.events.MCNChatEvent]
*/
var substituteEvents: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ internal class FallbackConfig : IConfig {
override var consoleTemplate: String
get() = "<CONSOLE to :player_to:> :message:"
set(_) {}

override var substituteEvents: Boolean
get() = false
set(_) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,11 @@ internal class BoostedYamlConfig(document: File, resource: InputStream) : IConfi
config.set("toTemplate", value)
config.save()
}

override var substituteEvents: Boolean
get() = config.getBoolean("substituteEvents", false)
set(value) {
config.set("substituteEvents", value)
config.save()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ internal class MCNCListener(private val plugin: ChatPlugin) : Listener {
if (event.isGlobal) return

plugin.server.scheduler.scheduleSyncDelayedTask(plugin) {
val spies = plugin.server.onlinePlayers.filter { player -> !event.recipients.contains(player) }
.filter { player -> checkSpy(player) }.toSet()
val spies = plugin.server.onlinePlayers
.filter { player -> !event.recipients.contains(player) }
.filter { player -> checkSpy(player) }
.toSet()

if (spies.isEmpty()) return@scheduleSyncDelayedTask

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is an automatic property, do not change!
configVersion: 2
configVersion: 3

# Local chat settings
# If enabled, by default all messages sent by a player
Expand Down Expand Up @@ -55,3 +55,6 @@ fromTemplate: '%player_name%'

# If PAPI is present, this field will be used to replace :player_to:
toTemplate: '%player_name%'

# Cancel all AsyncPlayerChatEvent and rely solely on MCNChatEvent
substituteEvents: false

0 comments on commit 44ad9da

Please # to comment.