| 1 | package nl.timfalken.copperkeys; |
| 2 | |
| 3 | import io.papermc.paper.datapack.DatapackRegistrar; |
| 4 | import io.papermc.paper.plugin.bootstrap.BootstrapContext; |
| 5 | import io.papermc.paper.plugin.bootstrap.PluginBootstrap; |
| 6 | import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; |
| 7 | import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; |
| 8 | |
| 9 | import java.io.IOException; |
| 10 | import java.net.URI; |
| 11 | import java.net.URISyntaxException; |
| 12 | import java.util.Objects; |
| 13 | |
| 14 | public final class CopperKeysBootstrap implements PluginBootstrap { |
| 15 | @Override |
| 16 | public void bootstrap(BootstrapContext context) { |
| 17 | LifecycleEventManager<BootstrapContext> lifecycle = context.getLifecycleManager(); |
| 18 | lifecycle.registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, event -> { |
| 19 | DatapackRegistrar registrar = event.registrar(); |
| 20 | try { |
| 21 | URI uri = Objects.requireNonNull( |
| 22 | CopperKeysBootstrap.class.getResource("/datapack"), |
| 23 | "Missing /datapack resources" |
| 24 | ).toURI(); |
| 25 | registrar.discoverPack(uri, "advancements"); |
| 26 | } catch (URISyntaxException | IOException ex) { |
| 27 | throw new RuntimeException("Failed to register CopperKeys datapack", ex); |
| 28 | } |
| 29 | }); |
| 30 | } |
| 31 | } |