Add support for Sponge API 9+ (#3885)

This commit is contained in:
bloodmc 2024-05-06 13:20:47 -04:00 committed by GitHub
parent d74a4dcb7e
commit 484b04c17b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -49,6 +49,8 @@ import org.spongepowered.plugin.metadata.PluginMetadata;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
@ -197,6 +199,15 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap, LoaderBootstrap, B
}
public void registerListeners(Object obj) {
// Check if we are running Sponge API 9+
try {
final Method method = org.spongepowered.api.event.EventManager.class.getDeclaredMethod("registerListeners", PluginContainer.class, Object.class, MethodHandles.Lookup.class);
method.invoke(this.game.eventManager(), this.pluginContainer, obj, MethodHandles.lookup());
return;
} catch (Throwable t) {
// ignore
}
// Fallback to Sponge API 8
this.game.eventManager().registerListeners(this.pluginContainer, obj);
}