Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ tasks.test {
paper {
name = "ServiceIO"
main = "net.thenextlvl.service.ServicePlugin"
bootstrapper = "net.thenextlvl.service.ServiceBootstrapper"
author = "NonSwag"
apiVersion = "1.21"
foliaSupported = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.thenextlvl.service;

import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import org.jspecify.annotations.NullMarked;

import java.util.ArrayList;
import java.util.List;

@NullMarked
public class ServiceBootstrapper implements PluginBootstrap {
public static final String ISSUES = "https://github.com/TheNextLvl-net/service-io/issues/new?template=bug_report.yml";
public static final boolean COMPATIBILITY_MODE = Boolean.parseBoolean(System.getenv("COMPATIBILITY_MODE"));

@Override
public void bootstrap(BootstrapContext context) {
if (COMPATIBILITY_MODE) enableCompatibilityMode(context);
}

private void enableCompatibilityMode(BootstrapContext context) {
var logger = context.getLogger();
try {
var meta = context.getConfiguration();

var metaClass = meta.getClass();
var name = metaClass.getDeclaredField("name");
var provides = metaClass.getDeclaredField("provides");

name.trySetAccessible();
provides.trySetAccessible();

var providedPlugins = new ArrayList<>(meta.getProvidedPlugins());
providedPlugins.remove("Vault");
providedPlugins.add(meta.getName());

name.set(meta, "Vault");
provides.set(meta, List.copyOf(providedPlugins));
logger.info("Enabled compatibility mode, only use this if you really need to.");
} catch (NoSuchFieldException | IllegalAccessException e) {
logger.warn("Failed to initialize compatibility mode", e);
logger.warn("Please look for similar issues or report this on GitHub: {}", ISSUES);
}
}
}