Skip to content

Commit

Permalink
chore: better 1.20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Syrent committed Feb 12, 2024
1 parent 5abc2e8 commit 1cc4045
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID>()

fun updateTabState(player: Player, state: GameMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1cc4045

Please sign in to comment.