Skip to content

Commit

Permalink
[2.0.15] Fix Folia & Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFlicker committed Mar 10, 2024
1 parent 9ca6019 commit 0284bb8
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 63 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ subprojects {
env {
install(UNIVERSAL, DATABASE, KETHER, METRICS, NMS_UTIL, UI)
install(EXPANSION_REDIS, EXPANSION_JAVASCRIPT, EXPANSION_PLAYER_DATABASE)
install(BUKKIT_ALL, BUNGEE, VELOCITY, "platform-bukkit-impl")
install(BUKKIT_ALL, BUNGEE, VELOCITY)
}
version {
taboolib = "6.1.1-beta4"
taboolib = "6.1.1-beta7"
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.0.14
version=2.0.15
kotlin.incremental=true
kotlin.incremental.java=true
koltin.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 @@ -19,6 +19,7 @@ taboolib {
}
}
relocate("com.eatthepath.uuid.", "${rootProject.group}.library.uuid.")
relocate("com.electronwill.nightconfig", "com.electronwill.nightconfig_3_6_7")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.arasple.mc.trchat.util;

public class ServerUtil {

public static boolean isModdedServer = false;

static {
try {
Class.forName("catserver.server.CatServerLaunch");
isModdedServer = true;
} catch (Throwable ignored) {
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.arasple.mc.trchat.api.nms

import me.arasple.mc.trchat.util.ServerUtil
import me.arasple.mc.trchat.util.reportOnce
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket
import net.minecraft.server.v1_12_R1.ChatMessageType
Expand Down Expand Up @@ -60,7 +61,7 @@ class NMSImpl : NMS() {
}

override fun sendMessage(receiver: Player, component: ComponentText, sender: UUID?) {
if (Folia.isFolia) {
if (Folia.isFolia || ServerUtil.isModdedServer) {
component.sendTo(adaptPlayer(receiver))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ object EnderChestShow : Function("ENDERCHEST") {
private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
} else {
var result = message
keys.forEach {
result = result.replaceFirst(it, "{{ENDERCHEST:${sender.name}}}", ignoreCase = true)
}
result
if (!enabled) {
return message
}
var result = message
keys.forEach {
result = result.replaceFirst(it, "{{ENDERCHEST:${sender.name}}}", ignoreCase = true)
}
return result
}

override fun parseVariable(sender: Player, arg: String): ComponentText? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ object ImageShow : Function("IMAGE") {
val tasks = mutableMapOf<String, CompletableFuture<NMSMap>>()

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
} else {
val result = key.get().find(message) ?: return message
val description = result.groupValues[1]
val url = result.groupValues[2]
message.replaceFirst(key.get(), "{{IMAGE:$description;${url.encodeBase64()}}}")
if (!enabled) {
return message
}
val result = key.get().find(message) ?: return message
val description = result.groupValues[1]
val url = result.groupValues[2]
return message.replaceFirst(key.get(), "{{IMAGE:$description;${url.encodeBase64()}}}")
}

override fun parseVariable(sender: Player, arg: String): ComponentText? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ object InventoryShow : Function("INVENTORY") {
private val PLACEHOLDER_ITEM = buildItem(XMaterial.WHITE_STAINED_GLASS_PANE) { name = "§f" }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
} else {
var result = message
keys.forEach {
result = result.replaceFirst(it, "{{INVENTORY:${sender.name}}}", ignoreCase = true)
}
result
if (!enabled) {
return message
}
var result = message
keys.forEach {
result = result.replaceFirst(it, "{{INVENTORY:${sender.name}}}", ignoreCase = true)
}
return result
}

override fun parseVariable(sender: Player, arg: String): ComponentText? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import taboolib.module.nms.*
import taboolib.module.ui.buildMenu
import taboolib.module.ui.type.Chest
import taboolib.module.ui.type.PageableChest
import taboolib.platform.Folia
import taboolib.platform.util.*

/**
Expand Down Expand Up @@ -85,19 +86,18 @@ object ItemShow : Function("ITEM") {
private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
} else {
var result = message
keys.forEach { key ->
(1..9).forEach {
result = result.replace("$key-$it", "{{ITEM:$it}}", ignoreCase = true)
result = result.replace("$key$it", "{{ITEM:$it}}", ignoreCase = true)
}
result = result.replace(key, "{{ITEM:${sender.inventory.heldItemSlot + 1}}}", ignoreCase = true)
if (!enabled) {
return message
}
var result = message
keys.forEach { key ->
(1..9).forEach {
result = result.replace("$key-$it", "{{ITEM:$it}}", ignoreCase = true)
result = result.replace("$key$it", "{{ITEM:$it}}", ignoreCase = true)
}
result
result = result.replace(key, "{{ITEM:${sender.inventory.heldItemSlot + 1}}}", ignoreCase = true)
}
return result
}

override fun parseVariable(sender: Player, arg: String): ComponentText? {
Expand Down Expand Up @@ -201,6 +201,9 @@ object ItemShow : Function("ITEM") {

@Suppress("Deprecation")
private fun ItemStack.getNameComponent(player: Player): ComponentText {
if (Folia.isFolia) {
return Components.text("Item")
}
return if (originName || itemMeta?.hasDisplayName() != true) {
try {
if (MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_15)) {
Expand All @@ -213,7 +216,11 @@ object ItemShow : Function("ITEM") {
// 玄学问题 https://github.com/TrPlugins/TrChat/issues/344
Components.translation(NMS.instance.getLocaleKey(this).path)
} catch (_: Throwable) {
Components.text(nmsProxy<NMSItem>().getKey(this))
try {
Components.text(nmsProxy<NMSItem>().getKey(this))
} catch (_: Throwable) {
Components.text("Item")
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ object Mention : Function("MENTION") {
val cooldown = ConfigNodeTransfer<String, Long> { parseMillis() }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
} else {
val regex = getRegex(sender) ?: return message
val result = regex.replace(message, "{{MENTION:\$1}}")
if (result != message && !sender.hasPermission("trchat.bypass.mentioncd")) {
sender.updateCooldown(CooldownType.MENTION, cooldown.get())
}
result
if (!enabled) {
return message
}
val regex = getRegex(sender) ?: return message
val result = regex.replace(message, "{{MENTION:\$1}}")
if (result != message && !sender.hasPermission("trchat.bypass.mentioncd")) {
sender.updateCooldown(CooldownType.MENTION, cooldown.get())
}
return result
}

override fun parseVariable(sender: Player, arg: String): ComponentText? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ object MentionAll : Function("MENTIONALL") {
var keys = emptyList<String>()

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
} else {
var result = message
keys.forEach {
result = result.replace(it, "{{MENTIONALL:${sender.name}}}")
}
result
if (!enabled) {
return message
}
var result = message
keys.forEach {
result = result.replace(it, "{{MENTIONALL:${sender.name}}}")
}
return result
}

override fun parseVariable(sender: Player, arg: String): ComponentText? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ import org.bukkit.inventory.meta.ItemMeta
import taboolib.module.chat.ComponentText
import taboolib.module.chat.component
import taboolib.module.nms.getI18nName
import taboolib.platform.Folia
import taboolib.platform.util.*

fun String.parseSimple() = component().build {
transform { it.colorify() }
}

fun ComponentText.hoverItemFixed(item: ItemStack): ComponentText {
if (Folia.isFolia) {
return hoverText("Folia is unsupported! Click to view it.")
}
var newItem = item.optimizeShulkerBox()
newItem = NMS.instance.optimizeNBT(newItem)
return try {
hoverItem(newItem)
// https://github.com/TrPlugins/TrChat/issues/363
NMS.instance.hoverItem(this, newItem)
} catch (_: Throwable) {
try {
// try another method https://github.com/TrPlugins/TrChat/issues/363
NMS.instance.hoverItem(this, newItem)
hoverItem(newItem)
} catch (_: Throwable) {
hoverText("Unable to display this item! Click to view it.")
}
Expand Down
8 changes: 4 additions & 4 deletions project/runtime-bukkit/src/main/resources/filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Cloud-Thesaurus:
- 'https://raw.githubusercontent.com/Yurinann/Filter-Thesaurus-Cloud/main/database.json' # 感谢南城提供的词库
- 'https://raw.githubusercontent.com/konsheng/Sensitive-lexicon/main/ThirdPartyCompatibleFormats/TrChat/SensitiveLexicon.json'

Local: |-
NMSL
fuck
shit
Local:
- NMSL
- fuck
- shit

Ignored-Punctuations: ['!','.',',','#','$','%','&','*','(',')','|','?','/','@','"','\',';','[',']','{','}','+','~','-','_','=','^','<','>',' ',' ','!','。',',','¥','(',')','?','、','“','‘',';','【','】','——','……','《','》','\\', '`']
WhiteList: ['has been']
Expand Down

0 comments on commit 0284bb8

Please sign in to comment.