NBT-API

NBT-API

98.9k Downloads

IllegalPluginAccessException when plugin uses `load: STARTUP`

JarvisCraft opened this issue ยท 2 comments

commented

Description

Whenever a plugin specifies load property to STARTUP in its plugin.yml there is a chance that early call to API method will cause IllegalPluginAccessException:

[01:53:16] [pool-7-thread-1/INFO]: [NBTAPI] [NBTAPI] Found Spigot: v1_12_R1! Trying to find NMS support
[01:53:16] [pool-7-thread-1/INFO]: [NBTAPI] [NBTAPI] NMS support 'MC1_12_R1' loaded!
[01:53:16] [pool-7-thread-1/INFO]: [NBTAPI] [NBTAPI] Found Gson: class com.google.gson.Gson
[01:53:18] [pool-7-thread-1/WARN]: [NBTAPI] [NBTAPI] Error enabling Metrics!
org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register task while disabled
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.validate(CraftScheduler.java:488) ~[patched_1.12.2.jar:git-Paper-1618]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:150) ~[patched_1.12.2.jar:git-Paper-1618]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.runTaskLater(CraftScheduler.java:133) ~[patched_1.12.2.jar:git-Paper-1618]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.runTask(CraftScheduler.java:116) ~[patched_1.12.2.jar:git-Paper-1618]
        at {relocated_package}.nbtapi.utils.ApiMetricsLite.<init>(ApiMetricsLite.java:143) ~[?:?]
        at {relocated_package}.nbtapi.utils.MinecraftVersion.init(MinecraftVersion.java:87) ~[?:?]
        at {relocated_package}.nbtapi.utils.MinecraftVersion.getVersion(MinecraftVersion.java:80) ~[?:?]
        at {relocated_package}.nbtapi.utils.nmsmappings.ClassWrapper.<init>(ClassWrapper.java:56) ~[?:?]
        at {relocated_package}.nbtapi.utils.nmsmappings.ClassWrapper.<clinit>(ClassWrapper.java:33) ~[?:?]
        at {relocated_package}.nbtapi.utils.nmsmappings.ReflectionMethod.<clinit>(ReflectionMethod.java:22) ~[?:?]
        at {relocated_package}.nbtapi.NBTContainer.<init>(NBTContainer.java:66) ~[?:?]
< ... >

Specification

The exact dependency is:

<dependency>
    <groupId>de.tr7zw</groupId>
    <artifactId>item-nbt-api</artifactId>
    <version>2.5.0</version>
</dependency>

Running on PaperSpigot 1.12, although this issue seems to be unrelated to the server version.

Possible reason

NBT API attempts to load Metrics provider although it is not yet ready.

Possible fix

Delay call to metrics to Bukkit's first POSTWORLD tick.

commented

Why was this added to wont fix?

commented

Since it's not a functional issue, just causes a the metrics and probably the update check to fail, while not happening in normal usecases. You have to shade it, and then use the nbtapi before the plugin is enabled. That is not intended(neither from the spigot plugin logic, nor the nbtapi).
If this happens to become a regular issue it could be hotfixed by skipping metrics if there is no loaded plugin, but that's not a proper fix.