mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Release the plugin instance and runtime statics on disable
A disabled Iris stayed reachable through statics and a re-enable in the same JVM answered from the previous boot's caches. Disable now releases the instance, services, capability singletons and host bindings, and reaching Iris afterwards fails with "Iris is disabled" instead of a NullPointerException.
Upstream: 6c6dba023
This commit is contained in:
1 parent
c77a9fb012
commit
128e90ea9b
10 files changed
+173
-13
No files matched your search
@@ -158,6 +158,16 @@ public class ServerConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
loadedDatapackRuntimeReady = false;
|
||||
loadedDatapackCompilerInputFingerprint = "";
|
||||
loadedDatapackRegistryRequirements = Map.of();
|
||||
loadedDatapackRuntimeGeneration++;
|
||||
loadedDatapackRestartRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static LoadedDatapackRuntimeInvalidation invalidateLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
boolean wasReady = loadedDatapackRuntimeReady;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.core.ServerConfigurator;
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.runtime.WorldRuntimeControlService;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
|
||||
/**
|
||||
* Drops every process-wide cache core keeps about the running server, so a disable leaves nothing an
|
||||
* enable in the same JVM could answer from. The host bindings are not cleared here: core still logs
|
||||
* through them while the adapter finishes its own teardown.
|
||||
*/
|
||||
public final class IrisRuntimeStatics {
|
||||
private IrisRuntimeStatics() {
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
IrisServices.clear();
|
||||
WorldLifecycleService.reset();
|
||||
WorldRuntimeControlService.reset();
|
||||
ServerConfigurator.resetLoadedDatapackRuntime();
|
||||
IrisLanguage.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ public final class WorldLifecycleService {
|
||||
this.worldBackendByKey = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
synchronized (WorldLifecycleService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldLifecycleService get() {
|
||||
WorldLifecycleService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -78,6 +78,11 @@ public final class IrisLanguage {
|
||||
private IrisLanguage() {
|
||||
}
|
||||
|
||||
public static synchronized void shutdown() {
|
||||
dataFolder = null;
|
||||
PLAIN_MEMO.set(null);
|
||||
}
|
||||
|
||||
public static boolean initialize() {
|
||||
if (!IrisPlatforms.isBound()) {
|
||||
return false;
|
||||
|
||||
@@ -79,6 +79,12 @@ public final class WorldRuntimeControlService {
|
||||
+ ", " + backend.describeCapabilities();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
synchronized (WorldRuntimeControlService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldRuntimeControlService get() {
|
||||
WorldRuntimeControlService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -103,6 +103,14 @@ public final class BukkitPlatform implements IrisPlatform {
|
||||
PLUGIN = plugin;
|
||||
}
|
||||
|
||||
public static void releaseHost() {
|
||||
PLUGIN = null;
|
||||
HUD_BAR = null;
|
||||
HUD_LANES = null;
|
||||
CONSOLE = null;
|
||||
BRIDGE = null;
|
||||
}
|
||||
|
||||
public static Plugin plugin() {
|
||||
Plugin plugin = PLUGIN;
|
||||
if (plugin == null) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class IrisRuntimeStaticsTest {
|
||||
@After
|
||||
public void clearStatics() {
|
||||
IrisRuntimeStatics.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetUnbindsEveryRegisteredService() {
|
||||
IrisServices.register(Runnable.class, (Runnable) () -> {
|
||||
});
|
||||
|
||||
IrisRuntimeStatics.reset();
|
||||
|
||||
assertNull(IrisServices.getOrNull(Runnable.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class BukkitPlatformHostReleaseTest {
|
||||
@After
|
||||
public void clearHost() {
|
||||
BukkitPlatform.releaseHost();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releasingTheHostDropsThePluginTheHudAndTheBridges() {
|
||||
BukkitPlatform.hostPlugin(mock(Plugin.class));
|
||||
BukkitPlatform.hostConsoleSender(() -> null);
|
||||
|
||||
BukkitPlatform.releaseHost();
|
||||
|
||||
assertFalse(BukkitPlatform.hasPlugin());
|
||||
assertFalse(BukkitPlatform.hasHud());
|
||||
assertThrows(IllegalStateException.class, BukkitPlatform::console);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user