Use Spleef-OG API

This commit is contained in:
NotAlexNoyle committed 2026-07-13 15:40:11 -04:00
1 parent c9fbd2d966
commit 1657b3a93e
1 file changed
+29 -4
@@ -38,13 +38,14 @@ public final class ProtectedActivity {
private static boolean isInSpleef(Player player) {
if (!isPluginEnabled("Spleef-OG", "ArenaSpleef")) {
Plugin spleef = getEnabledPlugin("Spleef-OG");
if (spleef == null) {
return false;
}
return invoke(getSpleefMethod(), player);
return invoke(getSpleefMethod(spleef), player);
}
@@ -61,11 +62,11 @@ public final class ProtectedActivity {
}
private static Method getSpleefMethod() {
private static Method getSpleefMethod(Plugin spleef) {
if (!spleefLookupComplete) {
spleefIsInSpleef = findMethod("org.battleplugins.arena.spleef.api.SpleefAPI", "isInSpleef");
spleefIsInSpleef = findMethod(spleef, "net.trueog.spleefog.api.SpleefAPI", "isInSpleef");
spleefLookupComplete = true;
}
@@ -90,6 +91,23 @@ public final class ProtectedActivity {
}
private static Method findMethod(Plugin plugin, String className, String methodName) {
try {
Method method = Class.forName(className, true, plugin.getClass().getClassLoader()).getMethod(methodName,
Player.class);
method.setAccessible(true);
return method;
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
return null;
}
}
private static boolean invoke(Method method, Player player) {
if (method == null) {
@@ -127,4 +145,11 @@ public final class ProtectedActivity {
}
private static Plugin getEnabledPlugin(String name) {
Plugin plugin = Bukkit.getPluginManager().getPlugin(name);
return plugin != null && plugin.isEnabled() ? plugin : null;
}
}