Skip to content

Commit

Permalink
Support Paper's lack of CraftBukkit relocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Apr 28, 2024
1 parent 58d71cb commit 0fa00a8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions spigot/src/main/java/org/geysermc/floodgate/util/ClassNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,26 @@ public class ClassNames {

static {
// ahhhhhhh, this class should really be reworked at this point
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];

String[] versionSplit = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
// Paper, since 1.20.5, no longer relocates CraftBukkit classes
// and NMS classes aren't relocated for a few versions now (both Spigot & Paper)
if (versionSplit.length <= 3 && getClassSilently("net.minecraft.server.MinecraftServer") == null) {
throw new IllegalStateException(
"Was unable to find net.minecraft.server.MinecraftServer. " +
"We don't support Mojmap yet"
);
}
// Makes it that we don't have to lookup both the new and the old
// 'org.bukkit.craftbukkit. + version + CraftPlayer' will be .CraftPlayer on new
// versions and .v1_8R3.CraftPlayer on older versions
String version = versionSplit.length > 3 ? versionSplit[3] + '.' : "";
SPIGOT_MAPPING_PREFIX = "net.minecraft.server." + version;


// SpigotSkinApplier
Class<?> craftPlayerClass = ReflectionUtils.getClass(
"org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
"org.bukkit.craftbukkit." + version + "entity.CraftPlayer");
GET_PROFILE_METHOD = getMethod(craftPlayerClass, "getProfile");
checkNotNull(GET_PROFILE_METHOD, "Get profile method");

Expand All @@ -120,9 +133,9 @@ public class ClassNames {

// WhitelistUtils
Class<?> craftServerClass = ReflectionUtils.getClass(
"org.bukkit.craftbukkit." + version + ".CraftServer");
"org.bukkit.craftbukkit." + version + "CraftServer");
Class<OfflinePlayer> craftOfflinePlayerClass = ReflectionUtils.getCastedClass(
"org.bukkit.craftbukkit." + version + ".CraftOfflinePlayer");
"org.bukkit.craftbukkit." + version + "CraftOfflinePlayer");

CRAFT_OFFLINE_PLAYER_CONSTRUCTOR = ReflectionUtils.getConstructor(
craftOfflinePlayerClass, true, craftServerClass, GameProfile.class);
Expand Down

0 comments on commit 0fa00a8

Please sign in to comment.