Skip to content

Commit

Permalink
[2.0.14] Support Folia
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFlicker committed Mar 2, 2024
1 parent d88cb47 commit 9ca6019
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 23 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
id("io.izzel.taboolib") version "2.0.5"
id("io.izzel.taboolib") version "2.0.9"
id("org.jetbrains.kotlin.jvm") version "1.8.22"
}

Expand All @@ -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)
install(BUKKIT_ALL, BUNGEE, VELOCITY, "platform-bukkit-impl")
}
version {
taboolib = "6.1.0"
taboolib = "6.1.1-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.0.13
version=2.0.14
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 @@ -3,6 +3,7 @@ package me.arasple.mc.trchat.api.nms
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.module.chat.ComponentText
import taboolib.module.nms.LocaleKey
import taboolib.module.nms.nmsProxy
import java.util.*

Expand Down Expand Up @@ -30,6 +31,8 @@ abstract class NMS {

abstract fun setCustomChatCompletions(player: Player, entries: List<String>)

abstract fun getLocaleKey(itemStack: ItemStack): LocaleKey

companion object {

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import net.minecraft.server.v1_12_R1.ChatMessageType
import net.minecraft.server.v1_12_R1.PacketPlayOutChat
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.common.platform.function.adaptPlayer
import taboolib.library.reflex.Reflex.Companion.invokeConstructor
import taboolib.module.chat.ComponentText
import taboolib.module.nms.LocaleKey
import taboolib.module.nms.MinecraftVersion.isUniversal
import taboolib.module.nms.MinecraftVersion.majorLegacy
import taboolib.module.nms.NMSItem
import taboolib.module.nms.nmsProxy
import taboolib.module.nms.sendPacket
import taboolib.platform.Folia
import taboolib.platform.util.isAir
import java.util.*

Expand Down Expand Up @@ -55,6 +60,10 @@ class NMSImpl : NMS() {
}

override fun sendMessage(receiver: Player, component: ComponentText, sender: UUID?) {
if (Folia.isFolia) {
component.sendTo(adaptPlayer(receiver))
return
}
if (majorLegacy >= 11900) {
val player = (receiver as CraftPlayer19).handle
player.sendSystemMessage(craftChatMessageFromComponent(component) as NMSIChatBaseComponent)
Expand Down Expand Up @@ -147,4 +156,10 @@ class NMSImpl : NMS() {
} catch (_: NoClassDefFoundError) {
}
}

override fun getLocaleKey(itemStack: ItemStack): LocaleKey {
val nmsItemStack = nmsProxy<NMSItem>().getNMSCopy(itemStack) as net.minecraft.server.v1_16_R3.ItemStack
val nmsItem = nmsItemStack.item
return LocaleKey("N", nmsItem.f(nmsItemStack))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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.function.Function
import me.arasple.mc.trchat.module.internal.data.ChatLogs
import me.arasple.mc.trchat.module.internal.script.Condition
import me.arasple.mc.trchat.module.internal.service.Metrics
import me.arasple.mc.trchat.util.*
import org.bukkit.command.CommandSender
Expand Down Expand Up @@ -61,8 +60,8 @@ open class Channel(
name = bindings.command[0],
aliases = subList(bindings.command, 1),
description = "TrChat channel $id",
permission = settings.joinPermission,
permissionDefault = if (settings.speakCondition != Condition.EMPTY) PermissionDefault.TRUE else PermissionDefault.OP
permission = "trchat.command.channel.${id.lowercase()}",
permissionDefault = PermissionDefault.TRUE
) {
execute<Player> { sender, _, _ ->
if (sender.session.channel == this@Channel.id) {
Expand Down Expand Up @@ -91,7 +90,11 @@ open class Channel(
}

open fun canSpeak(player: Player): Boolean {
return settings.speakCondition.pass(player)
return if (settings.speakCondition.isEmpty()) {
player.passPermission(settings.joinPermission)
} else {
settings.speakCondition.pass(player)
}
}

open fun execute(sender: CommandSender, message: String): ChannelExecuteResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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
import me.arasple.mc.trchat.module.internal.data.PlayerData
import me.arasple.mc.trchat.module.internal.script.Condition
import me.arasple.mc.trchat.module.internal.service.Metrics
import me.arasple.mc.trchat.util.pass
import me.arasple.mc.trchat.util.sendComponent
Expand Down Expand Up @@ -59,8 +58,8 @@ class PrivateChannel(
name = bindings.command[0],
aliases = subList(bindings.command, 1),
description = "TrChat channel $id",
permission = settings.joinPermission,
permissionDefault = if (settings.speakCondition != Condition.EMPTY) PermissionDefault.TRUE else PermissionDefault.OP
permission = "trchat.command.channel.${id.lowercase()}",
permissionDefault = PermissionDefault.TRUE
) {
execute<Player> { sender, _, _ ->
if (sender.session.channel == this@PrivateChannel.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import me.arasple.mc.trchat.api.event.TrChatItemShowEvent
import me.arasple.mc.trchat.api.impl.BukkitProxyManager
import me.arasple.mc.trchat.api.nms.NMS
import me.arasple.mc.trchat.module.adventure.toNative
import me.arasple.mc.trchat.module.conf.file.Functions
import me.arasple.mc.trchat.module.display.function.Function
Expand Down Expand Up @@ -102,7 +103,7 @@ object ItemShow : Function("ITEM") {
override fun parseVariable(sender: Player, arg: String): ComponentText? {
val item = sender.inventory.getItem(arg.toInt() - 1) ?: ItemStack(Material.AIR)
var newItem = if (compatible) {
buildItem(item) { material = Material.STONE }
if (item.isAir()) ItemStack(Material.STONE) else buildItem(item) { material = Material.STONE }
} else {
var newItem = item.clone()
HookPlugin.registry.filterIsInstance<HookDisplayItem>().forEach { element ->
Expand Down Expand Up @@ -208,7 +209,12 @@ object ItemShow : Function("ITEM") {
Components.text(getI18nName(player))
}
} catch (_: UnsupportedVersionException) {
Components.text(nmsProxy<NMSItem>().getKey(this))
try {
// 玄学问题 https://github.com/TrPlugins/TrChat/issues/344
Components.translation(NMS.instance.getLocaleKey(this).path)
} catch (_: Throwable) {
Components.text(nmsProxy<NMSItem>().getKey(this))
}
}
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import taboolib.common.platform.*
import taboolib.common.platform.function.console
import taboolib.common.platform.function.pluginVersion
import taboolib.module.lang.sendLang
import taboolib.module.nms.ChannelExecutor
import taboolib.module.nms.MinecraftVersion.majorLegacy
import taboolib.platform.Folia

@PlatformSide(Platform.BUKKIT)
object TrChatBukkit : Plugin() {
Expand All @@ -43,6 +45,9 @@ object TrChatBukkit : Plugin() {
}

override fun onEnable() {
if (Folia.isFolia) {
ChannelExecutor.disable()
}
BukkitProxyManager.processor
HookPlugin.printInfo()
reload(console())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ value class Condition(private val script: String) {
else eval(player, script)
}

fun isEmpty(): Boolean {
return script.isEmpty()
}

companion object {

val EMPTY = Condition("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fun ComponentText.hoverItemFixed(item: ItemStack): ComponentText {
hoverItem(newItem)
} catch (_: Throwable) {
try {
// try another method https://github.com/TrPlugins/TrChat/issues/363
NMS.instance.hoverItem(this, newItem)
} catch (_: Throwable) {
hoverText("Unable to display this item! Click to view it.")
Expand Down
10 changes: 0 additions & 10 deletions project/runtime-velocity/src/main/resources/velocity-plugin.json

This file was deleted.

0 comments on commit 9ca6019

Please sign in to comment.