|
| 1 | +package net.thenextlvl.service; |
| 2 | + |
| 3 | +import io.papermc.paper.plugin.bootstrap.BootstrapContext; |
| 4 | +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; |
| 5 | +import org.jspecify.annotations.NullMarked; |
| 6 | + |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.List; |
| 9 | + |
| 10 | +@NullMarked |
| 11 | +public class ServiceBootstrapper implements PluginBootstrap { |
| 12 | + public static final String ISSUES = "https://github.com/TheNextLvl-net/service-io/issues/new?template=bug_report.yml"; |
| 13 | + public static final boolean COMPATIBILITY_MODE = Boolean.parseBoolean(System.getenv("COMPATIBILITY_MODE")); |
| 14 | + |
| 15 | + @Override |
| 16 | + public void bootstrap(BootstrapContext context) { |
| 17 | + if (COMPATIBILITY_MODE) enableCompatibilityMode(context); |
| 18 | + } |
| 19 | + |
| 20 | + private void enableCompatibilityMode(BootstrapContext context) { |
| 21 | + var logger = context.getLogger(); |
| 22 | + try { |
| 23 | + var meta = context.getConfiguration(); |
| 24 | + |
| 25 | + var metaClass = meta.getClass(); |
| 26 | + var name = metaClass.getDeclaredField("name"); |
| 27 | + var provides = metaClass.getDeclaredField("provides"); |
| 28 | + |
| 29 | + name.trySetAccessible(); |
| 30 | + provides.trySetAccessible(); |
| 31 | + |
| 32 | + var providedPlugins = new ArrayList<>(meta.getProvidedPlugins()); |
| 33 | + providedPlugins.remove("Vault"); |
| 34 | + providedPlugins.add(meta.getName()); |
| 35 | + |
| 36 | + name.set(meta, "Vault"); |
| 37 | + provides.set(meta, List.copyOf(providedPlugins)); |
| 38 | + logger.info("Enabled compatibility mode, only use this if you really need to."); |
| 39 | + } catch (NoSuchFieldException | IllegalAccessException e) { |
| 40 | + logger.warn("Failed to initialize compatibility mode", e); |
| 41 | + logger.warn("Please look for similar issues or report this on GitHub: {}", ISSUES); |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments