Skip to content

Commit c18009b

Browse files
authored
Merge pull request #108 from TheNextLvl-net/compatibility-mode
Added experimental compatibility mode
2 parents a42a543 + 25f4f86 commit c18009b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

plugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ tasks.test {
6565
paper {
6666
name = "ServiceIO"
6767
main = "net.thenextlvl.service.ServicePlugin"
68+
bootstrapper = "net.thenextlvl.service.ServiceBootstrapper"
6869
author = "NonSwag"
6970
apiVersion = "1.21"
7071
foliaSupported = true
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)