From 6e05a2e0be6482bb021610928619f0031a19cd54 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Wed, 14 Feb 2024 11:06:14 +0000 Subject: [PATCH] Get ready for Paper no longer relocating CB under MC ver (#251) --- dough-common/pom.xml | 15 +++++++++++++++ .../dough/reflection/ReflectionUtils.java | 13 +++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dough-common/pom.xml b/dough-common/pom.xml index ef7babd5..1ec9b224 100644 --- a/dough-common/pom.xml +++ b/dough-common/pom.xml @@ -13,4 +13,19 @@ dough-common jar + + + papermc-repo + https://papermc.io/repo/repository/maven-public/ + + + + + + io.papermc + paperlib + 1.0.7 + compile + + diff --git a/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java b/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java index 377a3b88..06b21307 100644 --- a/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java +++ b/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java @@ -14,6 +14,7 @@ import io.github.bakedlibs.dough.versions.MinecraftVersion; import io.github.bakedlibs.dough.versions.UnknownServerVersionException; +import io.papermc.lib.PaperLib; /** * This class provides some useful static methods to perform reflection. @@ -53,10 +54,18 @@ private ReflectionUtils() {} if (versionSpecificPackage == null) { String packageName = Bukkit.getServer().getClass().getPackage().getName(); - versionSpecificPackage = packageName.substring(packageName.lastIndexOf('.') + 1); + + // Paper are no longer relocating CB to live under the version in the package name + // This means org.bukkit.craftbukkit.v1_20_R1.CraftWorld is now org.bukkit.craftbukkit.CraftWorld + // So we check that it is Paper and does NOT have the _v1 in the package name and just return an empty string + if (PaperLib.isPaper() && !packageName.contains(".v1_")) { + return (versionSpecificPackage = ""); + } + + versionSpecificPackage = packageName.substring(packageName.lastIndexOf('.') + 1) + '.'; } - return versionSpecificPackage + '.'; + return versionSpecificPackage; } /**