diff --git a/build.gradle.kts b/build.gradle.kts index 1ef969a9..c0209606 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,11 @@ -import io.izzel.taboolib.gradle.* +import io.izzel.taboolib.gradle.BUKKIT +import io.izzel.taboolib.gradle.BUNGEE +import io.izzel.taboolib.gradle.VELOCITY import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java - id("io.izzel.taboolib") version "2.0.12" + id("io.izzel.taboolib") version "2.0.13" id("org.jetbrains.kotlin.jvm") version "1.8.22" } @@ -14,13 +16,42 @@ subprojects { taboolib { env { - install(UNIVERSAL, DATABASE, KETHER, METRICS, NMS_UTIL) - install(EXPANSION_REDIS, EXPANSION_JAVASCRIPT, EXPANSION_PLAYER_DATABASE) - install(BUKKIT_ALL, BUNGEE, VELOCITY) + install("basic-configuration") + install( + "bukkit-hook", + "bukkit-util", + "bukkit-ui", + "bukkit-xseries" + ) + install("database-sql") + install( + "minecraft-chat", + "minecraft-command-helper", + "minecraft-i18n", + "minecraft-kether", + "minecraft-metrics" + ) + install( + "nms", + "nms-util" + ) + install( + "database-alkaid-redis", + "database-player", + "script-javascript" + ) + install(BUKKIT, BUNGEE, VELOCITY) + install("platform-bukkit-impl") +// install(UNIVERSAL, DATABASE, KETHER, METRICS, NMS_UTIL) +// install(EXPANSION_REDIS, EXPANSION_JAVASCRIPT, EXPANSION_PLAYER_DATABASE) +// install(BUKKIT_ALL, BUNGEE, VELOCITY) + repoTabooLib = "http://mcitd.cn:8081/repository/releases" } version { - taboolib = "6.1.2-beta10" + taboolib = "6.2.0-beta4-dev" coroutines = null +// isSkipKotlin = true +// isSkipKotlinRelocate = true } } @@ -28,6 +59,7 @@ subprojects { repositories { mavenLocal() mavenCentral() + maven("http://mcitd.cn:8081/repository/releases") { isAllowInsecureProtocol = true } maven("https://jitpack.io") maven("https://oss.sonatype.org/content/repositories/snapshots") maven("https://papermc.io/repo/repository/maven-public/") diff --git a/gradle.properties b/gradle.properties index 9571ac3b..141f92b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=me.arasple.mc.trchat -version=2.1.3 +version=2.2.0-beta1 kotlin.incremental=true kotlin.incremental.java=true kotlin.incremental.useClasspathSnapshot=true diff --git a/project/common/src/main/kotlin/me/arasple/mc/trchat/api/ChannelManager.kt b/project/common/src/main/kotlin/me/arasple/mc/trchat/api/ChannelManager.kt index 297d0614..b075be34 100644 --- a/project/common/src/main/kotlin/me/arasple/mc/trchat/api/ChannelManager.kt +++ b/project/common/src/main/kotlin/me/arasple/mc/trchat/api/ChannelManager.kt @@ -19,7 +19,6 @@ interface ChannelManager { * 获取聊天频道 * * Bukkit -> Channel - * BungeeCord/Velocity -> String */ fun getChannel(id: String): Any? diff --git a/project/module-nms/build.gradle.kts b/project/module-nms/build.gradle.kts index 6c7700a3..1ed219ee 100644 --- a/project/module-nms/build.gradle.kts +++ b/project/module-nms/build.gradle.kts @@ -1,5 +1,6 @@ dependencies { compileOnly(project(":project:common")) +// compileOnly("ink.ptms.core:v12101:12101:mapped") // compileOnly("ink.ptms.core:v12005:12005:mapped") compileOnly("ink.ptms.core:v12004:12004:mapped") compileOnly("ink.ptms.core:v12002:12002:mapped") diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/api/impl/BukkitProxyManager.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/api/impl/BukkitProxyManager.kt index cf7e6f2c..e7ca4ed5 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/api/impl/BukkitProxyManager.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/api/impl/BukkitProxyManager.kt @@ -60,7 +60,7 @@ object BukkitProxyManager : ClientMessageManager { override val executor: ExecutorService by unsafeLazy { val factory = ThreadFactoryBuilder().setNameFormat("TrChat PluginMessage Processing Thread #%d").build() - Executors.newFixedThreadPool(4, factory) + Executors.newFixedThreadPool(8, factory) } override val mode: ProxyMode by unsafeLazy { diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt index 8f49358f..e5b933ea 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/conf/Loader.kt @@ -1,7 +1,6 @@ package me.arasple.mc.trchat.module.conf import me.arasple.mc.trchat.api.event.TrChatReloadEvent -import me.arasple.mc.trchat.api.impl.BukkitProxyManager import me.arasple.mc.trchat.module.conf.file.Functions import me.arasple.mc.trchat.module.display.channel.Channel import me.arasple.mc.trchat.module.display.channel.PrivateChannel @@ -36,7 +35,6 @@ import taboolib.common5.FileWatcher import taboolib.library.configuration.ConfigurationSection import taboolib.module.configuration.util.getMap import taboolib.module.lang.sendLang -import taboolib.platform.util.onlinePlayers import java.io.File import kotlin.system.measureTimeMillis @@ -73,8 +71,6 @@ object Loader { Channel.channels.values.forEach { it.unregister() } Channel.channels.clear() - BukkitProxyManager.sendMessage(onlinePlayers.firstOrNull(), arrayOf("FetchProxyChannels")) - filterChannelFiles(folder).forEach { if (FileWatcher.INSTANCE.hasListener(it)) { loadChannel(it) diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/EnderChestShow.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/EnderChestShow.kt new file mode 100644 index 00000000..2da6fee7 --- /dev/null +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/EnderChestShow.kt @@ -0,0 +1,126 @@ +package me.arasple.mc.trchat.module.display.function.standard + +import com.google.common.cache.Cache +import com.google.common.cache.CacheBuilder +import me.arasple.mc.trchat.api.impl.BukkitProxyManager +import me.arasple.mc.trchat.module.conf.file.Functions +import me.arasple.mc.trchat.module.display.function.Function +import me.arasple.mc.trchat.module.display.function.StandardFunction +import me.arasple.mc.trchat.module.internal.script.Reaction +import me.arasple.mc.trchat.util.CooldownType +import me.arasple.mc.trchat.util.getCooldownLeft +import me.arasple.mc.trchat.util.passPermission +import me.arasple.mc.trchat.util.updateCooldown +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack +import taboolib.common.io.digest +import taboolib.common.platform.Platform +import taboolib.common.platform.PlatformSide +import taboolib.common.util.asList +import taboolib.common.util.resettableLazy +import taboolib.common5.util.encodeBase64 +import taboolib.common5.util.parseMillis +import taboolib.library.xseries.XMaterial +import taboolib.module.chat.ComponentText +import taboolib.module.configuration.ConfigNode +import taboolib.module.configuration.ConfigNodeTransfer +import taboolib.module.nms.MinecraftVersion +import taboolib.module.ui.buildMenu +import taboolib.module.ui.type.PageableChest +import taboolib.platform.util.* + +/** + * @author ItsFlicker + * @since 2022/3/18 19:14 + */ +@StandardFunction +@PlatformSide(Platform.BUKKIT) +object EnderChestShow : Function("ENDERCHEST") { + + override val alias = "EnderChest-Show" + + override val reaction by resettableLazy("functions") { + Functions.conf["General.EnderChest-Show.Action"]?.let { Reaction(it.asList()) } + } + + @ConfigNode("General.EnderChest-Show.Enabled", "function.yml") + var enabled = true + + @ConfigNode("General.EnderChest-Show.Permission", "function.yml") + var permission = "none" + + @ConfigNode("General.EnderChest-Show.Cooldown", "function.yml") + val cooldown = ConfigNodeTransfer { parseMillis() } + + @ConfigNode("General.EnderChest-Show.Keys", "function.yml") + var keys = listOf() + + val cache: Cache = CacheBuilder.newBuilder() + .maximumSize(10) + .build() + + private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" } + + override fun createVariable(sender: Player, message: String): String { + 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? { + return computeAndCache(sender).let { + BukkitProxyManager.sendMessage(sender, arrayOf( + "ForwardMessage", + "EnderChestShow", + MinecraftVersion.minecraftVersion, + sender.name, + it.first, + it.second) + ) + sender.getComponentFromLang("Function-EnderChest-Show-Format", sender.name, it.first) + } + } + + override fun canUse(sender: Player): Boolean { + return sender.passPermission(permission) + } + + override fun checkCooldown(sender: Player, message: String): Boolean { + if (enabled && keys.any { message.contains(it, ignoreCase = true) } && !sender.hasPermission("trchat.bypass.enderchestcd")) { + val enderChestCooldown = sender.getCooldownLeft(CooldownType.ENDERCHEST_SHOW) + if (enderChestCooldown > 0) { + sender.sendLang("Cooldowns-EnderChest-Show", enderChestCooldown / 1000) + return false + } else { + sender.updateCooldown(CooldownType.ENDERCHEST_SHOW, cooldown.get()) + } + } + return true + } + + fun computeAndCache(sender: Player): Pair { + val inventory = sender.enderChest + val sha1 = inventory.serializeToByteArray(zipped = false).encodeBase64().digest("sha-1") + if (cache.getIfPresent(sha1) != null) { + return sha1 to cache.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64() + } + val menu = buildMenu>(sender.asLangText("Function-EnderChest-Show-Title", sender.name)) { + rows(3) + slots((0..26).toList()) + elements { (0..26).map { inventory.getItem(it).replaceAir() } } + onGenerate { _, element, _, _ -> element } + onClick(lock = true) + } + cache.put(sha1, menu) + return sha1 to menu.serializeToByteArray().encodeBase64() + } + + private fun ItemStack?.replaceAir() = if (isAir()) AIR_ITEM else this + +} \ No newline at end of file diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/InventoryShow.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/InventoryShow.kt new file mode 100644 index 00000000..137b6e8a --- /dev/null +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/InventoryShow.kt @@ -0,0 +1,147 @@ +package me.arasple.mc.trchat.module.display.function.standard + +import com.google.common.cache.Cache +import com.google.common.cache.CacheBuilder +import me.arasple.mc.trchat.api.impl.BukkitProxyManager +import me.arasple.mc.trchat.module.conf.file.Functions +import me.arasple.mc.trchat.module.display.function.Function +import me.arasple.mc.trchat.module.display.function.StandardFunction +import me.arasple.mc.trchat.module.internal.script.Reaction +import me.arasple.mc.trchat.util.CooldownType +import me.arasple.mc.trchat.util.getCooldownLeft +import me.arasple.mc.trchat.util.passPermission +import me.arasple.mc.trchat.util.updateCooldown +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack +import taboolib.common.io.digest +import taboolib.common.platform.Platform +import taboolib.common.platform.PlatformSide +import taboolib.common.util.asList +import taboolib.common.util.resettableLazy +import taboolib.common5.util.encodeBase64 +import taboolib.common5.util.parseMillis +import taboolib.library.xseries.XMaterial +import taboolib.module.chat.ComponentText +import taboolib.module.configuration.ConfigNode +import taboolib.module.configuration.ConfigNodeTransfer +import taboolib.module.nms.MinecraftVersion +import taboolib.module.ui.buildMenu +import taboolib.module.ui.type.PageableChest +import taboolib.platform.util.* + +/** + * @author ItsFlicker + * @since 2022/3/18 19:14 + */ +@StandardFunction +@PlatformSide(Platform.BUKKIT) +object InventoryShow : Function("INVENTORY") { + + override val alias = "Inventory-Show" + + override val reaction by resettableLazy("functions") { + Functions.conf["General.Inventory-Show.Action"]?.let { Reaction(it.asList()) } + } + + @ConfigNode("General.Inventory-Show.Enabled", "function.yml") + var enabled = true + + @ConfigNode("General.Inventory-Show.Permission", "function.yml") + var permission = "none" + + @ConfigNode("General.Inventory-Show.Cooldown", "function.yml") + val cooldown = ConfigNodeTransfer { parseMillis() } + + @ConfigNode("General.Inventory-Show.Keys", "function.yml") + var keys = listOf() + + val cache: Cache = CacheBuilder.newBuilder() + .maximumSize(10) + .build() + + private val inventorySlots = IntRange(18, 53).toList() + private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" } + private val PLACEHOLDER_ITEM = buildItem(XMaterial.WHITE_STAINED_GLASS_PANE) { name = "§f" } + + override fun createVariable(sender: Player, message: String): String { + 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? { + return computeAndCache(sender).let { + BukkitProxyManager.sendMessage(sender, arrayOf( + "ForwardMessage", + "InventoryShow", + MinecraftVersion.minecraftVersion, + sender.name, + it.first, + it.second) + ) + sender.getComponentFromLang("Function-Inventory-Show-Format", sender.name, it.first) + } + } + + override fun canUse(sender: Player): Boolean { + return sender.passPermission(permission) + } + + override fun checkCooldown(sender: Player, message: String): Boolean { + if (enabled && keys.any { message.contains(it, ignoreCase = true) } && !sender.hasPermission("trchat.bypass.inventorycd")) { + val inventoryCooldown = sender.getCooldownLeft(CooldownType.INVENTORY_SHOW) + if (inventoryCooldown > 0) { + sender.sendLang("Cooldowns-Inventory-Show", inventoryCooldown / 1000) + return false + } else { + sender.updateCooldown(CooldownType.INVENTORY_SHOW, cooldown.get()) + } + } + return true + } + + @Suppress("Deprecation") + fun computeAndCache(sender: Player): Pair { + val inventory = sender.inventory + val sha1 = inventory.serializeToByteArray(zipped = false).encodeBase64().digest("sha-1") + if (cache.getIfPresent(sha1) != null) { + return sha1 to cache.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64() + } + val menu = buildMenu>(sender.asLangText("Function-Inventory-Show-Title", sender.name)) { + rows(6) + slots(inventorySlots) + elements { + (9..35).map { inventory.getItem(it).replaceAir() } + + (0..8).map { inventory.getItem(it).replaceAir() } + } + onGenerate { _, element, _, _ -> element } + onBuild { _, inv -> + inv.setItem(0, PLACEHOLDER_ITEM) + inv.setItem(1, inventory.runCatching { itemInOffHand }.getOrDefault(AIR_ITEM).replaceAir()) + inv.setItem(2, buildItem(XMaterial.PLAYER_HEAD) { + name = "§e${sender.name}" + skullOwner = sender.name + }) + inv.setItem(3, inventory.itemInHand.replaceAir()) + inv.setItem(4, PLACEHOLDER_ITEM) + inv.setItem(5, inventory.getItem(inventory.size - 2).replaceAir()) + inv.setItem(6, inventory.getItem(inventory.size - 3).replaceAir()) + inv.setItem(7, inventory.getItem(inventory.size - 4).replaceAir()) + inv.setItem(8, inventory.getItem(inventory.size - 5).replaceAir()) + (9..17).forEach { slot -> inv.setItem(slot, PLACEHOLDER_ITEM) } + } + onClick(lock = true) + } + cache.put(sha1, menu) + return sha1 to menu.serializeToByteArray().encodeBase64() + } + + private fun ItemStack?.replaceAir() = if (isAir()) AIR_ITEM else this + +} \ No newline at end of file diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/ItemShow.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/ItemShow.kt index ffa1d61b..82084f52 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/ItemShow.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/ItemShow.kt @@ -15,15 +15,19 @@ import me.arasple.mc.trchat.module.internal.hook.type.HookDisplayItem import me.arasple.mc.trchat.module.internal.script.Reaction import me.arasple.mc.trchat.util.* import org.bukkit.Material +import org.bukkit.block.ShulkerBox 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 import taboolib.common.util.asList import taboolib.common.util.replaceWithOrder import taboolib.common.util.resettableLazy +import taboolib.common5.util.encodeBase64 import taboolib.common5.util.parseMillis import taboolib.library.xseries.XMaterial import taboolib.module.chat.ComponentText @@ -32,10 +36,11 @@ import taboolib.module.chat.impl.DefaultComponent import taboolib.module.configuration.ConfigNode import taboolib.module.configuration.ConfigNodeTransfer 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.buildItem -import taboolib.platform.util.isAir -import taboolib.platform.util.sendLang +import taboolib.platform.util.* /** * @author ItsFlicker @@ -63,7 +68,7 @@ object ItemShow : Function("ITEM") { @ConfigNode("General.Item-Show.Compatible", "function.yml") var compatible = false -// @ConfigNode("General.Item-Show.UI", "function.yml") + @ConfigNode("General.Item-Show.UI", "function.yml") var ui = false @ConfigNode("General.Item-Show.Cooldown", "function.yml") @@ -164,37 +169,36 @@ object ItemShow : Function("ITEM") { } fun computeAndCache(sender: Player, item: ItemStack): Pair { - TODO("1.21") -// val sha1 = item.serializeToByteArray(zipped = false).encodeBase64().digest("sha-1") -// if (cacheInventory.getIfPresent(sha1) != null) { -// return sha1 to cacheInventory.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64() -// } -// val inv = if (item.type.name.endsWith("SHULKER_BOX")) { -// val blockStateMeta = item.itemMeta!! as BlockStateMeta -// val shulkerBox = blockStateMeta.blockState as ShulkerBox -// val shulkerInv = shulkerBox.inventory -// buildMenu>(sender.asLangText("Function-Item-Show-Title", sender.name)) { -// rows(3) -// slots((0..26).toList()) -// elements { (0..26).map { shulkerInv.getItem(it).replaceAir() } } -// onGenerate { _, element, _, _ -> element } -// onClick(lock = true) -// } -// } else { -// buildMenu(sender.asLangText("Function-Item-Show-Title", sender.name)) { -// rows(3) -// map( -// "xxxxxxxxx", -// "xxxxixxxx", -// "xxxxxxxxx" -// ) -// set('x', XMaterial.BLACK_STAINED_GLASS_PANE) { name = "§f" } -// set('i', item) -// onClick(lock = true) -// } -// } -// cacheInventory.put(sha1, inv) -// return sha1 to inv.serializeToByteArray().encodeBase64() + val sha1 = item.serializeToByteArray(zipped = false).encodeBase64().digest("sha-1") + if (cacheInventory.getIfPresent(sha1) != null) { + return sha1 to cacheInventory.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64() + } + val inv = if (item.type.name.endsWith("SHULKER_BOX")) { + val blockStateMeta = item.itemMeta!! as BlockStateMeta + val shulkerBox = blockStateMeta.blockState as ShulkerBox + val shulkerInv = shulkerBox.inventory + buildMenu>(sender.asLangText("Function-Item-Show-Title", sender.name)) { + rows(3) + slots((0..26).toList()) + elements { (0..26).map { shulkerInv.getItem(it).replaceAir() } } + onGenerate { _, element, _, _ -> element } + onClick(lock = true) + } + } else { + buildMenu(sender.asLangText("Function-Item-Show-Title", sender.name)) { + rows(3) + map( + "xxxxxxxxx", + "xxxxixxxx", + "xxxxxxxxx" + ) + set('x', XMaterial.BLACK_STAINED_GLASS_PANE) { name = "§f" } + set('i', item) + onClick(lock = true) + } + } + cacheInventory.put(sha1, inv) + return sha1 to inv.serializeToByteArray().encodeBase64() } @Suppress("Deprecation") diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/main/CommandViews.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/main/CommandViews.kt index 72b5ba79..fea890bc 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/main/CommandViews.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/main/CommandViews.kt @@ -1,7 +1,9 @@ package me.arasple.mc.trchat.module.internal.command.main import me.arasple.mc.trchat.module.conf.file.Settings +import me.arasple.mc.trchat.module.display.function.standard.EnderChestShow import me.arasple.mc.trchat.module.display.function.standard.ImageShow +import me.arasple.mc.trchat.module.display.function.standard.InventoryShow import me.arasple.mc.trchat.module.display.function.standard.ItemShow import org.bukkit.entity.Player import taboolib.common.LifeCycle @@ -42,41 +44,40 @@ object CommandViews { createHelper() } } - // TODO 1.21 -// command("view-inventory", permissionDefault = PermissionDefault.TRUE) { -// dynamic("inventory") { -// execute { sender, _, argument -> -// InventoryShow.cache.getIfPresent(argument)?.let { -// sender.openInventory(it) -// } ?: kotlin.run { -// sender.sendLang("Function-Inventory-Show-Unavailable") -// } -// } -// } -// incorrectSender { sender, _ -> -// sender.sendLang("Command-Not-Player") -// } -// incorrectCommand { _, _, _, _ -> -// createHelper() -// } -// } -// command("view-enderchest", permissionDefault = PermissionDefault.TRUE) { -// dynamic("enderchest") { -// execute { sender, _, argument -> -// EnderChestShow.cache.getIfPresent(argument)?.let { -// sender.openInventory(it) -// } ?: kotlin.run { -// sender.sendLang("Function-EnderChest-Show-Unavailable") -// } -// } -// } -// incorrectSender { sender, _ -> -// sender.sendLang("Command-Not-Player") -// } -// incorrectCommand { _, _, _, _ -> -// createHelper() -// } -// } + command("view-inventory", permissionDefault = PermissionDefault.TRUE) { + dynamic("inventory") { + execute { sender, _, argument -> + InventoryShow.cache.getIfPresent(argument)?.let { + sender.openInventory(it) + } ?: kotlin.run { + sender.sendLang("Function-Inventory-Show-Unavailable") + } + } + } + incorrectSender { sender, _ -> + sender.sendLang("Command-Not-Player") + } + incorrectCommand { _, _, _, _ -> + createHelper() + } + } + command("view-enderchest", permissionDefault = PermissionDefault.TRUE) { + dynamic("enderchest") { + execute { sender, _, argument -> + EnderChestShow.cache.getIfPresent(argument)?.let { + sender.openInventory(it) + } ?: kotlin.run { + sender.sendLang("Function-EnderChest-Show-Unavailable") + } + } + } + incorrectSender { sender, _ -> + sender.sendLang("Command-Not-Player") + } + incorrectCommand { _, _, _, _ -> + createHelper() + } + } command("view-image", permissionDefault = PermissionDefault.TRUE) { dynamic("image") { execute { sender, _, argument -> diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerJoin.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerJoin.kt index 86a6abdb..e265963a 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerJoin.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerJoin.kt @@ -1,6 +1,5 @@ package me.arasple.mc.trchat.module.internal.listener -import me.arasple.mc.trchat.api.impl.BukkitProxyManager import me.arasple.mc.trchat.module.display.channel.Channel import me.arasple.mc.trchat.module.internal.service.Updater import me.arasple.mc.trchat.util.data @@ -21,8 +20,6 @@ import taboolib.expansion.setupDataContainer @PlatformSide(Platform.BUKKIT) object ListenerJoin { - private var hasFetched = false - @SubscribeEvent(priority = EventPriority.HIGHEST) fun onJoin(e: PlayerJoinEvent) { val player = e.player @@ -33,10 +30,6 @@ object ListenerJoin { submit(delay = 20) { if (!player.isOnline) return@submit - if (!hasFetched) { - BukkitProxyManager.sendMessage(player, arrayOf("FetchProxyChannels")) - hasFetched = true - } Channel.channels.values.filter { it.settings.alwaysListen }.forEach { if (it.canListen(player)) { it.listeners.add(player.name) diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerPackets.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerPackets.kt index 52547c57..cef429c8 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerPackets.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerPackets.kt @@ -22,15 +22,16 @@ object ListenerPackets { /** * 去除进入时右上角提示/禁止聊天举报 + * TODO Support 1.21 */ @SubscribeEvent fun secure(e: PacketSendEvent) { - if (majorLegacy < 11902 || majorLegacy >= 12005) return + if (!cheatClientSecureChat) return + if (majorLegacy < 11902) return when (e.packet.name) { "ClientboundServerDataPacket" -> { - if (cheatClientSecureChat) e.packet.write("enforcesSecureChat", true) + if (majorLegacy < 12005) e.packet.write("enforcesSecureChat", true) } - "ClientboundPlayerChatHeaderPacket" -> e.isCancelled = true } } diff --git a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/proxy/BukkitProxyProcessor.kt b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/proxy/BukkitProxyProcessor.kt index ec03e7a6..b338e86d 100644 --- a/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/proxy/BukkitProxyProcessor.kt +++ b/project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/proxy/BukkitProxyProcessor.kt @@ -1,8 +1,9 @@ package me.arasple.mc.trchat.module.internal.proxy import me.arasple.mc.trchat.api.impl.BukkitProxyManager -import me.arasple.mc.trchat.module.conf.Loader -import me.arasple.mc.trchat.module.display.channel.Channel +import me.arasple.mc.trchat.module.display.function.standard.EnderChestShow +import me.arasple.mc.trchat.module.display.function.standard.InventoryShow +import me.arasple.mc.trchat.module.display.function.standard.ItemShow import me.arasple.mc.trchat.module.internal.TrChatBukkit import me.arasple.mc.trchat.module.internal.command.main.CommandReply import me.arasple.mc.trchat.module.internal.proxy.redis.RedisManager @@ -13,17 +14,23 @@ import me.arasple.mc.trchat.util.proxy.common.MessageReader import me.arasple.mc.trchat.util.sendComponent import me.arasple.mc.trchat.util.toUUID import org.bukkit.Bukkit -import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory import org.bukkit.plugin.messaging.PluginMessageListener import org.bukkit.plugin.messaging.PluginMessageRecipient import taboolib.common.platform.function.console import taboolib.common.platform.function.getProxyPlayer import taboolib.common.platform.function.submitAsync import taboolib.common.util.subList +import taboolib.common5.util.decodeBase64 import taboolib.module.chat.Components +import taboolib.module.lang.asLangText import taboolib.module.lang.sendLang +import taboolib.module.nms.MinecraftVersion +import taboolib.module.ui.MenuHolder +import taboolib.module.ui.type.impl.ChestImpl import taboolib.platform.util.bukkitPlugin +import taboolib.platform.util.deserializeToInventory import taboolib.platform.util.onlinePlayers import java.io.IOException import java.util.concurrent.ExecutorService @@ -102,48 +109,39 @@ sealed interface BukkitProxyProcessor : PluginMessageListener { "off" -> TrChatBukkit.isGlobalMuting = false } } - "SendProxyChannel" -> { - val id = data[1] - val channel = data[2] - Loader.loadChannel(id, YamlConfiguration().also { it.loadFromString(channel) }).let { - Channel.channels[it.id] = it + "ItemShow" -> { + if (data[1] > MinecraftVersion.minecraftVersion) return + val name = data[2] + val sha1 = data[3] + if (ItemShow.cacheInventory.getIfPresent(sha1) == null) { + val inventory = data[4].decodeBase64().deserializeToInventory( + createNoClickChest(3, console().asLangText("Function-Item-Show-Title", name)) + ) + ItemShow.cacheInventory.put(sha1, inventory) + } + } + "InventoryShow" -> { + if (data[1] > MinecraftVersion.minecraftVersion) return + val name = data[2] + val sha1 = data[3] + if (InventoryShow.cache.getIfPresent(sha1) == null) { + val inventory = data[4].decodeBase64().deserializeToInventory( + createNoClickChest(6, console().asLangText("Function-Inventory-Show-Title", name)) + ) + InventoryShow.cache.put(sha1, inventory) + } + } + "EnderChestShow" -> { + if (data[1] > MinecraftVersion.minecraftVersion) return + val name = data[2] + val sha1 = data[3] + if (EnderChestShow.cache.getIfPresent(sha1) == null) { + val inventory = data[4].decodeBase64().deserializeToInventory( + createNoClickChest(3, console().asLangText("Function-EnderChest-Show-Title", name)) + ) + EnderChestShow.cache.put(sha1, inventory) } - BukkitProxyManager.sendMessage(onlinePlayers.firstOrNull(), arrayOf("LoadedProxyChannel", id)) } - // TODO 1.21 -// "ItemShow" -> { -// if (data[1] > MinecraftVersion.minecraftVersion) return -// val name = data[2] -// val sha1 = data[3] -// if (ItemShow.cacheInventory.getIfPresent(sha1) == null) { -// val inventory = data[4].decodeBase64().deserializeToInventory( -// createNoClickChest(3, console().asLangText("Function-Item-Show-Title", name)) -// ) -// ItemShow.cacheInventory.put(sha1, inventory) -// } -// } -// "InventoryShow" -> { -// if (data[1] > MinecraftVersion.minecraftVersion) return -// val name = data[2] -// val sha1 = data[3] -// if (InventoryShow.cache.getIfPresent(sha1) == null) { -// val inventory = data[4].decodeBase64().deserializeToInventory( -// createNoClickChest(6, console().asLangText("Function-Inventory-Show-Title", name)) -// ) -// InventoryShow.cache.put(sha1, inventory) -// } -// } -// "EnderChestShow" -> { -// if (data[1] > MinecraftVersion.minecraftVersion) return -// val name = data[2] -// val sha1 = data[3] -// if (EnderChestShow.cache.getIfPresent(sha1) == null) { -// val inventory = data[4].decodeBase64().deserializeToInventory( -// createNoClickChest(3, console().asLangText("Function-EnderChest-Show-Title", name)) -// ) -// EnderChestShow.cache.put(sha1, inventory) -// } -// } } } @@ -274,14 +272,14 @@ sealed interface BukkitProxyProcessor : PluginMessageListener { } } -// fun createNoClickChest(rows: Int, title: String): Inventory { -// return MenuHolder(object : ChestImpl(title) { -// init { -// rows(rows) -// onClick(lock = true) -// } -// }).inventory -// } + fun createNoClickChest(rows: Int, title: String): Inventory { + return MenuHolder(object : ChestImpl(title) { + init { + rows(rows) + onClick(lock = true) + } + }).inventory + } } } \ No newline at end of file diff --git a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeChannelManager.kt b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeChannelManager.kt deleted file mode 100644 index ae73d65d..00000000 --- a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeChannelManager.kt +++ /dev/null @@ -1,109 +0,0 @@ -package me.arasple.mc.trchat.api.impl - -import me.arasple.mc.trchat.api.ChannelManager -import me.arasple.mc.trchat.util.print -import net.md_5.bungee.api.ProxyServer -import taboolib.common.io.newFile -import taboolib.common.platform.Platform -import taboolib.common.platform.PlatformFactory -import taboolib.common.platform.PlatformSide -import taboolib.common.platform.ProxyCommandSender -import taboolib.common.platform.function.getDataFolder -import taboolib.common.platform.function.releaseResourceFile -import taboolib.common.platform.function.server -import taboolib.common.util.unsafeLazy -import taboolib.common5.FileWatcher -import taboolib.module.lang.sendLang -import java.io.File -import kotlin.system.measureTimeMillis - -/** - * @author ItsFlicker - * @since 2022/6/19 20:26 - */ -@PlatformSide(Platform.BUNGEE) -object BungeeChannelManager : ChannelManager { - - init { - PlatformFactory.registerAPI(this) - } - - private val folder by unsafeLazy { - val folder = File(getDataFolder(), "channels") - - if (!folder.exists()) { - releaseResourceFile("channels/Bungee.yml", replace = true) - newFile(File(getDataFolder(), "data"), folder = true) - } - - folder - } - - val channels = mutableMapOf() - val loadedServers = mutableMapOf>() - - override fun loadChannels(sender: ProxyCommandSender) { - measureTimeMillis { - channels.clear() - - filterChannelFiles(folder).forEach { - val id = it.nameWithoutExtension - if (FileWatcher.INSTANCE.hasListener(it)) { - try { - val channel = it.readText() - channels[id] = channel - loadedServers[id]?.clear() - sendProxyChannel(id, channel) - } catch (t: Throwable) { - t.print("Channel file ${it.name} loaded failed!") - } - } else { - FileWatcher.INSTANCE.addSimpleListener(it, { - try { - val channel = it.readText() - channels[id] = channel - loadedServers[id]?.clear() - sendProxyChannel(id, channel) - } catch (t: Throwable) { - t.print("Channel file ${it.name} loaded failed!") - } - }, true) - } - } - }.let { - sender.sendLang("Plugin-Loaded-Channels", channels.size, it) - } - } - - override fun getChannel(id: String): String? { - return channels[id] - } - - @Suppress("Deprecation") - fun sendProxyChannel(id: String, channel: String, all: Boolean = false) { - BungeeProxyManager.sendMessageToAll("SendProxyChannel", id, channel) { - all || it.address.port !in loadedServers.computeIfAbsent(id) { ArrayList() } - } - } - - @Suppress("Deprecation") - fun sendAllProxyChannels(port: Int) { - val server = server().servers.values.firstOrNull { it.address.port == port } ?: return - channels.forEach { - BungeeProxyManager.sendMessage(server, "SendProxyChannel", it.key, it.value) - } - } - - private fun filterChannelFiles(file: File): List { - return mutableListOf().apply { - if (file.isDirectory) { - file.listFiles()?.forEach { - addAll(filterChannelFiles(it)) - } - } else if (file.extension.equals("yml", true)) { - add(file) - } - } - } - -} \ No newline at end of file diff --git a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeProxyManager.kt b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeProxyManager.kt index a5aa1a2f..f08d70ee 100644 --- a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeProxyManager.kt +++ b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/api/impl/BungeeProxyManager.kt @@ -33,7 +33,7 @@ object BungeeProxyManager : ProxyMessageManager { override val executor: ExecutorService by unsafeLazy { val factory = ThreadFactoryBuilder().setNameFormat("TrChat PluginMessage Processing Thread #%d").build() - Executors.newFixedThreadPool(4, factory) + Executors.newFixedThreadPool(8, factory) } override val allNames = mutableMapOf>() @@ -68,7 +68,7 @@ object BungeeProxyManager : ProxyMessageManager { } } - @Schedule(async = true, period = 200L) + @Schedule(async = true, period = 100L) override fun updateAllNames() { sendMessageToAll( "UpdateAllNames", diff --git a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatBungee.kt b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatBungee.kt index ff909ef7..4a7ae590 100644 --- a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatBungee.kt +++ b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatBungee.kt @@ -1,6 +1,5 @@ package me.arasple.mc.trchat.module.internal -import me.arasple.mc.trchat.api.impl.BungeeChannelManager import me.arasple.mc.trchat.api.impl.BungeeProxyManager import net.md_5.bungee.api.ProxyServer import taboolib.common.platform.Platform @@ -39,7 +38,6 @@ object TrChatBungee : Plugin() { } } } - BungeeChannelManager.loadChannels(console()) console().sendLang("Plugin-Enabled", pluginVersion) } } diff --git a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerBungeeTransfer.kt b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerBungeeTransfer.kt index c0271466..122e2c4e 100644 --- a/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerBungeeTransfer.kt +++ b/project/runtime-bungee/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerBungeeTransfer.kt @@ -1,6 +1,5 @@ package me.arasple.mc.trchat.module.internal.listener -import me.arasple.mc.trchat.api.impl.BungeeChannelManager import me.arasple.mc.trchat.api.impl.BungeeComponentManager import me.arasple.mc.trchat.api.impl.BungeeProxyManager import me.arasple.mc.trchat.module.internal.TrChatBungee @@ -78,13 +77,6 @@ object ListenerBungeeTransfer { val names = data[1].split(",").map { it.split("-", limit = 2) } BungeeProxyManager.allNames[connection.address.port] = names.associate { it[0] to it[1].takeIf { dn -> dn != "null" } } } - "FetchProxyChannels" -> { - BungeeChannelManager.sendAllProxyChannels(connection.address.port) - } - "LoadedProxyChannel" -> { - val id = data[1] - BungeeChannelManager.loadedServers.computeIfAbsent(id) { ArrayList() }.add(connection.address.port) - } } } } \ No newline at end of file diff --git a/project/runtime-bungee/src/main/resources/channels/Bungee.yml b/project/runtime-bungee/src/main/resources/channels/Bungee.yml deleted file mode 100644 index 78fc1f75..00000000 --- a/project/runtime-bungee/src/main/resources/channels/Bungee.yml +++ /dev/null @@ -1,35 +0,0 @@ -Options: - Speak-Condition: 'perm "trchat.global"' - Proxy: true - Force-Proxy: true - Double-Transfer: true - Always-Listen: true - -#Bindings: -# Prefix: ['!all'] -# Command: ['global', 'all', 'shout'] - -Formats: - - condition: null - prefix: - server: - text: '&8[&3%server_name%&8] ' - hover: |- - &7Server &3%server_name% - &f - &7Version: &6%server_version% - &7Online: &a%server_online%&7/&2%server_max_players% - &7TPS: &b%server_tps% - player: - text: '&e%player_name%&8: ' - msg: - default-color: 'f' - hover: '&7Date: %server_time_HH:mm:ss%' - -# Can't use placeholders! -Console: - - prefix: - server: - text: '&eServer&8: ' - msg: - default-color: 'l' \ No newline at end of file diff --git a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityChannelManager.kt b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityChannelManager.kt deleted file mode 100644 index 81efb9b5..00000000 --- a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityChannelManager.kt +++ /dev/null @@ -1,107 +0,0 @@ -package me.arasple.mc.trchat.api.impl - -import com.velocitypowered.api.proxy.ProxyServer -import me.arasple.mc.trchat.api.ChannelManager -import me.arasple.mc.trchat.util.print -import taboolib.common.io.newFile -import taboolib.common.platform.Platform -import taboolib.common.platform.PlatformFactory -import taboolib.common.platform.PlatformSide -import taboolib.common.platform.ProxyCommandSender -import taboolib.common.platform.function.getDataFolder -import taboolib.common.platform.function.releaseResourceFile -import taboolib.common.platform.function.server -import taboolib.common.util.unsafeLazy -import taboolib.common5.FileWatcher -import taboolib.module.lang.sendLang -import java.io.File -import kotlin.system.measureTimeMillis - -/** - * @author ItsFlicker - * @since 2022/6/19 20:26 - */ -@PlatformSide(Platform.VELOCITY) -object VelocityChannelManager : ChannelManager { - - init { - PlatformFactory.registerAPI(this) - } - - private val folder by unsafeLazy { - val folder = File(getDataFolder(), "channels") - - if (!folder.exists()) { - releaseResourceFile("channels/Velocity.yml", replace = true) - newFile(File(getDataFolder(), "data"), folder = true) - } - - folder - } - - val channels = mutableMapOf() - val loadedServers = mutableMapOf>() - - override fun loadChannels(sender: ProxyCommandSender) { - measureTimeMillis { - channels.clear() - - filterChannelFiles(folder).forEach { - val id = it.nameWithoutExtension - if (FileWatcher.INSTANCE.hasListener(it)) { - try { - val channel = it.readText() - channels[id] = channel - loadedServers[id]?.clear() - sendProxyChannel(id, channel) - } catch (t: Throwable) { - t.print("Channel file ${it.name} loaded failed!") - } - } else { - FileWatcher.INSTANCE.addSimpleListener(it, { - try { - val channel = it.readText() - channels[id] = channel - loadedServers[id]?.clear() - sendProxyChannel(id, channel) - } catch (t: Throwable) { - t.print("Channel file ${it.name} loaded failed!") - } - }, true) - } - } - }.let { - sender.sendLang("Plugin-Loaded-Channels", channels.size, it) - } - } - - override fun getChannel(id: String): String? { - return channels[id] - } - - fun sendProxyChannel(id: String, channel: String, all: Boolean = false) { - VelocityProxyManager.sendMessageToAll("SendProxyChannel", id, channel) { - all || it.serverInfo.address.port !in loadedServers.computeIfAbsent(id) { ArrayList() } - } - } - - fun sendAllProxyChannels(port: Int) { - val server = server().allServers.firstOrNull { it.serverInfo.address.port == port } ?: return - channels.forEach { - VelocityProxyManager.sendMessage(server, "SendProxyChannel", it.key, it.value) - } - } - - private fun filterChannelFiles(file: File): List { - return mutableListOf().apply { - if (file.isDirectory) { - file.listFiles()?.forEach { - addAll(filterChannelFiles(it)) - } - } else if (file.extension.equals("yml", true)) { - add(file) - } - } - } - -} \ No newline at end of file diff --git a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityProxyManager.kt b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityProxyManager.kt index 308e442f..e8b2938f 100644 --- a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityProxyManager.kt +++ b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/api/impl/VelocityProxyManager.kt @@ -1,6 +1,7 @@ package me.arasple.mc.trchat.api.impl import com.google.common.util.concurrent.ThreadFactoryBuilder +import com.velocitypowered.api.proxy.ServerConnection import com.velocitypowered.api.proxy.messages.ChannelMessageSink import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier import com.velocitypowered.api.proxy.server.RegisteredServer @@ -12,6 +13,7 @@ import taboolib.common.platform.Platform import taboolib.common.platform.PlatformFactory import taboolib.common.platform.PlatformSide import taboolib.common.platform.Schedule +import taboolib.common.platform.function.warning import taboolib.common.util.unsafeLazy import java.io.IOException import java.util.concurrent.CompletableFuture @@ -37,7 +39,7 @@ object VelocityProxyManager : ProxyMessageManager { override val executor: ExecutorService by unsafeLazy { val factory = ThreadFactoryBuilder().setNameFormat("TrChat PluginMessage Processing Thread #%d").build() - Executors.newFixedThreadPool(4, factory) + Executors.newFixedThreadPool(8, factory) } override val allNames = mutableMapOf>() @@ -49,7 +51,16 @@ object VelocityProxyManager : ProxyMessageManager { return executor.submit { try { for (bytes in buildMessage(*args)) { - recipient.sendPluginMessage(outgoing, bytes) + if (!recipient.sendPluginMessage(outgoing, bytes)) { + warning("Failed to send proxy trchat message!") + warning(args) + val info = when (recipient) { + is RegisteredServer -> recipient.serverInfo + is ServerConnection -> recipient.serverInfo + else -> continue + } + warning(info) + } } } catch (e: IOException) { e.print("Failed to send proxy trchat message!") @@ -63,17 +74,20 @@ object VelocityProxyManager : ProxyMessageManager { try { for (bytes in buildMessage(*args)) { recipients.forEach { v -> - v.sendPluginMessage(outgoing, bytes) + if (!v.sendPluginMessage(outgoing, bytes)) { + warning("Failed to send proxy trchat message!") + warning(args) + warning(v.serverInfo) + } } } } catch (e: IOException) { e.print("Failed to send proxy trchat message!") } } - } - @Schedule(async = true, period = 200L) + @Schedule(async = true, period = 100L) override fun updateAllNames() { sendMessageToAll( "UpdateAllNames", diff --git a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatVelocity.kt b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatVelocity.kt index 7816af85..d51ee947 100644 --- a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatVelocity.kt +++ b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatVelocity.kt @@ -1,6 +1,5 @@ package me.arasple.mc.trchat.module.internal -import me.arasple.mc.trchat.api.impl.VelocityChannelManager import me.arasple.mc.trchat.api.impl.VelocityProxyManager import taboolib.common.platform.Platform import taboolib.common.platform.PlatformSide @@ -26,13 +25,12 @@ object TrChatVelocity : Plugin() { val plugin by unsafeLazy { VelocityPlugin.getInstance() } override fun onLoad() { + plugin.server.channelRegistrar.register(VelocityProxyManager.incoming, VelocityProxyManager.outgoing) VelocityConsole().sendLang("Plugin-Loading", plugin.server.version.version) VelocityConsole().sendLang("Plugin-Proxy-Supported", "Velocity") } override fun onEnable() { - plugin.server.channelRegistrar.register(VelocityProxyManager.incoming, VelocityProxyManager.outgoing) - command("muteallservers", permission = "trchatv.muteallservers") { dynamic("state") { suggest { @@ -44,7 +42,6 @@ object TrChatVelocity : Plugin() { } } } - VelocityChannelManager.loadChannels(VelocityConsole()) VelocityConsole().sendLang("Plugin-Enabled", pluginVersion) } diff --git a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerVelocityTransfer.kt b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerVelocityTransfer.kt index d0dd91ec..94ba2a7b 100644 --- a/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerVelocityTransfer.kt +++ b/project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerVelocityTransfer.kt @@ -2,7 +2,6 @@ package me.arasple.mc.trchat.module.internal.listener import com.velocitypowered.api.event.connection.PluginMessageEvent import com.velocitypowered.api.proxy.ServerConnection -import me.arasple.mc.trchat.api.impl.VelocityChannelManager import me.arasple.mc.trchat.api.impl.VelocityProxyManager import me.arasple.mc.trchat.module.internal.TrChatVelocity.plugin import me.arasple.mc.trchat.util.print @@ -14,6 +13,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import taboolib.common.platform.Platform import taboolib.common.platform.PlatformSide import taboolib.common.platform.event.SubscribeEvent +import taboolib.common.platform.function.warning import java.io.IOException /** @@ -28,16 +28,20 @@ object ListenerVelocityTransfer { @SubscribeEvent fun onTransfer(e: PluginMessageEvent) { - if (e.identifier.id == VelocityProxyManager.incoming.id) { - try { - val message = MessageReader.read(e.data) - if (message.isCompleted) { - val data = message.build() - execute(data, e.source as ServerConnection) - } - } catch (ex: IOException) { - ex.print("Error occurred while reading plugin message.") + if (e.identifier != VelocityProxyManager.incoming) return + val source = e.source + if (source !is ServerConnection) { + warning("Received trchat:proxy message, but source is not ServerConnection") + return + } + try { + val message = MessageReader.read(e.data) + if (message.isCompleted) { + val data = message.build() + execute(data, source) } + } catch (ex: IOException) { + ex.print("Error occurred while reading plugin message.") } } @@ -73,13 +77,6 @@ object ListenerVelocityTransfer { val names = data[1].split(",").map { it.split("-", limit = 2) } VelocityProxyManager.allNames[connection.serverInfo.address.port] = names.associate { it[0] to it[1].takeIf { dn -> dn != "null" } } } - "FetchProxyChannels" -> { - VelocityChannelManager.sendAllProxyChannels(connection.serverInfo.address.port) - } - "LoadedProxyChannel" -> { - val id = data[1] - VelocityChannelManager.loadedServers.computeIfAbsent(id) { ArrayList() }.add(connection.serverInfo.address.port) - } } } } \ No newline at end of file diff --git a/project/runtime-velocity/src/main/resources/channels/Velocity.yml b/project/runtime-velocity/src/main/resources/channels/Velocity.yml deleted file mode 100644 index 78fc1f75..00000000 --- a/project/runtime-velocity/src/main/resources/channels/Velocity.yml +++ /dev/null @@ -1,35 +0,0 @@ -Options: - Speak-Condition: 'perm "trchat.global"' - Proxy: true - Force-Proxy: true - Double-Transfer: true - Always-Listen: true - -#Bindings: -# Prefix: ['!all'] -# Command: ['global', 'all', 'shout'] - -Formats: - - condition: null - prefix: - server: - text: '&8[&3%server_name%&8] ' - hover: |- - &7Server &3%server_name% - &f - &7Version: &6%server_version% - &7Online: &a%server_online%&7/&2%server_max_players% - &7TPS: &b%server_tps% - player: - text: '&e%player_name%&8: ' - msg: - default-color: 'f' - hover: '&7Date: %server_time_HH:mm:ss%' - -# Can't use placeholders! -Console: - - prefix: - server: - text: '&eServer&8: ' - msg: - default-color: 'l' \ No newline at end of file