Paper Plugins

This commit is contained in:
Owen1212055
2022-07-06 23:00:36 -04:00
parent 844bc6c46a
commit 23095683d0
40 changed files with 1509 additions and 290 deletions

View File

@@ -0,0 +1,16 @@
package io.papermc.paper.plugin.bootstrap;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
* instantiation logic.
* A bootstrap 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
@NullMarked
@ApiStatus.NonExtendable
public interface BootstrapContext extends PluginProviderContext {
}

View File

@@ -0,0 +1,41 @@
package io.papermc.paper.plugin.bootstrap;
import io.papermc.paper.plugin.provider.util.ProviderUtil;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* A plugin bootstrap is meant for loading certain parts of the plugin before the server is loaded.
* <p>
* Plugin bootstrapping allows values to be initialized in certain parts of the server that might not be allowed
* when the server is running.
* <p>
* Your bootstrap class will be on the same classloader as your JavaPlugin.
* <p>
* <b>All calls to Bukkit may throw a NullPointerExceptions or return null unexpectedly. You should only call api methods that are explicitly documented to work in the bootstrapper</b>
*/
@ApiStatus.Experimental
@NullMarked
@ApiStatus.OverrideOnly
public interface PluginBootstrap {
/**
* Called by the server, allowing you to bootstrap the plugin with a context that provides things like a logger and your shared plugin configuration file.
*
* @param context the server provided context
*/
void bootstrap(BootstrapContext context);
/**
* Called by the server to instantiate your main class.
* Plugins may override this logic to define custom creation logic for said instance, like passing addition
* constructor arguments.
*
* @param context the server created bootstrap object
* @return the server requested instance of the plugins main class.
*/
default JavaPlugin createPlugin(final PluginProviderContext context) {
return ProviderUtil.loadClass(context.getConfiguration().getMainClass(), JavaPlugin.class, this.getClass().getClassLoader());
}
}

View File

@@ -0,0 +1,48 @@
package io.papermc.paper.plugin.bootstrap;
import io.papermc.paper.plugin.configuration.PluginMeta;
import java.nio.file.Path;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
* instantiation logic.
* A bootstrap 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
@NullMarked
@ApiStatus.NonExtendable
public interface PluginProviderContext {
/**
* Provides the plugin's configuration.
*
* @return the plugin's configuration
*/
PluginMeta getConfiguration();
/**
* Provides the path to the data directory of the plugin.
*
* @return the previously described path
*/
Path getDataDirectory();
/**
* Provides the logger used for this plugin.
*
* @return the logger instance
*/
ComponentLogger getLogger();
/**
* Provides the path to the originating source of the plugin, such as the plugin's JAR file.
*
* @return the previously described path
*/
Path getPluginSource();
}