diff --git a/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt b/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt index d405b1e..00daa40 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt @@ -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 } diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt index aca4c8c..1a5c269 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt @@ -62,4 +62,8 @@ internal class FallbackConfig : IConfig { override var consoleTemplate: String get() = " :message:" set(_) {} + + override var substituteEvents: Boolean + get() = false + set(_) {} } diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt index 98b00ed..3d01fdc 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt @@ -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() + } } diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt index b1f413c..eb7744a 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt @@ -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 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8d69668..ff28cbb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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 @@ -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