Skip to content

Commit

Permalink
[2.0.11] Fix
Browse files Browse the repository at this point in the history
* Fix #314
* Fix #338
  • Loading branch information
ItsFlicker committed Jan 7, 2024
1 parent a608c61 commit 096b7e6
Show file tree
Hide file tree
Showing 28 changed files with 106 additions and 123 deletions.
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
}

repositories {
mavenLocal()
mavenCentral()
}

subprojects {
apply<JavaPlugin>()
apply(plugin = "org.jetbrains.kotlin.jvm")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
group=me.arasple.mc.trchat
version=2.0.10
taboolib_version=6.0.12-55
version=2.0.11
taboolib_version=6.0.12-local
kotlin.incremental=true
kotlin.incremental.java=true
koltin.incremental.useClasspathSnapshot=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import java.net.URL
import java.nio.charset.StandardCharsets
import java.util.*

/**
* @author Arasple
* @date 2019/11/29 21:04
*/
@SkipTo(LifeCycle.LOAD)
object Updater {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ package me.arasple.mc.trchat.util
import java.util.*
import java.util.concurrent.ConcurrentHashMap

/**
* @author ItsFlicker
* @since 2022/3/5 14:09
*/
object Cooldowns {

private val COOLDOWNS = ConcurrentHashMap<UUID, Cooldown>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import taboolib.common.util.asList
import taboolib.library.configuration.Converter
import java.util.*

/**
* Util
* me.arasple.mc.trchat.util
*
* @author ItsFlicker
* @since 2021/9/12 18:11
*/
private val jsonParser = JsonParser()
private val reportedErrors = mutableListOf<String>()
val nilUUID = UUID(0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ abstract class NMS {

abstract fun sendMessage(receiver: Player, component: ComponentText, sender: UUID?)

abstract fun hoverItem(component: ComponentText, itemStack: ItemStack): ComponentText

abstract fun optimizeNBT(itemStack: ItemStack, nbtWhitelist: Array<String> = whitelistTags): ItemStack

abstract fun addCustomChatCompletions(player: Player, entries: List<String>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ class NMSImpl : NMS() {
}
}

override fun hoverItem(component: ComponentText, itemStack: ItemStack): ComponentText {
val nmsItem = CraftItemStack19.asNMSCopy(itemStack)
val nbtTag = NBTTagCompound19()
nmsItem.save(nbtTag)
val id = nbtTag.getString("id") ?: "minecraft:air"
val nbt = nbtTag.get("tag")?.toString() ?: "{}"
return component.hoverItem(id, nbt)
}

override fun optimizeNBT(itemStack: ItemStack, nbtWhitelist: Array<String>): ItemStack {
if (itemStack.isAir()) return itemStack
try {
Expand Down
4 changes: 2 additions & 2 deletions project/runtime-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ dependencies {
compileOnly("ink.ptms.core:v12004:12004:universal")
compileOnly("net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT")

compileOnly("com.discordsrv:discordsrv:1.26.0")
compileOnly("me.clip:placeholderapi:2.11.3") { isTransitive = false }
compileOnly("com.discordsrv:discordsrv:1.26.0") { isTransitive = false }
compileOnly("com.willfp:eco:6.35.1") { isTransitive = false }
compileOnly("com.github.LoneDev6:api-itemsadder:3.5.0b") { isTransitive = false }
compileOnly("com.github.LoneDev6:api-itemsadder:3.6.2-beta-r3-b") { isTransitive = false }
compileOnly("xyz.xenondevs.nova:nova-api:0.12.13") { isTransitive = false }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,8 @@ object BukkitProxyManager : ClientMessageManager {
)
}

fun sendRaw(recipient: Any?, to: String, component: ComponentText, doubleTransfer: Boolean) {
sendMessage(recipient, arrayOf(
"SendRaw",
to,
component.toRawMessage(),
doubleTransfer.toString())
)
fun sendPrivateRaw(recipient: Any?, to: String, from: String, component: ComponentText) {
sendMessage(recipient, arrayOf("ForwardMessage", "SendPrivateRaw", to, from, component.toRawMessage()))
}

fun updateNames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ object Loader {
val filterBeforeSending = section.getBoolean("Filter-Before-Sending", false)
val sendToDiscord = section.getBoolean("Send-To-Discord", !isPrivate)
val receiveFromDiscord = section.getBoolean("Receive-From-Discord", true)
val discordChannel = section.getString("Discord-Channel", "")!!
ChannelSettings(
joinPermission, speakCondition, autoJoin, isPrivate,
range, proxy, forceProxy, doubleTransfer, ports, disabledFunctions, filterBeforeSending,
sendToDiscord, receiveFromDiscord
sendToDiscord, receiveFromDiscord, discordChannel
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import me.arasple.mc.trchat.module.display.channel.obj.ChannelSettings
import me.arasple.mc.trchat.module.display.channel.obj.Range
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.hook.HookPlugin
import me.arasple.mc.trchat.module.internal.service.Metrics
import me.arasple.mc.trchat.util.*
import org.bukkit.command.CommandSender
Expand Down Expand Up @@ -155,7 +156,13 @@ open class Channel(
session.cancelChat = false
return null
}
// TODO: 跨服事件传递
if (settings.sendToDiscord) {
HookPlugin.getDiscordSRV().sendMessage(
player,
TrChat.api().getFilterManager().filter(component.toLegacyText(), adaptPlayer(player)).filtered,
settings.discordChannel.takeIf { it.isNotEmpty() }
)
}
// Proxy
if (settings.proxy) {
if (BukkitProxyManager.processor != null || settings.forceProxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ class PrivateChannel(
}
dynamic("player", optional = true) {
suggest {
BukkitProxyManager.getPlayerNames().keys.filter { it !in PlayerData.vanishing }
BukkitProxyManager.getPlayerNames().flatMap { (key, value) ->
if (key !in PlayerData.vanishing) {
if (value == null || key == value) listOf(key) else listOf(key, value)
}
else emptyList()
}
}
execute<Player> { sender, _, argument ->
sender.session.lastPrivateTo = BukkitProxyManager.getExactName(argument)
Expand Down Expand Up @@ -154,11 +159,11 @@ class PrivateChannel(
Metrics.increase(0)

if (settings.proxy && BukkitProxyManager.processor != null) {
BukkitProxyManager.sendRaw(
BukkitProxyManager.sendPrivateRaw(
player,
to,
receive,
settings.doubleTransfer
player.name,
receive
)
BukkitProxyManager.sendProxyLang(player, to, "Private-Message-Receive", player.name)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ class ChannelSettings(
val disabledFunctions: List<String> = emptyList(),
val filterBeforeSending: Boolean = false,
val sendToDiscord: Boolean = true,
val receiveFromDiscord: Boolean = true
val receiveFromDiscord: Boolean = true,
val discordChannel: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ class MsgComponent(val defaultColor: List<Pair<CustomColor, Condition?>>, style:
val component = Components.empty()
var message = msg

// 非玩家 不处理functions
if (sender !is Player) {
val defaultColor = defaultColor[0].first
return toTextComponent(sender, defaultColor.colored(sender, message))
}

// 创建{{xxx:xxx}}
Function.functions.filter { it.alias !in disabledFunctions && it.canUse(sender) }.forEach {
message = it.createVariable(sender, message)
}

val defaultColor = sender.session.getColor(defaultColor.firstOrNull { it.second.pass(sender) }?.first)

// 分割为多个ComponentText
for (part in parser.readToFlatten(message)) {
if (part.isVariable) {
val args = part.text.split(":", limit = 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Text(val content: String, val condition: Condition?) {
if (dynamic) {
text = text.setPlaceholders(sender)
}
text = HookPlugin.getItemsAdder().replaceFontImages(text, sender as? Player)
text = HookPlugin.getItemsAdder().replaceFontImages(text, null)
}
return Components.text(text.replaceWithOrder(*vars).colorify())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.BlockStateMeta
import taboolib.common.UnsupportedVersionException
import taboolib.common.io.digest
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
Expand All @@ -31,9 +32,7 @@ import taboolib.module.chat.Components
import taboolib.module.chat.impl.DefaultComponent
import taboolib.module.configuration.ConfigNode
import taboolib.module.configuration.ConfigNodeTransfer
import taboolib.module.nms.MinecraftVersion
import taboolib.module.nms.getI18nName
import taboolib.module.nms.getLocaleKey
import taboolib.module.nms.*
import taboolib.module.ui.buildMenu
import taboolib.module.ui.type.Basic
import taboolib.module.ui.type.Linked
Expand Down Expand Up @@ -101,16 +100,14 @@ object ItemShow : Function("ITEM") {

override fun parseVariable(sender: Player, arg: String): ComponentText? {
val item = sender.inventory.getItem(arg.toInt() - 1) ?: ItemStack(Material.AIR)
val newItem = (item).let {
if (compatible) {
buildItem(it) { material = Material.STONE }
} else {
var newItem = it.clone()
HookPlugin.registry.filterIsInstance(HookDisplayItem::class.java).forEach { element ->
newItem = element.displayItem(newItem, sender)
}
newItem
val newItem = if (compatible) {
buildItem(item) { material = Material.STONE }
} else {
var newItem = item.clone()
HookPlugin.registry.filterIsInstance<HookDisplayItem>().forEach { element ->
newItem = element.displayItem(newItem, sender)
}
newItem
}

return cacheComponent.get(newItem) {
Expand All @@ -126,25 +123,23 @@ object ItemShow : Function("ITEM") {
)
it.first
}
sender
.getComponentFromLang("Function-Item-Show-Format-With-Hopper", newItem.amount, sha1) { type, i, part, proxySender ->
val component = if (part.isVariable && part.text == "item") {
newItem.getNameComponent(sender)
} else {
Components.text(part.text.translate(proxySender).replaceWithOrder(newItem.amount, sha1))
}
component.applyStyle(type, part, i, proxySender, newItem.amount, sha1).hoverItemFixed(newItem)
sender.getComponentFromLang("Function-Item-Show-Format-With-Hopper", newItem.amount, sha1) { type, i, part, proxySender ->
val component = if (part.isVariable && part.text == "item") {
item.getNameComponent(sender)
} else {
Components.text(part.text.translate(proxySender).replaceWithOrder(newItem.amount, sha1))
}
component.applyStyle(type, part, i, proxySender, newItem.amount, sha1).hoverItemFixed(newItem)
}
} else {
sender
.getComponentFromLang("Function-Item-Show-Format-New", newItem.amount) { type, i, part, proxySender ->
val component = if (part.isVariable && part.text == "item") {
item.getNameComponent(sender)
} else {
Components.text(part.text.translate(proxySender).replaceWithOrder(newItem.amount))
}
component.applyStyle(type, part, i, proxySender, newItem.amount).hoverItemFixed(newItem)
sender.getComponentFromLang("Function-Item-Show-Format-New", newItem.amount) { type, i, part, proxySender ->
val component = if (part.isVariable && part.text == "item") {
item.getNameComponent(sender)
} else {
Components.text(part.text.translate(proxySender).replaceWithOrder(newItem.amount))
}
component.applyStyle(type, part, i, proxySender, newItem.amount).hoverItemFixed(newItem)
}
}
}
}
Expand Down Expand Up @@ -202,10 +197,14 @@ object ItemShow : Function("ITEM") {
@Suppress("Deprecation")
private fun ItemStack.getNameComponent(player: Player): ComponentText {
return if (originName || itemMeta?.hasDisplayName() != true) {
if (MinecraftVersion.major >= 7) {
Components.empty().appendTranslation(getLocaleKey().path)
} else {
Components.text(getI18nName(player))
try {
if (MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_15)) {
Components.translation(getLocaleKey().path)
} else {
Components.text(getI18nName(player))
}
} catch (_: UnsupportedVersionException) {
Components.text(nmsProxy<NMSItem>().getKey(this))
}
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ object CommandReply {
dynamic("message") {
execute<Player> { sender, _, argument ->
val session = sender.session
if (sender.checkMute()) {
if (lastMessageFrom.containsKey(sender.name)) {
val to = BukkitProxyManager.getExactName(lastMessageFrom[sender.name]!!)
?: return@execute sender.sendLang("Command-Player-Not-Exist")
session.lastPrivateTo = to
Channel.channels.values
.firstOrNull { it is PrivateChannel && sender.passPermission(it.settings.joinPermission) }
?.execute(sender, argument)
}
if (!sender.checkMute()) {
return@execute
}
if (!lastMessageFrom.containsKey(sender.name)) {
return@execute sender.sendLang("Command-Player-Not-Exist")
}
val to = BukkitProxyManager.getExactName(lastMessageFrom[sender.name]!!)
?: return@execute sender.sendLang("Command-Player-Not-Exist")
session.lastPrivateTo = to
Channel.channels.values
.firstOrNull { it is PrivateChannel && sender.passPermission(it.settings.joinPermission) }
?.execute(sender, argument)
}
}
incorrectSender { sender, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ object HookPlaceholderAPI : PlaceholderExpansion {
val session = player.session
val data = player.data
return when (params[0].lowercase()) {
// "js" -> if (params.size > 1) JavaScriptAgent.eval(player, args.substringAfter('_')).get() else ""
"channel" -> session.channel
"lastpublicmessage", "lastmessage" -> {
if (params.getOrNull(1) == "uncolored") session.lastPublicMessage.uncolored()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import github.scarsz.discordsrv.DiscordSRV
import github.scarsz.discordsrv.api.Subscribe
import github.scarsz.discordsrv.api.events.DiscordGuildMessagePreBroadcastEvent
import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent
import me.arasple.mc.trchat.TrChat
import me.arasple.mc.trchat.module.internal.hook.HookAbstract
import me.arasple.mc.trchat.util.session
import org.bukkit.entity.Player
import taboolib.common.platform.function.adaptPlayer

class HookDiscordSRV : HookAbstract() {

Expand All @@ -17,10 +15,7 @@ class HookDiscordSRV : HookAbstract() {
DiscordSRV.api.subscribe(object {
@Subscribe
fun onChatPreProcess(e: GameChatMessagePreProcessEvent) {
val channel = e.player.session.lastChannel ?: return
if (channel.settings.sendToDiscord) {
e.message = TrChat.api().getFilterManager().filter(e.message, adaptPlayer(e.player)).filtered
} else {
if (e.player.session.lastChannel != null && e.triggeringBukkitEvent != null) {
e.isCancelled = true
}
}
Expand All @@ -33,4 +28,14 @@ class HookDiscordSRV : HookAbstract() {
})
}

fun sendMessage(player: Player, message: String, channel: String?) {
if (!isHooked) return
DiscordSRV.getPlugin().processChatMessage(
player,
message,
channel,
false
)
}

}
Loading

0 comments on commit 096b7e6

Please sign in to comment.