Skip to content

Commit

Permalink
[2.1.2] Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFlicker committed Jun 10, 2024
1 parent d3d059b commit 7413581
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 68 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ subprojects {
install(BUKKIT_ALL, BUNGEE, VELOCITY)
}
version {
taboolib = "6.1.1"
taboolib = "6.1.2-beta4"
coroutines = null
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=me.arasple.mc.trchat
version=2.1.1
version=2.1.2
kotlin.incremental=true
kotlin.incremental.java=true
kotlin.incremental.useClasspathSnapshot=true
Expand Down
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ taboolib {
name("ItemsAdder").with("bukkit").optional(true)
name("Nova").with("bukkit").optional(true)
name("Multiverse-Core").with("bukkit").loadafter(true)
name("Geyser-Spigot").with("bukkit").loadafter(true)
}
}
relocate("com.eatthepath.uuid.", "${rootProject.group}.library.uuid.")
Expand Down
2 changes: 1 addition & 1 deletion project/module-compat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repositories {

dependencies {
compileOnly(project(":project:common"))
compileOnly("ink.ptms.core:v12004:12004:universal")
compileOnly("ink.ptms.core:v12005:12005:universal")

compileOnly("com.discordsrv:discordsrv:1.26.0") { isTransitive = false }
compileOnly("com.willfp:eco:6.35.1") { isTransitive = false }
Expand Down
1 change: 1 addition & 0 deletions project/module-nms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
compileOnly(project(":project:common"))
// compileOnly("ink.ptms.core:v12005:12005:mapped")
compileOnly("ink.ptms.core:v12004:12004:mapped")
compileOnly("ink.ptms.core:v12002:12002:mapped")
compileOnly("ink.ptms.core:v11903:11903:mapped")
Expand Down
2 changes: 1 addition & 1 deletion project/runtime-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {
compileOnly(project(":project:module-adventure"))
compileOnly(project(":project:module-compat"))
compileOnly(project(":project:module-nms"))
compileOnly("ink.ptms.core:v12004:12004:universal")
compileOnly("ink.ptms.core:v12005:12005:universal")
compileOnly("net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT")
compileOnly(fileTree(rootDir.resolve("libs")))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,17 @@ public static String parseGradients(String message) {
}

public static String parseHex(String message) {
if (BukkitUtilKt.isDragonCoreHooked())
return message;

String parsed = message;

for (Pattern pattern : HEX_PATTERNS) {
Matcher matcher = pattern.matcher(parsed);
while (matcher.find()) {
String color = translateHex(cleanHex(matcher.group())).toString();
String color;
if (BukkitUtilKt.isDragonCoreHooked()) {
color = '§' + cleanHex(matcher.group());
} else {
color = translateHex(cleanHex(matcher.group())).toString();
}
String before = parsed.substring(0, matcher.start());
String after = parsed.substring(matcher.end());
parsed = before + color + after;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.arasple.mc.trchat.api.event

import org.bukkit.entity.Player
import taboolib.platform.type.BukkitProxyEvent

class TrChatMentionEvent(
val sender: Player,
val receiver: String
) : BukkitProxyEvent() {

override val allowCancelled: Boolean
get() = true

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,21 @@ object Loader {
val condition = map["condition"]?.toString()?.toCondition()
val priority = Coerce.asInteger(map["priority"]).orNull() ?: 100
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
val msg = parseGroup(map["msg"], isMsg = true)
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
Format(condition, priority, prefix, msg, suffix)
}.sortedBy { it.priority }
val receiver = conf.getMapList("Receiver").map { map ->
val condition = map["condition"]?.toString()?.toCondition()
val priority = Coerce.asInteger(map["priority"]).orNull() ?: 100
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
val msg = parseGroup(map["msg"], isMsg = true)
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
Format(condition, priority, prefix, msg, suffix)
}.sortedBy { it.priority }
val console = conf.getMapList("Console").map { map ->
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
val msg = parseGroup(map["msg"], isMsg = true)
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
Format(null, 100, prefix, msg, suffix)
}
Expand All @@ -173,13 +173,13 @@ object Loader {
val condition = map["condition"]?.toString()?.toCondition()
val priority = Coerce.asInteger(map["priority"]).orNull() ?: 100
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
val msg = parseGroup(map["msg"], isMsg = true)
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
Format(condition, priority, prefix, msg, suffix)
}.sortedBy { it.priority }
val console = conf.getMapList("Console").map { map ->
val prefix = parseGroups(map["prefix"] as LinkedHashMap<*, *>)
val msg = parseMsg(map["msg"] as LinkedHashMap<*, *>)
val msg = parseGroup(map["msg"], isMsg = true)
val suffix = parseGroups(map["suffix"] as? LinkedHashMap<*, *>)
Format(null, 100, prefix, msg, suffix)
}
Expand All @@ -200,7 +200,7 @@ object Loader {
val priority = map.getInt("priority", 100)
val regex = map.getString("pattern")!!.toRegex()
val filterTextRegex = map.getString("text-filter")?.toRegex()
val displayJson = parseJSON(map.getConfigurationSection("display")!!.toMap())
val displayJson = parseJSON(map.getConfigurationSection("display")!!.toMap(), isMsg = false)
val reaction = map["action"]?.let { Reaction(it.asList()) }

CustomFunction(id, condition, priority, regex, filterTextRegex, displayJson, reaction)
Expand All @@ -209,44 +209,29 @@ object Loader {
Function.reload(functions)
}

private fun parseGroups(map: LinkedHashMap<*, *>?): Map<String, List<Group>> {
map ?: return emptyMap()
return map.map { (id, content) ->
id as String
when (content) {
is Map<*, *> -> {
val condition = content["condition"]?.toString()?.toCondition()
id to listOf(Group(condition, 100, parseJSON(content)))
}
is List<*> -> {
id to content.map {
it as LinkedHashMap<*, *>
val condition = it["condition"]?.toString()?.toCondition()
val priority = Coerce.asInteger(map["priority"]).orNull() ?: 100
Group(condition, priority, parseJSON(it))
}.sortedBy { it.priority }
}
else -> error("Unexpected group: $content")
}
}.toMap()
private fun parseGroups(map: LinkedHashMap<*, *>?, isMsg: Boolean = false): Map<String, List<Group>> {
return map?.map { (id, content) -> (id as String) to parseGroup(content, isMsg) }?.toMap() ?: emptyMap()
}

private fun parseJSON(content: Map<*, *>): JsonComponent {
val text = Property.serialize(content["text"] ?: "null").map { Text(it.first, it.second.getCondition()) }
val style = mutableListOf<Style?>()
style += content["hover"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Hover.Text(it) }
style += content["suggest"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.Suggest(it) }
style += content["command"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.Command(it) }
style += content["url"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.Url(it) }
style += content["copy"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.Copy(it) }
style += content["file"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.File(it) }
style += content["insertion"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Insertion(it) }
style += content["font"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Font(it) }
return JsonComponent(text, style.filterNotNull())
private fun parseGroup(content: Any?, isMsg: Boolean = false): List<Group> {
return when (content) {
is Map<*, *> -> {
val condition = content["condition"]?.toString()?.toCondition()
listOf(Group(condition, 100, parseJSON(content, isMsg)))
}
is List<*> -> {
content.map {
it as LinkedHashMap<*, *>
val condition = it["condition"]?.toString()?.toCondition()
val priority = Coerce.asInteger(it["priority"]).orNull() ?: 100
Group(condition, priority, parseJSON(it, isMsg))
}.sortedBy { it.priority }
}
else -> error("Unexpected group: $content")
}
}

private fun parseMsg(content: Map<*, *>): MsgComponent {
val defaultColor = content["default-color"]!!.serialize().map { CustomColor.get(it.first) to it.second.getCondition() }
private fun parseJSON(content: Map<*, *>, isMsg: Boolean = false): JsonComponent {
val style = mutableListOf<Style?>()
style += content["hover"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Hover.Text(it) }
style += content["suggest"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.Suggest(it) }
Expand All @@ -256,7 +241,13 @@ object Loader {
style += content["file"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Click.File(it) }
style += content["insertion"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Insertion(it) }
style += content["font"]?.serialize()?.map { it.first to it.second.getCondition() }?.let { Style.Font(it) }
return MsgComponent(defaultColor, style.filterNotNull())
return if (isMsg) {
val defaultColor = content["default-color"]!!.serialize().map { CustomColor.get(it.first) to it.second.getCondition() }
MsgComponent(defaultColor, style.filterNotNull())
} else {
val text = Property.serialize(content["text"] ?: "null").map { Text(it.first, it.second.getCondition()) }
JsonComponent(text, style.filterNotNull())
}
}

private fun filterChannelFiles(file: File): List<File> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import me.arasple.mc.trchat.api.impl.BukkitProxyManager
import me.arasple.mc.trchat.module.conf.file.Settings
import me.arasple.mc.trchat.module.display.channel.obj.*
import me.arasple.mc.trchat.module.display.format.Format
import me.arasple.mc.trchat.module.display.format.MsgComponent
import me.arasple.mc.trchat.module.display.function.Function
import me.arasple.mc.trchat.module.internal.data.ChatLogs
import me.arasple.mc.trchat.module.internal.service.Metrics
Expand Down Expand Up @@ -105,7 +106,7 @@ open class Channel(
consoleFormat.firstOrNull()?.let { format ->
format.prefix.forEach { prefix ->
component.append(prefix.value[0].content.toTextComponent(sender)) }
component.append(format.msg.createComponent(sender, message, settings.disabledFunctions))
component.append((format.msg[0].content as MsgComponent).createComponent(sender, message, settings.disabledFunctions))
format.suffix.forEach { suffix ->
component.append(suffix.value[0].content.toTextComponent(sender)) }
} ?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
Expand Down Expand Up @@ -147,7 +148,9 @@ open class Channel(
format.prefix
.mapNotNull { prefix -> prefix.value.firstOrNull { it.condition.pass(player) }?.content?.toTextComponent(player) }
.forEach { prefix -> component.append(prefix) }
component.append(format.msg.createComponent(player, msg, settings.disabledFunctions))
format.msg.firstOrNull { it.condition.pass(player) }
?.let { component.append((it.content as MsgComponent).createComponent(player, msg, settings.disabledFunctions)) }
?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
format.suffix
.mapNotNull { suffix -> suffix.value.firstOrNull { it.condition.pass(player) }?.content?.toTextComponent(player) }
.forEach { suffix -> component.append(suffix) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import me.arasple.mc.trchat.module.display.channel.obj.ChannelEvents
import me.arasple.mc.trchat.module.display.channel.obj.ChannelExecuteResult
import me.arasple.mc.trchat.module.display.channel.obj.ChannelSettings
import me.arasple.mc.trchat.module.display.format.Format
import me.arasple.mc.trchat.module.display.format.MsgComponent
import me.arasple.mc.trchat.module.internal.command.main.CommandReply
import me.arasple.mc.trchat.module.internal.data.ChatLogs
import me.arasple.mc.trchat.module.internal.data.PlayerData
Expand All @@ -23,7 +24,6 @@ import taboolib.common.platform.command.suggest
import taboolib.common.platform.function.console
import taboolib.common.platform.function.getProxyPlayer
import taboolib.common.util.subList
import taboolib.module.chat.ComponentText
import taboolib.module.chat.Components
import taboolib.module.lang.sendLang
import taboolib.platform.util.onlinePlayers
Expand Down Expand Up @@ -105,7 +105,9 @@ class PrivateChannel(
format.prefix
.mapNotNull { prefix -> prefix.value.firstOrNull { it.condition.pass(toPlayer) }?.content?.toTextComponent(toPlayer) }
.forEach { prefix -> component.append(prefix) }
component.append(format.msg.createComponent(toPlayer, message, settings.disabledFunctions))
format.msg.firstOrNull { it.condition.pass(toPlayer) }
?.let { component.append((it.content as MsgComponent).createComponent(toPlayer, message, settings.disabledFunctions)) }
?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
format.suffix
.mapNotNull { suffix -> suffix.value.firstOrNull { it.condition.pass(toPlayer) }?.content?.toTextComponent(toPlayer) }
.forEach { suffix -> component.append(suffix) }
Expand All @@ -114,7 +116,7 @@ class PrivateChannel(
consoleFormat.firstOrNull()?.let { format ->
format.prefix.forEach { prefix ->
component.append(prefix.value[0].content.toTextComponent(sender)) }
component.append(format.msg.createComponent(sender, message, settings.disabledFunctions))
component.append((format.msg[0].content as MsgComponent).createComponent(sender, message, settings.disabledFunctions))
format.suffix.forEach { suffix ->
component.append(suffix.value[0].content.toTextComponent(sender)) }
} ?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
Expand Down Expand Up @@ -159,13 +161,15 @@ class PrivateChannel(
?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.EVENT)

val send = Components.empty()
var msgComponent: ComponentText? = null
val msgComponent = Components.empty()
sender.firstOrNull { it.condition.pass(player) }?.let { format ->
format.prefix
.mapNotNull { prefix -> prefix.value.firstOrNull { it.condition.pass(player) }?.content?.toTextComponent(player) }
.forEach { prefix -> send.append(prefix) }
msgComponent = format.msg.createComponent(player, msg, settings.disabledFunctions)
send.append(msgComponent!!)
format.msg.firstOrNull { it.condition.pass(player) }
?.let { msgComponent.append((it.content as MsgComponent).createComponent(player, msg, settings.disabledFunctions)) }
?: return ChannelExecuteResult(failedReason = ChannelExecuteResult.FailReason.NO_FORMAT)
send.append(msgComponent)
format.suffix
.mapNotNull { suffix -> suffix.value.firstOrNull { it.condition.pass(player) }?.content?.toTextComponent(player) }
.forEach { suffix -> send.append(suffix) }
Expand All @@ -176,7 +180,7 @@ class PrivateChannel(
format.prefix
.mapNotNull { prefix -> prefix.value.firstOrNull { it.condition.pass(player) }?.content?.toTextComponent(player) }
.forEach { prefix -> receive.append(prefix) }
receive.append(msgComponent!!)
receive.append(msgComponent)
format.suffix
.mapNotNull { suffix -> suffix.value.firstOrNull { it.condition.pass(player) }?.content?.toTextComponent(player) }
.forEach { suffix -> receive.append(suffix) }
Expand All @@ -194,9 +198,9 @@ class PrivateChannel(

PlayerData.spying.forEach {
Bukkit.getPlayer(it)
?.sendLang("Private-Message-Spy-Format", player.name, to, msgComponent!!.toLegacyText())
?.sendLang("Private-Message-Spy-Format", player.name, to, msgComponent.toLegacyText())
}
console().sendLang("Private-Message-Spy-Format", player.name, to, msgComponent!!.toLegacyText())
console().sendLang("Private-Message-Spy-Format", player.name, to, msgComponent.toLegacyText())

CommandReply.lastMessageFrom[to] = player.name
ChatLogs.logPrivate(player.name, to, message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class Format(
val condition: Condition?,
val priority: Int,
val prefix: Map<String, List<Group>>,
val msg: MsgComponent,
val msg: List<Group>,
val suffix: Map<String, List<Group>>
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import me.arasple.mc.trchat.module.internal.hook.HookPlugin
import me.arasple.mc.trchat.module.internal.script.Condition
import me.arasple.mc.trchat.module.internal.script.kether.KetherHandler
import me.arasple.mc.trchat.util.color.colorify
import me.arasple.mc.trchat.util.isDragonCoreHooked
import me.arasple.mc.trchat.util.papiRegex
import me.arasple.mc.trchat.util.setPlaceholders
import net.md_5.bungee.api.chat.TextComponent
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import taboolib.common.util.replaceWithOrder
import taboolib.module.chat.ComponentText
import taboolib.module.chat.Components
import taboolib.module.chat.impl.DefaultComponent

/**
* @author ItsFlicker
Expand All @@ -28,6 +31,10 @@ class Text(val content: String, val condition: Condition?) {
}
text = HookPlugin.getItemsAdder().replaceFontImages(text, null)
}
return Components.text(text.replaceWithOrder(*vars).colorify())
return if (isDragonCoreHooked) {
DefaultComponent(listOf(TextComponent(text.replaceWithOrder(*vars).colorify())))
} else {
Components.text(text.replaceWithOrder(*vars).colorify())
}
}
}
Loading

0 comments on commit 7413581

Please sign in to comment.