Skip to content

Commit

Permalink
+ [2.0.0-PRE-5] Improve Kether & Fix legacy eco hook & Support filter…
Browse files Browse the repository at this point in the history
… before sending
  • Loading branch information
ItsFlicker committed Apr 23, 2022
1 parent d9e54d5 commit b7ab826
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down Expand Up @@ -47,12 +47,12 @@ configure<org.tabooproject.shrinkingkt.ShrinkingExt> {
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=me.arasple.mc.trchat
version=2.0.0-PRE-4
version=2.0.0-PRE-5
1 change: 1 addition & 0 deletions src/main/kotlin/me/arasple/mc/trchat/TrChat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object TrChat : Plugin() {
Util.init()
}


Database.init()

Loader.loadChannels(console())
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/me/arasple/mc/trchat/api/config/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,6 +34,7 @@ open class Channel(
val settings: ChannelSettings,
val bindings: ChannelBindings,
val formats: List<Format>,
val console: Format? = null
) {

init {
Expand All @@ -46,8 +48,41 @@ open class Channel(
}
}
dynamic("message", optional = true) {
execute<Player> { sender, _, argument ->
execute(sender, argument)
execute<CommandSender> { 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, _ ->
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class ChannelSettings(
val autoJoin: Boolean,
val proxy: Boolean,
val ports: List<Int>?,
val disabledFunctions: List<String>
val disabledFunctions: List<String>,
val filterBeforeSending: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,8 +42,6 @@ object CommandHandler {
Functions.CONF.reload()
Filters.CONF.reload()
Loader.loadChannels(sender)
Loader.loadFunctions(sender)
ChatFilter.loadFilter(true, sender)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ActionChannel(val symbol: Symbol, val channel: String?): ScriptAction<Void

companion object {

@KetherParser(["channel"], namespace = "trchat")
@KetherParser(["channel"], namespace = "trchat", shared = true)
fun parser() = scriptParser {
val symbol = when(val type = it.nextToken().lowercase()) {
"join" -> Symbol.JOIN
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void>() {

override fun run(frame: ScriptFrame): CompletableFuture<Void> {
val s = frame.script()
if (s.sender == null) {
error("No sender selected.")
}
frame.newFrame(server).run<Any>().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))
}
}
}
19 changes: 18 additions & 1 deletion src/main/resources/channels/Global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,21 @@ Formats:
text: '&e%player_name%&8: '
msg:
default-color: 'f'
hover: '&7Date: %server_time_HH:mm:ss%'
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%'
7 changes: 7 additions & 0 deletions src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/lang/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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全员禁言已开启.'
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7ab826

Please sign in to comment.