Skip to content

Commit 58febe0

Browse files
committed
[2.1.0] Update & Fix
1 parent 3acacfd commit 58febe0

File tree

9 files changed

+41
-19
lines changed

9 files changed

+41
-19
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ subprojects {
1919
install(BUKKIT_ALL, BUNGEE, VELOCITY)
2020
}
2121
version {
22-
taboolib = "6.1.1-beta10"
22+
taboolib = "6.1.1-beta18"
2323
coroutines = null
2424
}
2525
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
group=me.arasple.mc.trchat
2-
version=2.0.16
2+
version=2.1.0
33
kotlin.incremental=true
44
kotlin.incremental.java=true
5-
koltin.incremental.useClasspathSnapshot=true
5+
kotlin.incremental.useClasspathSnapshot=true
66
kotlin.caching.enabled=true
77
kotlin.parallel.tasks.in.project=true

plugin/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ dependencies {
2929
tasks {
3030
jar {
3131
// 构件名
32-
archiveFileName.set("${rootProject.name}-${archiveFileName.get().substringAfter('-')}")
32+
archiveBaseName.set(rootProject.name)
3333
// 打包子项目源代码
3434
rootProject.subprojects.forEach { from(it.sourceSets["main"].output) }
3535
}
3636
sourcesJar {
3737
// 构件名
38-
archiveFileName.set("${rootProject.name}-${archiveFileName.get().substringAfter('-')}")
38+
archiveBaseName.set(rootProject.name)
3939
// 打包子项目源代码
4040
rootProject.subprojects.forEach { from(it.sourceSets["main"].allSource) }
4141
}

project/runtime-bukkit/src/main/java/me/arasple/mc/trchat/util/color/HexUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public static String parseHex(String message) {
226226
}
227227

228228
public static String parseLegacy(String message) {
229+
message = message.replace("&r", "&f").replace("§r", "§f");
229230
return ChatColor.translateAlternateColorCodes('&', message);
230231
}
231232

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/api/impl/BukkitComponentManager.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.arasple.mc.trchat.api.impl
22

3+
import com.google.common.cache.Cache
4+
import com.google.common.cache.CacheBuilder
35
import me.arasple.mc.trchat.TrChat
46
import me.arasple.mc.trchat.api.ComponentManager
57
import me.arasple.mc.trchat.api.event.TrChatReceiveEvent
@@ -31,6 +33,10 @@ object BukkitComponentManager : ComponentManager {
3133
@ConfigNode("Enable.Chat", "filter.yml")
3234
var isFilterEnabled = true
3335

36+
private val filteredCache: Cache<ComponentText, ComponentText> = CacheBuilder.newBuilder()
37+
.maximumSize(10)
38+
.build()
39+
3440
init {
3541
PlatformFactory.registerAPI<ComponentManager>(this)
3642
}
@@ -71,7 +77,9 @@ object BukkitComponentManager : ComponentManager {
7177
}
7278

7379
override fun filterComponent(component: ComponentText, maxLength: Int): ComponentText {
74-
return validateComponent(DefaultComponent(listOf(filterComponent(component.toSpigotObject()))), maxLength)
80+
return filteredCache.get(component) {
81+
validateComponent(DefaultComponent(listOf(filterComponent(component.toSpigotObject()))), maxLength)
82+
}
7583
}
7684

7785
override fun validateComponent(component: ComponentText, maxLength: Int): ComponentText {

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object Loader {
160160
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
161161
Format(condition, priority, prefix, msg, suffix)
162162
}.sortedBy { it.priority }
163-
val console = conf.getMapList("Console").firstOrNull()?.let { map ->
163+
val console = conf.getMapList("Console").map { map ->
164164
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
165165
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
166166
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
@@ -177,7 +177,7 @@ object Loader {
177177
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
178178
Format(condition, priority, prefix, msg, suffix)
179179
}.sortedBy { it.priority }
180-
val console = conf.getMapList("Console").firstOrNull()?.let { map ->
180+
val console = conf.getMapList("Console").map { map ->
181181
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
182182
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
183183
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/Channel.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ open class Channel(
3535
val bindings: ChannelBindings,
3636
val events: ChannelEvents,
3737
val formats: List<Format>,
38-
val consoleFormat: Format? = null
38+
val consoleFormat: List<Format>
3939
) {
4040

4141
val listeners: MutableSet<String> = mutableSetOf()
@@ -102,7 +102,7 @@ open class Channel(
102102
return execute(sender, message)
103103
}
104104
val component = Components.empty()
105-
consoleFormat?.let { format ->
105+
consoleFormat.firstOrNull()?.let { format ->
106106
format.prefix.forEach { prefix ->
107107
component.append(prefix.value[0].content.toTextComponent(sender)) }
108108
component.append(format.msg.createComponent(sender, message, settings.disabledFunctions))

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/PrivateChannel.kt

+21-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PrivateChannel(
4040
events: ChannelEvents,
4141
val sender: List<Format>,
4242
val receiver: List<Format>,
43-
consoleFormat: Format?
43+
consoleFormat: List<Format>
4444
) : Channel(id, settings, bindings, events, emptyList(), consoleFormat) {
4545

4646
var consolePrivateTo: String? = null
@@ -104,13 +104,26 @@ class PrivateChannel(
104104
}
105105
val to = consolePrivateTo ?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_RECEIVER)
106106
val component = Components.empty()
107-
consoleFormat?.let { format ->
108-
format.prefix.forEach { prefix ->
109-
component.append(prefix.value[0].content.toTextComponent(sender)) }
110-
component.append(format.msg.createComponent(sender, message, settings.disabledFunctions))
111-
format.suffix.forEach { suffix ->
112-
component.append(suffix.value[0].content.toTextComponent(sender)) }
113-
} ?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
107+
val toPlayer = Bukkit.getPlayer(to)
108+
if (toPlayer?.isOnline == true) {
109+
consoleFormat.firstOrNull { it.condition.pass(toPlayer) }?.let { format ->
110+
format.prefix
111+
.mapNotNull { prefix -> prefix.value.firstOrNull { it.condition.pass(toPlayer) }?.content?.toTextComponent(toPlayer) }
112+
.forEach { prefix -> component.append(prefix) }
113+
component.append(format.msg.createComponent(toPlayer, message, settings.disabledFunctions))
114+
format.suffix
115+
.mapNotNull { suffix -> suffix.value.firstOrNull { it.condition.pass(toPlayer) }?.content?.toTextComponent(toPlayer) }
116+
.forEach { suffix -> component.append(suffix) }
117+
} ?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
118+
} else {
119+
consoleFormat.firstOrNull()?.let { format ->
120+
format.prefix.forEach { prefix ->
121+
component.append(prefix.value[0].content.toTextComponent(sender)) }
122+
component.append(format.msg.createComponent(sender, message, settings.disabledFunctions))
123+
format.suffix.forEach { suffix ->
124+
component.append(suffix.value[0].content.toTextComponent(sender)) }
125+
} ?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
126+
}
114127

115128
console().sendComponent(null, component)
116129
if (settings.proxy && BukkitProxyManager.processor != null) {

project/runtime-bukkit/src/main/resources/channels/Private.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Receiver:
2323
default-color: 'f'
2424
hover: '&7日期: %server_time_HH:mm:ss%'
2525

26-
# Can't use placeholders!
26+
# Placeholders & Conditions are available only when not proxy!
2727
Console:
2828
- prefix:
2929
server:

0 commit comments

Comments
 (0)