mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
Merge branch 'Xiao-MoMi:dev' into dev
This commit is contained in:
@@ -4,6 +4,7 @@ import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
|
||||
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import net.momirealms.craftengine.bukkit.plugin.agent.RuntimePatcher;
|
||||
import net.momirealms.craftengine.bukkit.plugin.classpath.PaperClassPathAppender;
|
||||
import net.momirealms.craftengine.core.plugin.logger.PluginLogger;
|
||||
import net.momirealms.craftengine.core.plugin.logger.Slf4jPluginLogger;
|
||||
@@ -46,13 +47,13 @@ public class PaperCraftEngineBootstrap implements PluginBootstrap {
|
||||
this.plugin.applyDependencies();
|
||||
this.plugin.setUpConfig();
|
||||
if (VersionHelper.isOrAbove1_21_4()) {
|
||||
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, (e) -> {
|
||||
try {
|
||||
this.plugin.injectRegistries();
|
||||
} catch (Throwable ex) {
|
||||
logger.warn("Failed to inject registries", ex);
|
||||
}
|
||||
});
|
||||
new ModernEventHandler(context, this.plugin).register();
|
||||
} else {
|
||||
try {
|
||||
RuntimePatcher.patch(this.plugin);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to patch server", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +61,24 @@ public class PaperCraftEngineBootstrap implements PluginBootstrap {
|
||||
public @NotNull JavaPlugin createPlugin(@NotNull PluginProviderContext context) {
|
||||
return new PaperCraftEnginePlugin(this);
|
||||
}
|
||||
|
||||
public static class ModernEventHandler {
|
||||
private final BootstrapContext context;
|
||||
private final BukkitCraftEngine plugin;
|
||||
|
||||
public ModernEventHandler(BootstrapContext context, BukkitCraftEngine plugin) {
|
||||
this.context = context;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
this.context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, (e) -> {
|
||||
try {
|
||||
this.plugin.injectRegistries();
|
||||
} catch (Throwable ex) {
|
||||
this.plugin.logger().warn("Failed to inject registries", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user