diff --git a/build.gradle.kts b/build.gradle.kts index ab5cda30..4b511912 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7" - id("org.screamingsandals.nms-mapper") version "1.4.6" + id("org.screamingsandals.nms-mapper") version "1.4.9" id("xyz.jpenilla.run-paper") version "2.2.2" id("io.papermc.hangar-publish-plugin") version "0.1.0" id("com.modrinth.minotaur") version "2.8.6" @@ -331,6 +331,7 @@ nmsGen { /* Here we can define the classes */ val ServerGamePacketListenerImpl = reqClass("net.minecraft.server.network.ServerGamePacketListenerImpl") + var ServerCommonPacketListenerImpl = reqClass("net.minecraft.server.network.ServerCommonPacketListenerImpl") //1.20.2 and above val ClientboundUpdateMobEffectPacket = reqClass("net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket") val ClientboundRemoveMobEffectPacket = reqClass("net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket") val ClientboundPlayerInfoUpdatePacket = reqClass("net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket") @@ -372,6 +373,10 @@ nmsGen { ServerGamePacketListenerImpl .reqMethod("send", Packet) .reqField("connection") + ServerCommonPacketListenerImpl + .reqMethod("send", Packet) + .reqField("connection") + .reqMethod("latency") ClientboundUpdateMobEffectPacket .reqConstructor(Int::class, MobEffectInstance) ClientboundRemoveMobEffectPacket diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/command/VanishCommand.kt b/src/main/java/ir/syrent/velocityvanish/spigot/command/VanishCommand.kt index e2a5be91..1cd3b65c 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/command/VanishCommand.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/command/VanishCommand.kt @@ -5,19 +5,15 @@ import cloud.commandframework.DescriptiveCompletion import cloud.commandframework.arguments.flags.CommandFlag import cloud.commandframework.arguments.standard.IntegerArgument import cloud.commandframework.arguments.standard.StringArgument +import ir.syrent.velocityvanish.spigot.VelocityVanishSpigot import ir.syrent.velocityvanish.spigot.command.library.Command import ir.syrent.velocityvanish.spigot.command.library.interfaces.ISender -import ir.syrent.velocityvanish.spigot.VelocityVanishSpigot import ir.syrent.velocityvanish.spigot.ruom.Ruom import ir.syrent.velocityvanish.spigot.storage.Message import ir.syrent.velocityvanish.spigot.storage.Settings import ir.syrent.velocityvanish.spigot.utils.sendMessage import ir.syrent.velocityvanish.utils.TextReplacement -import net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer -import net.kyori.adventure.text.minimessage.MiniMessage -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import org.bukkit.Bukkit -import org.bukkit.ChatColor import org.bukkit.entity.Player import kotlin.jvm.optionals.getOrNull diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt b/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt index b6e73a26..9c36afd0 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt @@ -45,14 +45,8 @@ class VanishManager( private val potions = mutableSetOf( PotionEffect(PotionEffectType.NIGHT_VISION, Int.MAX_VALUE, 235, false, false), - PotionEffect(PotionEffectType.FIRE_RESISTANCE, Int.MAX_VALUE, 235, false, false), - PotionEffect(PotionEffectType.INVISIBILITY, Int.MAX_VALUE, 235, false, false), ) - init { - if (ServerVersion.supports(13)) potions.add(PotionEffect(PotionEffectType.WATER_BREATHING, Int.MAX_VALUE, 235, false, false)) - } - val invulnerablePlayers = mutableSetOf() fun updateTabState(player: Player, state: GameMode) { diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/utils/NMSUtils.kt b/src/main/java/ir/syrent/velocityvanish/spigot/utils/NMSUtils.kt index 50077168..093406b9 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/utils/NMSUtils.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/utils/NMSUtils.kt @@ -3,6 +3,7 @@ package ir.syrent.velocityvanish.spigot.utils import com.cryptomorin.xseries.ReflectionUtils import io.netty.channel.Channel import ir.syrent.nms.accessors.ConnectionAccessor +import ir.syrent.nms.accessors.ServerCommonPacketListenerImplAccessor import ir.syrent.nms.accessors.ServerGamePacketListenerImplAccessor import ir.syrent.nms.accessors.ServerPlayerAccessor import org.bukkit.entity.Player @@ -42,11 +43,15 @@ object NMSUtils { } } - fun sendPacket(player: Player?, vararg packets: Any?) { + fun sendPacket(player: Player, vararg packets: Any) { try { val connection = getServerGamePacketListener(player) for (packet in packets) { - ServerGamePacketListenerImplAccessor.getMethodSend1().invoke(connection, packet) + if (ServerVersion.supports(20) && ServerVersion.getPatchNumber() >= 2) { + ServerCommonPacketListenerImplAccessor.getMethodSend1().invoke(connection, packet) + } else { + ServerGamePacketListenerImplAccessor.getMethodSend1().invoke(connection, packet) + } } } catch (e: Exception) { e.printStackTrace() diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/utils/ServerVersion.java b/src/main/java/ir/syrent/velocityvanish/spigot/utils/ServerVersion.java index 94d10745..08458e24 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/utils/ServerVersion.java +++ b/src/main/java/ir/syrent/velocityvanish/spigot/utils/ServerVersion.java @@ -22,6 +22,13 @@ public static boolean isSuperLegacy() { return !supports(9); } + /** + * @return The server's patch number. Example return: 1.19.3 -> 3 + */ + public static int getPatchNumber() { + return ReflectionUtils.PATCH_NUMBER; + } + /** * Checks whether the server version is equal or greater than the given version. * @param version the version to compare the server version with