From b7ab826f51611950403343cd65ee7e220c27f94d Mon Sep 17 00:00:00 2001 From: ItsFlicker <1812496278@qq.com> Date: Sat, 23 Apr 2022 13:20:38 +0800 Subject: [PATCH] + [2.0.0-PRE-5] Improve Kether & Fix legacy eco hook & Support filter before sending --- build.gradle.kts | 4 +- gradle.properties | 2 +- .../kotlin/me/arasple/mc/trchat/TrChat.kt | 1 + .../arasple/mc/trchat/api/config/Settings.kt | 2 + .../arasple/mc/trchat/module/conf/Loader.kt | 12 ++++-- .../trchat/module/display/channel/Channel.kt | 43 ++++++++++++++++++- .../module/display/channel/PrivateChannel.kt | 5 +++ .../display/channel/obj/ChannelSettings.kt | 3 +- .../module/internal/command/CommandHandler.kt | 3 -- .../internal/hook/impl/HookEcoEnchants.kt | 6 ++- .../internal/script/kether/ActionChannel.kt | 2 +- .../internal/script/kether/ActionServer.kt | 33 ++++++++++++++ src/main/resources/channels/Global.yml | 19 +++++++- src/main/resources/lang/en_US.yml | 7 +++ src/main/resources/lang/zh_CN.yml | 7 +++ src/main/resources/settings.yml | 5 ++- 16 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionServer.kt diff --git a/build.gradle.kts b/build.gradle.kts index 8d510dca..7b81ffaa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-library` id("io.izzel.taboolib") version "1.38" - id("org.jetbrains.kotlin.jvm") version "1.6.10" + id("org.jetbrains.kotlin.jvm") version "1.5.10" id("org.tabooproject.shrinkingkt") version "1.0.6" } @@ -47,12 +47,12 @@ configure { } repositories { + mavenCentral() maven("https://nexus.velocitypowered.com/repository/maven-public/") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") maven("https://repo.codemc.io/repository/maven-public/") maven("https://papermc.io/repo/repository/maven-public/") maven("https://jitpack.io") - mavenCentral() } dependencies { diff --git a/gradle.properties b/gradle.properties index dbf8b7d5..02575da1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=me.arasple.mc.trchat -version=2.0.0-PRE-4 \ No newline at end of file +version=2.0.0-PRE-5 \ No newline at end of file diff --git a/src/main/kotlin/me/arasple/mc/trchat/TrChat.kt b/src/main/kotlin/me/arasple/mc/trchat/TrChat.kt index 8a59201d..689d1a47 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/TrChat.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/TrChat.kt @@ -57,6 +57,7 @@ object TrChat : Plugin() { Util.init() } + Database.init() Loader.loadChannels(console()) diff --git a/src/main/kotlin/me/arasple/mc/trchat/api/config/Settings.kt b/src/main/kotlin/me/arasple/mc/trchat/api/config/Settings.kt index 18748421..dc44da26 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/api/config/Settings.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/api/config/Settings.kt @@ -11,6 +11,7 @@ import taboolib.module.configuration.Config import taboolib.module.configuration.ConfigNode import taboolib.module.configuration.ConfigNodeTransfer import taboolib.module.configuration.Configuration +import taboolib.module.kether.Kether /** * @author wlys @@ -35,6 +36,7 @@ object Settings { Channel.defaultChannel = Channel.channels.firstOrNull { it.id == id }.also { if (it == null) severe("Default channel $id not found.") } + Kether.isAllowToleranceParser = CONF.getBoolean("Options.Kether-Allow-Tolerance-Parser", true) } @ConfigNode("Chat.Cooldown", "settings.yml") diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt b/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt index d13236f6..bd1fc34f 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt @@ -114,7 +114,8 @@ object Loader { val proxy = section.getBoolean("Proxy", false) val ports = section.getString("Ports")?.split(";")?.map { it.toInt() } val disabledFunctions = section.getStringList("Disabled-Functions") - ChannelSettings(joinPermission, speakCondition, target, autoJoin, proxy, ports, disabledFunctions) + val filterBeforeSending = section.getBoolean("Filter-Before-Sending", false) + ChannelSettings(joinPermission, speakCondition, target, autoJoin, proxy, ports, disabledFunctions, filterBeforeSending) } val private = conf.getBoolean("Options.Private", false) @@ -152,8 +153,13 @@ object Loader { val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>) Format(condition, priority, prefix, msg, suffix) }.sortedBy { it.priority } - - return Channel(id, settings, bindings, formats) + val console = conf.getConfigurationSection("Console")?.let { map -> + val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>) + val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>) + val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>) + Format(null, 100, prefix, msg, suffix) + } + return Channel(id, settings, bindings, formats, console) } } diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/Channel.kt b/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/Channel.kt index 6f7079b4..cb7b2ddb 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/Channel.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/Channel.kt @@ -4,6 +4,7 @@ import me.arasple.mc.trchat.api.event.TrChatEvent import me.arasple.mc.trchat.module.display.channel.obj.ChannelBindings import me.arasple.mc.trchat.module.display.channel.obj.ChannelSettings import me.arasple.mc.trchat.module.display.channel.obj.Target +import me.arasple.mc.trchat.module.display.filter.ChatFilter import me.arasple.mc.trchat.module.display.format.Format import me.arasple.mc.trchat.module.internal.data.ChatLogs import me.arasple.mc.trchat.module.internal.service.Metrics @@ -33,6 +34,7 @@ open class Channel( val settings: ChannelSettings, val bindings: ChannelBindings, val formats: List, + val console: Format? = null ) { init { @@ -46,8 +48,41 @@ open class Channel( } } dynamic("message", optional = true) { - execute { sender, _, argument -> - execute(sender, argument) + execute { sender, _, argument -> + if (sender is Player) { + execute(sender, argument) + } else { +// val builder = Component.text() +// console?.let { format -> +// format.prefix.forEach { prefix -> +// builder.append(prefix.value.first().content.toTextComponent(player)) } +// builder.append(format.msg.serialize(player, argument, settings.disabledFunctions)) +// format.suffix.forEach { suffix -> +// builder.append(suffix.value.first().content.toTextComponent(player)) } +// } ?: return@execute +// val component = builder.build() +// +// if (settings.proxy && Proxy.isEnabled) { +// val gson = gson(component) +// if (settings.ports != null) { +// player.sendBukkitMessage( +// "ForwardRaw", +// player.uniqueId.toString(), +// gson, +// settings.joinPermission ?: "null", +// settings.ports.joinToString(";") +// ) +// } else { +// player.sendBukkitMessage( +// "BroadcastRaw", +// player.uniqueId.toString(), +// gson, +// settings.joinPermission ?: "null" +// ) +// } +// return +// } + } } } incorrectSender { sender, _ -> @@ -67,6 +102,10 @@ open class Channel( player.sendLang("Channel-No-Speak-Permission") return } + if (settings.filterBeforeSending && ChatFilter.filter(message).sensitiveWords > 0) { + player.sendLang("Channel-Filter-Before-Sending") + return + } val event = TrChatEvent(this, player.getSession(), message) if (!event.call()) { return diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/PrivateChannel.kt b/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/PrivateChannel.kt index cfd4efe3..a20b8037 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/PrivateChannel.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/PrivateChannel.kt @@ -4,6 +4,7 @@ import me.arasple.mc.trchat.api.event.TrChatEvent import me.arasple.mc.trchat.module.display.ChatSession import me.arasple.mc.trchat.module.display.channel.obj.ChannelBindings import me.arasple.mc.trchat.module.display.channel.obj.ChannelSettings +import me.arasple.mc.trchat.module.display.filter.ChatFilter import me.arasple.mc.trchat.module.display.format.Format import me.arasple.mc.trchat.module.internal.command.main.CommandReply import me.arasple.mc.trchat.module.internal.data.ChatLogs @@ -76,6 +77,10 @@ class PrivateChannel( player.sendLang("Channel-No-Speak-Permission") return } + if (settings.filterBeforeSending && ChatFilter.filter(message).sensitiveWords > 0) { + player.sendLang("Channel-Filter-Before-Sending") + return + } val session = player.getSession() val event = TrChatEvent(this, session, message) if (!event.call()) { diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/obj/ChannelSettings.kt b/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/obj/ChannelSettings.kt index 823a272e..652f51ac 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/obj/ChannelSettings.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/obj/ChannelSettings.kt @@ -13,5 +13,6 @@ class ChannelSettings( val autoJoin: Boolean, val proxy: Boolean, val ports: List?, - val disabledFunctions: List + val disabledFunctions: List, + val filterBeforeSending: Boolean ) \ No newline at end of file diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/CommandHandler.kt b/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/CommandHandler.kt index bbc9098c..a92cb925 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/CommandHandler.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/CommandHandler.kt @@ -4,7 +4,6 @@ import me.arasple.mc.trchat.api.config.Filters import me.arasple.mc.trchat.api.config.Functions import me.arasple.mc.trchat.api.config.Settings import me.arasple.mc.trchat.module.conf.Loader -import me.arasple.mc.trchat.module.display.filter.ChatFilter import me.arasple.mc.trchat.module.display.menu.MenuControlPanel import me.arasple.mc.trchat.module.display.menu.MenuFilterControl import me.arasple.mc.trchat.module.internal.command.sub.CommandRemoveMessage @@ -43,8 +42,6 @@ object CommandHandler { Functions.CONF.reload() Filters.CONF.reload() Loader.loadChannels(sender) - Loader.loadFunctions(sender) - ChatFilter.loadFilter(true, sender) } } diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/internal/hook/impl/HookEcoEnchants.kt b/src/main/kotlin/me/arasple/mc/trchat/module/internal/hook/impl/HookEcoEnchants.kt index cbd3f3e9..e01fa833 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/internal/hook/impl/HookEcoEnchants.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/internal/hook/impl/HookEcoEnchants.kt @@ -18,6 +18,10 @@ class HookEcoEnchants : HookAbstract() { if (!isHooked || item.isAir()) { return item } - return Display.displayAndFinalize(item, player) + return try { + Display.displayAndFinalize(item, player) + } catch (_: Throwable){ + Display.displayAndFinalize(item) + } } } \ No newline at end of file diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionChannel.kt b/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionChannel.kt index 66d84b37..6d0cd301 100644 --- a/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionChannel.kt +++ b/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionChannel.kt @@ -30,7 +30,7 @@ class ActionChannel(val symbol: Symbol, val channel: String?): ScriptAction Symbol.JOIN diff --git a/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionServer.kt b/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionServer.kt new file mode 100644 index 00000000..331a628d --- /dev/null +++ b/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/ActionServer.kt @@ -0,0 +1,33 @@ +package me.arasple.mc.trchat.module.internal.script.kether + +import me.arasple.mc.trchat.util.proxy.bungee.Bungees +import taboolib.library.kether.ArgTypes +import taboolib.library.kether.ParsedAction +import taboolib.module.kether.* +import java.util.concurrent.CompletableFuture + +/** + * @author wlys + * @since 2021/8/29 15:44 + */ +class ActionServer(val server: ParsedAction<*>): ScriptAction() { + + override fun run(frame: ScriptFrame): CompletableFuture { + val s = frame.script() + if (s.sender == null) { + error("No sender selected.") + } + frame.newFrame(server).run().thenAccept { server -> + Bungees.sendBungeeData(s.sender!!.cast(), "Connect", server.toString()) + } + return CompletableFuture.completedFuture(null) + } + + companion object { + + @KetherParser(["server", "bungee", "connect"], shared = true) + fun parser() = scriptParser { + ActionServer(it.next(ArgTypes.ACTION)) + } + } +} \ No newline at end of file diff --git a/src/main/resources/channels/Global.yml b/src/main/resources/channels/Global.yml index fd103102..72cba8f0 100644 --- a/src/main/resources/channels/Global.yml +++ b/src/main/resources/channels/Global.yml @@ -23,4 +23,21 @@ Formats: text: '&e%player_name%&8: ' msg: default-color: 'f' - hover: '&7Date: %server_time_HH:mm:ss%' \ No newline at end of file + hover: '&7Date: %server_time_HH:mm:ss%' + +Console: + condition: null + prefix: + server: + text: '&8[&3%server_name%&8] ' + hover: |- + &7Server &3%server_name% + &r + &7Version: &6%server_version% + &7Online: &a%server_online%&7/&2%server_max_players% + &7TPS: &b%server_tps% + player: + text: '&e%player_name%&8: ' + msg: + default-color: 'f' + hover: '&7Date: %server_time_HH:mm:ss%' \ No newline at end of file diff --git a/src/main/resources/lang/en_US.yml b/src/main/resources/lang/en_US.yml index e1a96a08..54370b59 100644 --- a/src/main/resources/lang/en_US.yml +++ b/src/main/resources/lang/en_US.yml @@ -146,6 +146,13 @@ Channel-No-Speak-Permission: sound: 'ENTITY_ITEM_BREAK' volume: 1 pitch: 0 +Channel-Bad-Language: + - type: actionbar + text: '&cYou cannot speak bad language.' + - type: sound + sound: 'ENTITY_ITEM_BREAK' + volume: 1 + pitch: 0 Mute-Muted-Player: '&8[&3Tr&bChat&8] &7You muted {0} for {1} minute(s).' Mute-Muted-All: '&8[&3Tr&bChat&8] &7Global muted.' diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index 795f5626..6e02b1a7 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -151,6 +151,13 @@ Channel-No-Speak-Permission: sound: 'ENTITY_ITEM_BREAK' volume: 1 pitch: 0 +Channel-Bad-Language: + - type: actionbar + text: '&c你不能骂人哦' + - type: sound + sound: 'ENTITY_ITEM_BREAK' + volume: 1 + pitch: 0 Mute-Muted-Player: '&8[&3Tr&bChat&8] &7你已禁言 {0} {1}.' Mute-Muted-All: '&8[&3Tr&bChat&8] &7全员禁言已开启.' diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index 2cefb170..804e9382 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -4,19 +4,20 @@ Options: Depend-Expansions: ['player', 'server', 'vault'] Prevent-Tab-Complete: false Force-Proxy: ~ + Kether-Allow-Tolerance-Parser: true Database: Method: SQLite SQLite: file: '{plugin_folder}/data/data.db' - table: trchat + table: trchat_user_data SQL: host: localhost port: 3306 user: root password: root database: root - table: trchat + table: trchat_user_data Mongodb: client: 'mongodb://localhost:3307' database: trixey