Fix tag lifecycle event handlers not disabling /reload
Dieser Commit ist enthalten in:
Ursprung
9b1ee0d87d
Commit
1bc02e6b23
@ -54,15 +54,12 @@ index 30b50e6294c6eaade5e17cfaf34600d122e6251c..0bb7694188d5fb75bb756ce75d0060ea
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..d0ef7fa0b3e5935d48f894596be6672b0016948a
|
||||
index 0000000000000000000000000000000000000000..ce808520d639581696689a2ab85de00d85aa0ee3
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
@@ -0,0 +1,110 @@
|
||||
@@ -0,0 +1,100 @@
|
||||
+package io.papermc.paper.plugin.lifecycle.event;
|
||||
+
|
||||
+import com.google.common.base.Suppliers;
|
||||
+import com.mojang.logging.LogUtils;
|
||||
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.registrar.PaperRegistrar;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.registrar.RegistrarEvent;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.registrar.RegistrarEventImpl;
|
||||
@ -72,33 +69,27 @@ index 0000000000000000000000000000000000000000..d0ef7fa0b3e5935d48f894596be6672b
|
||||
+import io.papermc.paper.plugin.lifecycle.event.types.OwnerAwareLifecycleEvent;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+import java.util.Set;
|
||||
+import java.util.function.Predicate;
|
||||
+import java.util.function.Supplier;
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.slf4j.Logger;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public class LifecycleEventRunner {
|
||||
+
|
||||
+ private static final Logger LOGGER = LogUtils.getClassLogger();
|
||||
+ private static final Supplier<Set<LifecycleEventType<?, ?, ?>>> BLOCKS_RELOADING = Suppliers.memoize(() -> Set.of( // lazy due to cyclic initialization
|
||||
+ ));
|
||||
+ public static final LifecycleEventRunner INSTANCE = new LifecycleEventRunner();
|
||||
+
|
||||
+ private final List<LifecycleEventType<?, ?, ?>> lifecycleEventTypes = new ArrayList<>();
|
||||
+ private boolean blockPluginReloading = false;
|
||||
+
|
||||
+ public void checkRegisteredHandler(final LifecycleEventOwner owner, final LifecycleEventType<?, ?, ?> eventType) {
|
||||
+ public <O extends LifecycleEventOwner> void checkRegisteredHandler(final O owner, final AbstractLifecycleEventType<O, ?, ?> eventType) {
|
||||
+ /*
|
||||
+ Lifecycle event handlers for reloadable events that are registered from the BootstrapContext prevent
|
||||
+ the server from reloading plugins. This is because reloading plugins requires disabling all the plugins,
|
||||
+ running the reload logic (which would include places where these events should fire) and then re-enabling plugins.
|
||||
+ */
|
||||
+ if (owner instanceof BootstrapContext && BLOCKS_RELOADING.get().contains(eventType)) {
|
||||
+ if (eventType.blocksReloading(owner)) {
|
||||
+ this.blockPluginReloading = true;
|
||||
+ }
|
||||
+ }
|
||||
@ -107,9 +98,8 @@ index 0000000000000000000000000000000000000000..d0ef7fa0b3e5935d48f894596be6672b
|
||||
+ return this.blockPluginReloading;
|
||||
+ }
|
||||
+
|
||||
+ public <O extends LifecycleEventOwner, E extends LifecycleEvent, ET extends LifecycleEventType<O, E, ?>> ET addEventType(final ET eventType) {
|
||||
+ public <O extends LifecycleEventOwner, E extends LifecycleEvent, ET extends LifecycleEventType<O, E, ?>> void addEventType(final ET eventType) {
|
||||
+ this.lifecycleEventTypes.add(eventType);
|
||||
+ return eventType;
|
||||
+ }
|
||||
+
|
||||
+ public <O extends LifecycleEventOwner, E extends PaperLifecycleEvent> void callEvent(final LifecycleEventType<O, ? super E, ?> eventType, final E event) {
|
||||
@ -429,12 +419,13 @@ index 0000000000000000000000000000000000000000..6d530c52aaf0dc2cdfe3bd56af557274
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/AbstractLifecycleEventType.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/AbstractLifecycleEventType.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..30f47879f87fc991c651416546c2f068209545f2
|
||||
index 0000000000000000000000000000000000000000..01a4e9a36a9970f30ed9f9236fc5a4a1cf71844e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/AbstractLifecycleEventType.java
|
||||
@@ -0,0 +1,56 @@
|
||||
@@ -0,0 +1,62 @@
|
||||
+package io.papermc.paper.plugin.lifecycle.event.types;
|
||||
+
|
||||
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner;
|
||||
@ -455,6 +446,7 @@ index 0000000000000000000000000000000000000000..30f47879f87fc991c651416546c2f068
|
||||
+ protected AbstractLifecycleEventType(final String name, final Class<? extends O> ownerType) {
|
||||
+ this.name = name;
|
||||
+ this.ownerType = ownerType;
|
||||
+ LifecycleEventRunner.INSTANCE.addEventType(this);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
@ -468,6 +460,10 @@ index 0000000000000000000000000000000000000000..30f47879f87fc991c651416546c2f068
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public boolean blocksReloading(final O eventOwner) {
|
||||
+ return eventOwner instanceof BootstrapContext;
|
||||
+ }
|
||||
+
|
||||
+ public abstract boolean hasHandlers();
|
||||
+
|
||||
+ public abstract void forEachHandler(E event, Consumer<RegisteredHandler<O, E>> consumer, Predicate<RegisteredHandler<O, E>> predicate);
|
||||
@ -491,7 +487,7 @@ index 0000000000000000000000000000000000000000..30f47879f87fc991c651416546c2f068
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..7e84e0acd50ef04fa1ee2577f49e51c63f5ba5c3
|
||||
index 0000000000000000000000000000000000000000..b11346e04bb16c3238f32deb87dbd680e261d4d2
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java
|
||||
@@ -0,0 +1,25 @@
|
||||
@ -512,12 +508,12 @@ index 0000000000000000000000000000000000000000..7e84e0acd50ef04fa1ee2577f49e51c6
|
||||
+
|
||||
+ @Override
|
||||
+ public <O extends LifecycleEventOwner, E extends LifecycleEvent> LifecycleEventType.Monitorable<O, E> monitor(final String name, final Class<? extends O> ownerType) {
|
||||
+ return LifecycleEventRunner.INSTANCE.addEventType(new MonitorableLifecycleEventType<>(name, ownerType));
|
||||
+ return new MonitorableLifecycleEventType<>(name, ownerType);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public <O extends LifecycleEventOwner, E extends LifecycleEvent> LifecycleEventType.Prioritizable<O, E> prioritized(final String name, final Class<? extends O> ownerType) {
|
||||
+ return LifecycleEventRunner.INSTANCE.addEventType(new PrioritizableLifecycleEventType.Simple<>(name, ownerType));
|
||||
+ return new PrioritizableLifecycleEventType.Simple<>(name, ownerType);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/MonitorableLifecycleEventType.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/MonitorableLifecycleEventType.java
|
||||
|
@ -2010,26 +2010,6 @@ index 0000000000000000000000000000000000000000..0c3c82b28e581286b798ee58ca4193ef
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
index d0ef7fa0b3e5935d48f894596be6672b0016948a..cca76f2d1623952017a83fdb027f77a601c79b3e 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
@@ -9,6 +9,7 @@ import io.papermc.paper.plugin.lifecycle.event.registrar.RegistrarEventImpl;
|
||||
import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.AbstractLifecycleEventType;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.OwnerAwareLifecycleEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,6 +27,7 @@ public class LifecycleEventRunner {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getClassLogger();
|
||||
private static final Supplier<Set<LifecycleEventType<?, ?, ?>>> BLOCKS_RELOADING = Suppliers.memoize(() -> Set.of( // lazy due to cyclic initialization
|
||||
+ LifecycleEvents.COMMANDS
|
||||
));
|
||||
public static final LifecycleEventRunner INSTANCE = new LifecycleEventRunner();
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/commands/CommandSource.java b/src/main/java/net/minecraft/commands/CommandSource.java
|
||||
index 5ba0ef6eda157c4e61d1de99c6b017ceb34430ec..bc5fc57018e347caa5ca453430a45669e086bb22 100644
|
||||
--- a/src/main/java/net/minecraft/commands/CommandSource.java
|
||||
|
@ -9,7 +9,7 @@ public net.minecraft.resources.RegistryOps lookupProvider
|
||||
public net.minecraft.resources.RegistryOps$HolderLookupAdapter
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
index 70e2c3b5cac9a0dfb043de218df20dc1ab2cc070..38222dca2497cec5b104b21429a9ec3aaf05d99e 100644
|
||||
index c92ce42398a9bfd00eb4e05972289c521ee255cf..fba7c1758439db9044d9f7368bc9b79642d6b1b9 100644
|
||||
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
@@ -2,6 +2,7 @@ package io.papermc.paper.registry;
|
||||
@ -695,10 +695,10 @@ index 0000000000000000000000000000000000000000..cc9c8fd313f530777af80ad79e03903f
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5e09cebc3893ab788f7b1d169c5ac48a3e45afc1
|
||||
index 0000000000000000000000000000000000000000..bfcd0884d778ca62817fb1d22f0f2ed1f2abe855
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java
|
||||
@@ -0,0 +1,46 @@
|
||||
@@ -0,0 +1,45 @@
|
||||
+package io.papermc.paper.registry.event;
|
||||
+
|
||||
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
@ -728,7 +728,6 @@ index 0000000000000000000000000000000000000000..5e09cebc3893ab788f7b1d169c5ac48a
|
||||
+ eventType = (ET) this.eventTypes.get(registryKey);
|
||||
+ } else {
|
||||
+ eventType = eventTypeCreator.apply(registryKey, this.name);
|
||||
+ LifecycleEventRunner.INSTANCE.addEventType(eventType);
|
||||
+ this.eventTypes.put(registryKey, eventType);
|
||||
+ }
|
||||
+ return eventType;
|
||||
@ -822,10 +821,10 @@ index 0000000000000000000000000000000000000000..14d2d9766b8dee763f220c397aba3ad4
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0655386f85148cdb840d43ada97ab86bb773a765
|
||||
index 0000000000000000000000000000000000000000..fbf853bf1cbb3c7bbef531afe185818b9454299b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java
|
||||
@@ -0,0 +1,32 @@
|
||||
@@ -0,0 +1,37 @@
|
||||
+package io.papermc.paper.registry.event.type;
|
||||
+
|
||||
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
@ -844,6 +843,11 @@ index 0000000000000000000000000000000000000000..0655386f85148cdb840d43ada97ab86b
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean blocksReloading(final BootstrapContext eventOwner) {
|
||||
+ return false; // only runs once
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public RegistryEntryAddConfiguration<T> newHandler(final LifecycleEventHandler<? super RegistryEntryAddEvent<T, B>> handler) {
|
||||
+ return new RegistryEntryAddHandlerConfiguration<>(handler, this);
|
||||
+ }
|
||||
@ -908,10 +912,10 @@ index 0000000000000000000000000000000000000000..548f5bf979e88708e98d04dfe22ccaa3
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..159bb82c27e8fc8f350985f03082fe218fda3568
|
||||
index 0000000000000000000000000000000000000000..7ee77022198bf5f9f88c6a1917a1da30b1863883
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java
|
||||
@@ -0,0 +1,13 @@
|
||||
@@ -0,0 +1,18 @@
|
||||
+package io.papermc.paper.registry.event.type;
|
||||
+
|
||||
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
@ -924,6 +928,11 @@ index 0000000000000000000000000000000000000000..159bb82c27e8fc8f350985f03082fe21
|
||||
+ public RegistryLifecycleEventType(final RegistryKey<T> registryKey, final String eventName) {
|
||||
+ super(registryKey + " / " + eventName, BootstrapContext.class);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean blocksReloading(final BootstrapContext eventOwner) {
|
||||
+ return false; // only runs once
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java
|
||||
index 5562e8da5ebaef2a3add46e88d64358b7737b59e..e5880f76cdb8ebf01fcefdf77ba9b95674b997a8 100644
|
||||
|
@ -9,7 +9,7 @@ public net/minecraft/tags/TagEntry tag
|
||||
public net/minecraft/tags/TagEntry required
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java
|
||||
index 7e84e0acd50ef04fa1ee2577f49e51c63f5ba5c3..05ceb6a0556c5e958237cd8e17525343dc3e8458 100644
|
||||
index b11346e04bb16c3238f32deb87dbd680e261d4d2..996bac2fab8fb927d184fb62e043454e877727a6 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java
|
||||
@@ -13,6 +13,8 @@ public final class LifecycleEventTypeProviderImpl implements LifecycleEventTypeP
|
||||
@ -20,10 +20,10 @@ index 7e84e0acd50ef04fa1ee2577f49e51c63f5ba5c3..05ceb6a0556c5e958237cd8e17525343
|
||||
+
|
||||
@Override
|
||||
public <O extends LifecycleEventOwner, E extends LifecycleEvent> LifecycleEventType.Monitorable<O, E> monitor(final String name, final Class<? extends O> ownerType) {
|
||||
return LifecycleEventRunner.INSTANCE.addEventType(new MonitorableLifecycleEventType<>(name, ownerType));
|
||||
return new MonitorableLifecycleEventType<>(name, ownerType);
|
||||
@@ -22,4 +24,9 @@ public final class LifecycleEventTypeProviderImpl implements LifecycleEventTypeP
|
||||
public <O extends LifecycleEventOwner, E extends LifecycleEvent> LifecycleEventType.Prioritizable<O, E> prioritized(final String name, final Class<? extends O> ownerType) {
|
||||
return LifecycleEventRunner.INSTANCE.addEventType(new PrioritizableLifecycleEventType.Simple<>(name, ownerType));
|
||||
return new PrioritizableLifecycleEventType.Simple<>(name, ownerType);
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren