mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 17:07:34 +01:00
[ci skip] Use a separate interface for bootstrapping (#9267)
This commit is contained in:
parent
14cfd64d2d
commit
175a774247
@ -194,9 +194,29 @@ index 0000000000000000000000000000000000000000..cdbc93b317b3bab47bf6552c29cfbb2c
|
||||
+ void clearPermissions();
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java b/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..08f2050356acaf74e3210416760e3873c2dafd2c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java
|
||||
@@ -0,0 +1,14 @@
|
||||
+package io.papermc.paper.plugin.bootstrap;
|
||||
+
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+
|
||||
+/**
|
||||
+ * Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
|
||||
+ * instantiation logic.
|
||||
+ * A boostrap context may be used to access data or logic usually provided to {@link org.bukkit.plugin.Plugin} instances
|
||||
+ * like the plugin's configuration or logger during the plugins bootstrap.
|
||||
+ */
|
||||
+@ApiStatus.Experimental
|
||||
+@ApiStatus.NonExtendable
|
||||
+public interface BootstrapContext extends PluginProviderContext {
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/PluginBootstrap.java b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginBootstrap.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ea84b11e8682e73fcd563fec65e76b707546a99e
|
||||
index 0000000000000000000000000000000000000000..288c078da3d3ca78d02caa4e3565ac7cf89f9f9f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginBootstrap.java
|
||||
@@ -0,0 +1,41 @@
|
||||
@ -226,7 +246,7 @@ index 0000000000000000000000000000000000000000..ea84b11e8682e73fcd563fec65e76b70
|
||||
+ *
|
||||
+ * @param context the server provided context
|
||||
+ */
|
||||
+ void bootstrap(@NotNull PluginProviderContext context);
|
||||
+ void bootstrap(@NotNull BootstrapContext context);
|
||||
+
|
||||
+ /**
|
||||
+ * Called by the server to instantiate your main class.
|
||||
@ -243,7 +263,7 @@ index 0000000000000000000000000000000000000000..ea84b11e8682e73fcd563fec65e76b70
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContext.java b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContext.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..a9208254142d270da7bd4815a01b9627c7918c11
|
||||
index 0000000000000000000000000000000000000000..2c14693155de3654d5ca011c63e13e4a1abf2080
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContext.java
|
||||
@@ -0,0 +1,52 @@
|
||||
@ -258,7 +278,7 @@ index 0000000000000000000000000000000000000000..a9208254142d270da7bd4815a01b9627
|
||||
+
|
||||
+/**
|
||||
+ * Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
|
||||
+ * instanciation logic.
|
||||
+ * instantiation logic.
|
||||
+ * A boostrap context may be used to access data or logic usually provided to {@link org.bukkit.plugin.Plugin} instances
|
||||
+ * like the plugin's configuration or logger during the plugins bootstrap.
|
||||
+ */
|
||||
|
@ -595,17 +595,59 @@ index 0000000000000000000000000000000000000000..89bf48fd581ee6580b91e2eb31dd532c
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/PluginBootstrapContextImpl.java b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginBootstrapContextImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..45d6163074c5b4064185a16eb7d9dfe8a94027a4
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginBootstrapContextImpl.java
|
||||
@@ -0,0 +1,37 @@
|
||||
+package io.papermc.paper.plugin.bootstrap;
|
||||
+
|
||||
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
+import io.papermc.paper.plugin.provider.PluginProvider;
|
||||
+import java.nio.file.Path;
|
||||
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public record PluginBootstrapContextImpl(PluginMeta config, Path dataFolder,
|
||||
+ ComponentLogger logger, Path pluginSource) implements BootstrapContext {
|
||||
+
|
||||
+ public static PluginBootstrapContextImpl of(PluginProvider<?> provider, Path pluginFolder) {
|
||||
+ Path dataFolder = pluginFolder.resolve(provider.getMeta().getName());
|
||||
+
|
||||
+ return new PluginBootstrapContextImpl(provider.getMeta(), dataFolder, provider.getLogger(), provider.getSource());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull PluginMeta getConfiguration() {
|
||||
+ return this.config;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Path getDataDirectory() {
|
||||
+ return this.dataFolder;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull ComponentLogger getLogger() {
|
||||
+ return this.logger;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Path getPluginSource() {
|
||||
+ return this.pluginSource;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContextImpl.java b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContextImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..deffde92350f7c74694c2aa69799de446a3c3e0a
|
||||
index 0000000000000000000000000000000000000000..2d08792a3231c997ea64e66211042bfe371a15b9
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/bootstrap/PluginProviderContextImpl.java
|
||||
@@ -0,0 +1,45 @@
|
||||
@@ -0,0 +1,38 @@
|
||||
+package io.papermc.paper.plugin.bootstrap;
|
||||
+
|
||||
+import io.papermc.paper.plugin.PluginInitializerManager;
|
||||
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
+import io.papermc.paper.plugin.provider.PluginProvider;
|
||||
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
@ -620,12 +662,6 @@ index 0000000000000000000000000000000000000000..deffde92350f7c74694c2aa69799de44
|
||||
+ return new PluginProviderContextImpl(config, dataFolder, logger, pluginSource);
|
||||
+ }
|
||||
+
|
||||
+ public static PluginProviderContextImpl of(PluginProvider<?> provider, Path pluginFolder) {
|
||||
+ Path dataFolder = pluginFolder.resolve(provider.getMeta().getName());
|
||||
+
|
||||
+ return new PluginProviderContextImpl(provider.getMeta(), dataFolder, provider.getLogger(), provider.getSource());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull PluginMeta getConfiguration() {
|
||||
+ return this.config;
|
||||
@ -6301,7 +6337,7 @@ index 0000000000000000000000000000000000000000..14ed05945ba5bfeb2b539d4786278b0e
|
||||
+
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/storage/BootstrapProviderStorage.java b/src/main/java/io/papermc/paper/plugin/storage/BootstrapProviderStorage.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..94207f1489dc024dc660cfacaa107cd0c094b99f
|
||||
index 0000000000000000000000000000000000000000..31ec730e63adf82bf9ac02331bc7f186b98c35cf
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/storage/BootstrapProviderStorage.java
|
||||
@@ -0,0 +1,58 @@
|
||||
@ -6309,16 +6345,16 @@ index 0000000000000000000000000000000000000000..94207f1489dc024dc660cfacaa107cd0
|
||||
+
|
||||
+import com.mojang.logging.LogUtils;
|
||||
+import io.papermc.paper.plugin.PluginInitializerManager;
|
||||
+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.bootstrap.PluginProviderContextImpl;
|
||||
+import io.papermc.paper.plugin.provider.entrypoint.DependencyContext;
|
||||
+import io.papermc.paper.plugin.bootstrap.PluginBootstrapContextImpl;
|
||||
+import io.papermc.paper.plugin.entrypoint.dependency.DependencyContextHolder;
|
||||
+import io.papermc.paper.plugin.entrypoint.strategy.modern.ModernPluginLoadingStrategy;
|
||||
+import io.papermc.paper.plugin.entrypoint.strategy.ProviderConfiguration;
|
||||
+import io.papermc.paper.plugin.entrypoint.strategy.modern.ModernPluginLoadingStrategy;
|
||||
+import io.papermc.paper.plugin.provider.PluginProvider;
|
||||
+import io.papermc.paper.plugin.provider.ProviderStatus;
|
||||
+import io.papermc.paper.plugin.provider.ProviderStatusHolder;
|
||||
+import io.papermc.paper.plugin.provider.entrypoint.DependencyContext;
|
||||
+import org.slf4j.Logger;
|
||||
+
|
||||
+public class BootstrapProviderStorage extends SimpleProviderStorage<PluginBootstrap> {
|
||||
@ -6337,7 +6373,7 @@ index 0000000000000000000000000000000000000000..94207f1489dc024dc660cfacaa107cd0
|
||||
+ @Override
|
||||
+ public boolean load(PluginProvider<PluginBootstrap> provider, PluginBootstrap provided) {
|
||||
+ try {
|
||||
+ PluginProviderContext context = PluginProviderContextImpl.of(provider, PluginInitializerManager.instance().pluginDirectoryPath());
|
||||
+ BootstrapContext context = PluginBootstrapContextImpl.of(provider, PluginInitializerManager.instance().pluginDirectoryPath());
|
||||
+ provided.bootstrap(context);
|
||||
+ return true;
|
||||
+ } catch (Throwable e) {
|
||||
|
Loading…
Reference in New Issue
Block a user