From 9f7c48e1cc3e125ffd54c9e0927c9f6c0b78e4e8 Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Sun, 23 Jun 2024 15:37:15 +0200 Subject: [PATCH 1/2] build: update packetevents declaration Packetevents changed how they declare modules in 2.3.1 and ongoing. (Check their discord for more news) --- spigot/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts index eef4cf5..a26c029 100644 --- a/spigot/build.gradle.kts +++ b/spigot/build.gradle.kts @@ -42,7 +42,7 @@ dependencies { exclude("com.convallyria.languagy.libs") } implementation("org.bstats:bstats-bukkit:3.0.2") - implementation("com.github.retrooper.packetevents:spigot:${properties["packetevents_version"]}") + implementation("com.github.retrooper:packetevents-spigot:${properties["packetevents_version"]}") } tasks { From c3f75b62abddabfa3c39c2e4401874266cb1289c Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Sun, 23 Jun 2024 15:40:34 +0200 Subject: [PATCH 2/2] fix: fake players throw NPE when trying to get protocol version --- .../forcepack/spigot/util/ProtocolUtil.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spigot/src/main/java/com/convallyria/forcepack/spigot/util/ProtocolUtil.java b/spigot/src/main/java/com/convallyria/forcepack/spigot/util/ProtocolUtil.java index de29212..3bb4880 100644 --- a/spigot/src/main/java/com/convallyria/forcepack/spigot/util/ProtocolUtil.java +++ b/spigot/src/main/java/com/convallyria/forcepack/spigot/util/ProtocolUtil.java @@ -13,10 +13,19 @@ public class ProtocolUtil { public static int getProtocolVersion(Player player) { - final boolean viaversion = Bukkit.getPluginManager().isPluginEnabled("ViaVersion"); - return viaversion - ? Via.getAPI().getPlayerVersion(player) - : PacketEvents.getAPI().getPlayerManager().getUser(player).getClientVersion().getProtocolVersion(); + if(Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) { + return Via.getAPI().getPlayerVersion(player); + } + + final User user = PacketEvents.getAPI().getPlayerManager().getUser(player); + + // PacketEvents will not create users for fake online players + // so we can safely assume that if the user is null, the player is fake + if(user == null) { + return -1; + } + + return user.getClientVersion().getProtocolVersion(); } private static boolean warnedBadPlugin;