Bastian / bstats-metrics

The different bStats Metrics classes
https://bStats.org
MIT License
98 stars 114 forks source link

paper-plugin Support #120

Closed bonn2 closed 1 year ago

bonn2 commented 1 year ago

When trying to use bStats in papers new classloader. It fails to start because it fails its relocation check despite that as far as I can tell it should work like this.

Example implementation

public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) {
        MavenLibraryResolver resolver = new MavenLibraryResolver();
        // Paper repo used for bStats
        resolver.addRepository(new RemoteRepository.Builder("paper", "default", "https://repo.papermc.io/repository/maven-public/").build());
        // Add dependencies
        resolver.addDependency(new Dependency(new DefaultArtifact("org.bstats:bstats-bukkit:3.0.2"), null));
        // Add dependencies to classpath
        classpathBuilder.addLibrary(resolver);
}

results in this error

[15:27:44 ERROR]: Error occurred while enabling SlashSlime v1.0.0 (Is it up to date?)
java.lang.IllegalStateException: bStats Metrics class has not been relocated correctly!
        at org.bstats.MetricsBase.checkRelocation(MetricsBase.java:251) ~[?:?]
        at org.bstats.MetricsBase.<init>(MetricsBase.java:121) ~[?:?]
        at org.bstats.bukkit.Metrics.<init>(Metrics.java:74) ~[?:?]
        at net.bonn2.slashslime.SlashSlime.onEnable(SlashSlime.java:39) ~[SlashSlime-1.0.0.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:279) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[paper-1.19.4.jar:git-Paper-519]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.19.4.jar:git-Paper-519]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.enablePlugin(CraftServer.java:555) ~[paper-1.19.4.jar:git-Paper-519]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.enablePlugins(CraftServer.java:466) ~[paper-1.19.4.jar:git-Paper-519]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:638) ~[paper-1.19.4.jar:git-Paper-519]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:437) ~[paper-1.19.4.jar:git-Paper-519]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:308) ~[paper-1.19.4.jar:git-Paper-519]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1104) ~[paper-1.19.4.jar:git-Paper-519]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[paper-1.19.4.jar:git-Paper-519]
        at java.lang.Thread.run(Thread.java:1589) ~[?:?]
wtlgo commented 1 year ago

Apparently, the developer doesn't allow us to use the library this way, so we are all stuck with the shading process if we wish to use bStats ¯\(ツ)

mdcfe commented 1 year ago

By allowing unrelocated uses of bStats Metrics, you open up the possibility of plugins inadvertently using other plugins' versions of the library on older Spigot/Paper versions, potentially including modified versions that force enable metrics collection for all plugins (this has happened before).

As explained in #106, the bStats library is small and simple enough that there's no meaningful benefit to downloading it at runtime, and so there's no reason not to shade and relocate the library in.