Skip to content

Commit

Permalink
[2.0.8] 1.20.2 & Fix
Browse files Browse the repository at this point in the history
* Fix #303
* Fix #322
  • Loading branch information
ItsFlicker committed Sep 29, 2023
1 parent 789b573 commit 906aed6
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 83 deletions.
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.7
taboolib_version=6.0.12-15
version=2.0.8
taboolib_version=6.0.12-26
kotlin.incremental=true
kotlin.incremental.java=true
koltin.incremental.useClasspathSnapshot=true
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:v12002:12002:mapped")
compileOnly("ink.ptms.core:v12001:12001:mapped")
compileOnly("ink.ptms.core:v11903:11903:mapped")
compileOnly("ink.ptms.core:v11902:11902:mapped")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import taboolib.module.chat.ComponentText
import taboolib.module.nms.MinecraftVersion.isUniversal
import taboolib.module.nms.MinecraftVersion.majorLegacy
import taboolib.module.nms.sendPacket
import taboolib.platform.util.isNotAir
import taboolib.platform.util.isAir
import java.util.*

private typealias IChatBaseComponent12 = net.minecraft.server.v1_12_R1.IChatBaseComponent
private typealias ChatSerializer12 = net.minecraft.server.v1_12_R1.IChatBaseComponent.ChatSerializer
private typealias ChatSerializer16 = net.minecraft.server.v1_16_R1.IChatBaseComponent.ChatSerializer
private typealias CraftPlayer19 = org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer
private typealias CraftPlayer19 = org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer
private typealias CraftItemStack12 = org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack
private typealias CraftItemStack19 = org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack
private typealias CraftChatMessage19 = org.bukkit.craftbukkit.v1_19_R2.util.CraftChatMessage
private typealias NMSNBTTagCompound = net.minecraft.nbt.NBTTagCompound
private typealias NBTTagCompound12 = net.minecraft.server.v1_12_R1.NBTTagCompound
private typealias NBTTagCompound19 = net.minecraft.nbt.NBTTagCompound
private typealias NMSIChatBaseComponent = net.minecraft.network.chat.IChatBaseComponent

