PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
10.04k stars 2.34k forks source link

Can't enable/disable a datapack on startup #11242

Open Valgrifer opened 3 months ago

Valgrifer commented 3 months ago

Stack trace

[22:32:53 ERROR]: [CustomPackLib] an exception was thrown java.lang.NullPointerException: Cannot invoke "net.minecraft.util.debugchart.DebugSampleSubscriptionTracker.shouldLogSamples(net.minecraft.util.debugchart.RemoteDebugSampleType)" because "this.debugSampleSubscriptionTracker" is null at net.minecraft.server.dedicated.DedicatedServer.isTickTimeLoggingEnabled(DedicatedServer.java:901) ~[paper-1.21.1.jar:1.21.1-3-70dfa46] at net.minecraft.server.MinecraftServer.waitForTasks(MinecraftServer.java:1480) ~[paper-1.21.1.jar:1.21.1-3-70dfa46] at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[paper-1.21.1.jar:1.21.1-3-70dfa46] at net.minecraft.server.MinecraftServer.managedBlock(MinecraftServer.java:1466) ~[paper-1.21.1.jar:1.21.1-3-70dfa46] at net.minecraft.server.MinecraftServer.reloadResources(MinecraftServer.java:2359) ~[paper-1.21.1.jar:1.21.1-3-70dfa46] at io.papermc.paper.datapack.PaperDatapack.setEnabled(PaperDatapack.java:48) ~[paper-1.21.1.jar:?] at CustomPackLib-1.0.jar/fr.valcorp.custompacklib.CustomPackLib.lambda$onEnable$3(CustomPackLib.java:90) ~[CustomPackLib-1.0.jar:?] at java.base/java.util.HashMap.forEach(HashMap.java:1429) ~[?:?] at CustomPackLib-1.0.jar/fr.valcorp.custompacklib.CustomPackLib.onEnable(CustomPackLib.java:69) ~[CustomPackLib-1.0.jar:?]

Plugin and Datapack List

pl [22:35:11 INFO]: Server Plugins (1): [22:35:11 INFO]: Bukkit Plugins: [22:35:11 INFO]: - CustomPackLib datapack list [22:35:28 INFO]: There are 10 data pack(s) enabled: [vanilla (built-in)], [file/Terralith_1.21_v2.5.3.zip (world)], [file/Structory_1.21_v1.3.5.zip (world)], [file/Structory_Towers_1.21_v1.0.7.zip (world)], [file/Continents_1.21_v1.1.5.zip (world)], [bundle (feature)], [file/bukkit (world)], [paper (built-in)], [file/Incendium_1.21_DIRECT_PORT_v5.4.0.zip (world)], [file/custom_datapack.zip (world)] [22:35:28 INFO]: There are no more data packs available

Actions to reproduce (if known)

make a plugin load on startup and disable a datapack in "onEnable"

Paper version

[22:35:58 INFO]: This server is running Paper version 1.21.1-3-master@70dfa46 (2024-08-10T13:14:36Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)

Other

No response

Machine-Maker commented 3 months ago

This might be fixable, but I wouldn't recommend triggering a resources reload in the middle of plugin initialization. Instead, I would do it after the server has been loaded. So in the ServerLoadEvent with the STARTUP type, you can do it there without any issues.

Valgrifer commented 3 months ago

I will try, thank you

Valgrifer commented 3 months ago

it works, but it manages the data packs after the world is loaded, I'm not sure that it's good for the world that the data pack is reactivated after the world is loaded especially if the datapack contains paints, enchantments and anything datadriven

Valgrifer commented 3 months ago

I think the best way to do this would be to display a warning instead and rather go with this proposal #11289, it makes more sense. I just discovered the usefulness of bootstrap and it totally corresponds to what I want to do and what I understand of the goal of bootstrap goes in the same direction as my project.

Machine-Maker commented 2 months ago

Ok, I've implemented this functionality in https://github.com/PaperMC/Paper/pull/10711. That PR adds a new lifecycle event to deal with datapack discovery. It allows discovering new datapacks from arbitrary locations as well as removing previously discovered datapacks. I believe it should satisfy this issue, so I'll link it and when that PR is merged, this can be closed.