Add Lifecycle Event system
This event system is separate from Bukkit's event system and is meant for managing resources across reloads and from points in the PluginBootstrap.
This commit is contained in:
@@ -271,4 +271,12 @@ public interface UnsafeValues {
|
||||
*/
|
||||
@Nullable org.bukkit.Color getSpawnEggLayerColor(org.bukkit.entity.EntityType entityType, int layer);
|
||||
// Paper end - spawn egg color visibility
|
||||
|
||||
// Paper start - lifecycle event API
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
@org.jetbrains.annotations.ApiStatus.Internal
|
||||
io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager<org.bukkit.plugin.Plugin> createPluginLifecycleEventManager(final org.bukkit.plugin.java.JavaPlugin plugin, final java.util.function.BooleanSupplier registrationCheck);
|
||||
// Paper end - lifecycle event API
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <p>
|
||||
* The use of {@link PluginBase} is recommended for actual Implementation
|
||||
*/
|
||||
public interface Plugin extends TabExecutor {
|
||||
public interface Plugin extends TabExecutor, io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner { // Paper
|
||||
/**
|
||||
* Returns the folder that the plugin data files are located in. The
|
||||
* folder may not yet exist.
|
||||
@@ -224,4 +224,14 @@ public interface Plugin extends TabExecutor {
|
||||
*/
|
||||
@NotNull
|
||||
public String getName();
|
||||
|
||||
// Paper start - lifecycle events
|
||||
/**
|
||||
* Get the lifecycle event manager for registering handlers
|
||||
* for lifecycle events allowed on the {@link Plugin}.
|
||||
*
|
||||
* @return the lifecycle event manager
|
||||
*/
|
||||
io.papermc.paper.plugin.lifecycle.event.@NotNull LifecycleEventManager<Plugin> getLifecycleManager();
|
||||
// Paper end - lifecycle events
|
||||
}
|
||||
|
||||
@@ -48,6 +48,11 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
private FileConfiguration newConfig = null;
|
||||
private File configFile = null;
|
||||
private Logger logger = null; // Paper - PluginLogger -> Logger
|
||||
// Paper start - lifecycle events
|
||||
@SuppressWarnings("deprecation")
|
||||
private final io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager<org.bukkit.plugin.Plugin> lifecycleEventManager = org.bukkit.Bukkit.getUnsafe().createPluginLifecycleEventManager(this, () -> this.allowsLifecycleRegistration);
|
||||
private boolean allowsLifecycleRegistration = true;
|
||||
// Paper end
|
||||
|
||||
public JavaPlugin() {
|
||||
// Paper start
|
||||
@@ -279,7 +284,9 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
isEnabled = enabled;
|
||||
|
||||
if (isEnabled) {
|
||||
try { // Paper - lifecycle events
|
||||
onEnable();
|
||||
} finally { this.allowsLifecycleRegistration = false; } // Paper - lifecycle events
|
||||
} else {
|
||||
onDisable();
|
||||
}
|
||||
@@ -457,4 +464,11 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
// Paper start - lifecycle events
|
||||
@Override
|
||||
public final io.papermc.paper.plugin.lifecycle.event.@NotNull LifecycleEventManager<org.bukkit.plugin.Plugin> getLifecycleManager() {
|
||||
return this.lifecycleEventManager;
|
||||
}
|
||||
// Paper end - lifecycle events
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user