@Suppress("unused")
Expand Down Expand Up @@ -77,28 +79,42 @@ class NMSImpl : NMS() {

override fun hoverItem(component: ComponentText, itemStack: ItemStack): ComponentText {
val nmsItem = CraftItemStack19.asNMSCopy(itemStack)
val nbtTag = NMSNBTTagCompound()
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 {
val nmsItem = CraftItemStack19.asNMSCopy(itemStack)
if (itemStack.isNotAir() && nmsItem.hasTag()) {
if (isUniversal) {
val nbtTag = NMSNBTTagCompound()
nmsItem.tag!!.allKeys.forEach {
if (it in nbtWhitelist) {
nbtTag.put(it, nmsItem.tag!!.get(it))
if (isUniversal) {
val nmsItem = CraftItemStack19.asNMSCopy(itemStack)
if (nmsItem.hasTag()) {
val nbtTag = NBTTagCompound19()
nmsItem.tag!!.allKeys.forEach { key ->
if (key in nbtWhitelist) {
nbtTag.put(key, nmsItem.tag!!.get(key))
}
}
nmsItem.tag = nbtTag
return CraftItemStack19.asBukkitCopy(nmsItem)
}
} else {
val nmsItem = CraftItemStack12.asNMSCopy(itemStack)
if (nmsItem.hasTag()) {
val nbtTag = NBTTagCompound12()
nmsItem.tag!!.c().forEach { key ->
if (key in nbtWhitelist) {
nbtTag.set(key, nmsItem.tag!!.get(key))
}
}
nmsItem.tag = nbtTag
return CraftItemStack12.asBukkitCopy(nmsItem)
}
}

} catch (t: Throwable) {
t.reportOnce("Got an error optimizing item nbt")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import me.arasple.mc.trchat.module.display.channel.PrivateChannel
import me.arasple.mc.trchat.util.color.CustomColor
import me.arasple.mc.trchat.util.color.MessageColors
import me.arasple.mc.trchat.util.data
import me.arasple.mc.trchat.util.getDataContainer
import me.arasple.mc.trchat.util.reportOnce
import org.bukkit.entity.Player
import taboolib.expansion.getDataContainer
import taboolib.module.nms.Packet
import taboolib.module.nms.sendPacket
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import taboolib.common.platform.command.PermissionDefault
import taboolib.common.platform.command.command
import taboolib.common.platform.function.adaptPlayer
import taboolib.common.platform.function.console
import taboolib.common.platform.function.getProxyPlayer
import taboolib.common.platform.function.unregisterCommand
Expand Down Expand Up @@ -125,7 +126,7 @@ open class Channel(
player.sendLang("Channel-No-Speak-Permission")
return null
}
if (settings.filterBeforeSending && TrChat.api().getFilterManager().filter(message).sensitiveWords > 0) {
if (settings.filterBeforeSending && TrChat.api().getFilterManager().filter(message, adaptPlayer(player)).sensitiveWords > 0) {
player.sendLang("Channel-Bad-Language")
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.bukkit.entity.Player
import taboolib.common.platform.command.PermissionDefault
import taboolib.common.platform.command.command
import taboolib.common.platform.command.suggest
import taboolib.common.platform.function.adaptPlayer
import taboolib.common.platform.function.console
import taboolib.common.platform.function.getProxyPlayer
import taboolib.common.util.subList
Expand Down Expand Up @@ -93,7 +94,7 @@ class PrivateChannel(
player.sendLang("Channel-No-Speak-Permission")
return null
}
if (settings.filterBeforeSending && TrChat.api().getFilterManager().filter(message).sensitiveWords > 0) {
if (settings.filterBeforeSending && TrChat.api().getFilterManager().filter(message, adaptPlayer(player)).sensitiveWords > 0) {
player.sendLang("Channel-Bad-Language")
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,35 @@ object CommandMute {
BukkitProxyManager.getPlayerNames().keys.toList()
}
execute<CommandSender> { sender, ctx, _ ->
val player = Bukkit.getOfflinePlayer(ctx["player"])
if (!player.hasPlayedBefore()) {
return@execute sender.sendLang("Command-Player-Not-Exist")
}
val player = Bukkit.getPlayer(ctx["player"])
?: return@execute sender.sendLang("Command-Player-Not-Exist")
val data = player.data
data.updateMuteTime("999d".parseMillis())
sender.sendLang("Mute-Muted-Player", player.name!!, "999d", "null")
(player as? Player)?.sendLang("General-Muted", muteDateFormat.format(data.muteTime), data.muteReason)
sender.sendLang("Mute-Muted-Player", player.name, "999d", "null")
(player as? Player)
?.sendLang("General-Muted", muteDateFormat.format(data.muteTime), data.muteReason)
}
dynamic("options", optional = true) {
suggestUncheck {
listOf("-t 1h", "-t 2d", "-t 15m", "-r Reason", "--cancel")
}
execute<CommandSender> { sender, ctx, argument ->
val player = Bukkit.getOfflinePlayer(ctx["player"])
if (!player.hasPlayedBefore()) {
return@execute sender.sendLang("Command-Player-Not-Exist")
}
val player = Bukkit.getPlayer(ctx["player"])
?: return@execute sender.sendLang("Command-Player-Not-Exist")
val data = player.data
val de = Demand("mute $argument")
if (de.tags.contains("cancel")) {
data.updateMuteTime(0)
sender.sendLang("Mute-Cancel-Muted-Player", player.name!!)
sender.sendLang("Mute-Cancel-Muted-Player", player.name)
(player as? Player)?.sendLang("General-Cancel-Muted")
} else {
val time = de.get("t") ?: "999d"
val reason = de.get("r") ?: "null"
data.updateMuteTime(time.parseMillis())
data.setMuteReason(reason)
sender.sendLang("Mute-Muted-Player", player.name!!, time, reason)
(player as? Player)?.sendLang("General-Muted", muteDateFormat.format(data.muteTime), data.muteReason)
sender.sendLang("Mute-Muted-Player", player.name, time, reason)
(player as? Player)
?.sendLang("General-Muted", muteDateFormat.format(data.muteTime), data.muteReason)
}
}
}
Expand All @@ -84,12 +82,10 @@ object CommandMute {
BukkitProxyManager.getPlayerNames().keys.toList()
}
execute<CommandSender> { sender, ctx, _ ->
val player = Bukkit.getOfflinePlayer(ctx["player"])
if (!player.hasPlayedBefore()) {
return@execute sender.sendLang("Command-Player-Not-Exist")
}
val player = Bukkit.getPlayer(ctx["player"])
?: return@execute sender.sendLang("Command-Player-Not-Exist")
player.data.updateMuteTime(0)
sender.sendLang("Mute-Cancel-Muted-Player", player.name!!)
sender.sendLang("Mute-Cancel-Muted-Player", player.name)
(player as? Player)?.sendLang("General-Cancel-Muted")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package me.arasple.mc.trchat.module.internal.data

import me.arasple.mc.trchat.module.display.channel.Channel
import me.arasple.mc.trchat.util.getDataContainer
import me.arasple.mc.trchat.util.parseString
import me.arasple.mc.trchat.util.toUUID
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import taboolib.common5.cbool
import taboolib.common5.clong
import taboolib.expansion.getDataContainer
import java.util.*
import java.util.concurrent.ConcurrentHashMap

/**
* @author ItsFlicker
* @since 2022/6/25 18:17
*/
class PlayerData(val player: OfflinePlayer) {
class PlayerData(val player: Player) {

init {
if (isVanishing) {
vanishing += player.name!!
vanishing += player.name
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class PlayerData(val player: OfflinePlayer) {
fun switchVanish(): Boolean {
player.getDataContainer()["vanish"] = !isVanishing
return isVanishing.also {
if (it) vanishing += player.name!! else vanishing -= player.name!!
if (it) vanishing += player.name else vanishing -= player.name
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ class PlayerData(val player: OfflinePlayer) {

val vanishing = mutableSetOf<String>()

fun getData(player: OfflinePlayer): PlayerData {
fun getData(player: Player): PlayerData {
return data.computeIfAbsent(player.uniqueId) {
PlayerData(player)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package me.arasple.mc.trchat.module.internal.hook.ext

import me.arasple.mc.trchat.api.event.TrChatEvent
import me.arasple.mc.trchat.module.internal.command.main.CommandMute
import me.arasple.mc.trchat.util.Vars
import me.arasple.mc.trchat.util.PAPIUtil
import me.arasple.mc.trchat.util.data
import me.arasple.mc.trchat.util.session
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
Expand Down Expand Up @@ -58,27 +57,9 @@ object HookPlaceholderAPI : PlaceholderExpansion {
return "ERROR"
}

override fun onPlaceholderRequest(player: OfflinePlayer?, args: String): String {
if (player != null) {
if (player.isOnline) {
return onPlaceholderRequest(player.player, args)
}
val params = args.split('_')
val data = player.data
return when (params[0].lowercase()) {
"spy" -> data.isSpying
"filter" -> data.isFilterEnabled
"mute" -> data.isMuted
"vanish" -> data.isVanishing
else -> "out of case"
}.toString()
}
return "ERROR"
}

@SubscribeEvent(priority = EventPriority.LOW)
fun onChat(e: TrChatEvent) {
if (e.forward && !Vars.checkExpansions(e.session.player)) {
if (e.forward && !PAPIUtil.checkExpansions(e.session.player)) {
e.isCancelled = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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 @@ -15,7 +17,10 @@ class HookDiscordSRV : HookAbstract() {
DiscordSRV.api.subscribe(object {
@Subscribe
fun onChatPreProcess(e: GameChatMessagePreProcessEvent) {
if (e.player.session.lastChannel?.settings?.sendToDiscord == false) {
val channel = e.player.session.lastChannel ?: return
if (channel.settings.sendToDiscord) {
e.message = TrChat.api().getFilterManager().filter(e.message, adaptPlayer(e.player)).filtered
} else {
e.isCancelled = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object ListenerAnvilChange {
return@modifyMeta
}
if (filter) {
setDisplayName(TrChat.api().getFilterManager().filter(displayName, player = adaptPlayer(p)).filtered)
setDisplayName(TrChat.api().getFilterManager().filter(displayName, adaptPlayer(p)).filtered)
}
if (color) {
if (p.hasPermission("trchat.color.simple")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import taboolib.common.platform.event.EventPriority
import taboolib.common.platform.event.SubscribeEvent
import taboolib.common.platform.function.adaptPlayer
import taboolib.common.platform.function.submit
import taboolib.expansion.playerDataContainer
import taboolib.expansion.setupDataContainer

/**
Expand All @@ -29,9 +28,7 @@ object ListenerJoin {
fun onJoin(e: PlayerJoinEvent) {
val player = e.player

if (!playerDataContainer.containsKey(player.uniqueId)) {
player.setupDataContainer()
}
player.setupDataContainer()
player.data
player.session

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.arasple.mc.trchat.module.internal.listener

import me.arasple.mc.trchat.util.session
import me.arasple.mc.trchat.module.display.ChatSession
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
import taboolib.common.platform.event.SubscribeEvent
Expand Down Expand Up @@ -32,7 +32,7 @@ object ListenerPackets {
*/
@SubscribeEvent
fun recall(e: PacketSendEvent) {
val session = e.player.session
val session = ChatSession.sessions[e.player.uniqueId] ?: return
when (e.packet.name) {
"ClientboundSystemChatPacket" -> {
session.addMessage(e.packet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object ListenerSignChange {

for (index in e.lines.indices) {
if (filter) {
e.setLine(index, TrChat.api().getFilterManager().filter(e.getLine(index) ?: "", player = adaptPlayer(p)).filtered)
e.setLine(index, TrChat.api().getFilterManager().filter(e.getLine(index) ?: "", adaptPlayer(p)).filtered)
}
if (color) {
if (TrChatBukkit.isPaperEnv && p.hasPermission("trchat.color.simple")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryType
import taboolib.common.util.unsafeLazy
import taboolib.expansion.DataContainer
import taboolib.expansion.playerDataContainer
import taboolib.expansion.playerDatabase
import taboolib.module.chat.ComponentText
import taboolib.module.nms.MinecraftVersion
import taboolib.module.ui.MenuHolder
Expand Down Expand Up @@ -79,7 +76,7 @@ fun String.parseInline(sender: CommandSender, vars: Map<String, Any> = emptyMap(

inline val Player.session get() = ChatSession.getSession(this)

inline val OfflinePlayer.data get() = PlayerData.getData(this)
inline val Player.data get() = PlayerData.getData(this)

fun Player.checkMute(): Boolean {
if (TrChatBukkit.isGlobalMuting && !hasPermission("trchat.bypass.globalmute")) {
Expand All @@ -94,10 +91,6 @@ fun Player.checkMute(): Boolean {
return true
}

fun OfflinePlayer.getDataContainer(): DataContainer {
return playerDataContainer.computeIfAbsent(uniqueId) { DataContainer(uniqueId.parseString(), playerDatabase!!) }
}

fun Any.sendComponent(sender: Any?, component: ComponentText) {
BukkitComponentManager.sendComponent(this, component, sender)
}
Expand Down
Loading

0 comments on commit 906aed6

Please sign in to comment.