Skip to content

Commit c348f85

Browse files
committed
refactor: improve version detection and Spigot server compatibility
1 parent fc1d67b commit c348f85

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

lib/src/main/java/com/georgev22/particle/utils/ReflectionUtils.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package com.georgev22.particle.utils;
2525

2626
import com.georgev22.particle.ParticleConstants;
27-
import org.bukkit.Bukkit;
2827
import org.bukkit.Location;
2928
import org.bukkit.entity.Entity;
3029
import org.bukkit.entity.Player;
@@ -95,11 +94,13 @@ public final class ReflectionUtils {
9594
private static Plugin plugin;
9695

9796
static {
98-
String serverPath = Bukkit.getServer().getClass().getPackage().getName();
99-
String version = serverPath.substring(serverPath.lastIndexOf(".") + 1);
10097
MINECRAFT_VERSION = MinecraftVersion.getCurrentVersion();
98+
String version = MinecraftVersion.getCurrentVersionNameVtoLowerCase();
10199
NET_MINECRAFT_SERVER_PACKAGE_PATH = "net.minecraft" + (MINECRAFT_VERSION.isBelow(MinecraftVersion.V1_17_R1) ? ".server." + version : "");
102-
CRAFT_BUKKIT_PACKAGE_PATH = MINECRAFT_VERSION.isAbove(MinecraftVersion.V1_20_R3) ? "org.bukkit.craftbukkit" : "org.bukkit.craftbukkit." + version;
100+
CRAFT_BUKKIT_PACKAGE_PATH =
101+
MINECRAFT_VERSION.isAbove(MinecraftVersion.V1_20_R3) && isPaper()
102+
? "org.bukkit.craftbukkit"
103+
: "org.bukkit.craftbukkit." + version;
103104
plugin = readDeclaredField(PLUGIN_CLASS_LOADER_PLUGIN_FIELD, ReflectionUtils.class.getClassLoader());
104105
PLAYER_CONNECTION_CACHE = new PlayerConnectionCache();
105106
try {
@@ -556,4 +557,19 @@ public static InputStream getResourceStreamSafe(String resource) {
556557
}
557558
}
558559

560+
public static boolean isPaper() {
561+
try {
562+
Class.forName("com.destroystokyo.paper.PaperConfig");
563+
return true;
564+
} catch (ClassNotFoundException ignored) {
565+
}
566+
try {
567+
Class.forName("io.papermc.paper.configuration.Configuration");
568+
return true;
569+
} catch (ClassNotFoundException ignored) {
570+
}
571+
572+
return false;
573+
}
574+
559575
}

0 commit comments

Comments
 (0)