mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 03:31:32 +00:00
Resolve plugin blocks again once CraftEngine has loaded them
A startup world builds its engine before CraftEngine loads its packs, so every CraftEngine block resolved as missing and stayed that way. While a provider is still loading, an unclaimed namespaced block now resolves to an air placeholder without a warning, and the worlds that got one hotload once the provider reports its content loaded.
This commit is contained in:
1 parent
6c4e4ef6f7
commit
1ab8aeff9e
4 files changed
+83
No files matched your search
@@ -47,6 +47,11 @@ public abstract class ExternalDataProvider {
|
|||||||
return getPlugin() != null && getPlugin().isEnabled();
|
return getPlugin() != null && getPlugin().isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether the plugin is enabled but has not loaded its blocks and items yet, so a key it may own cannot be judged missing. */
|
||||||
|
public boolean isLoadingContent() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import art.arcane.iris.core.service.ExternalDataSVC;
|
|||||||
import art.arcane.volmlib.util.cache.CacheKey;
|
import art.arcane.volmlib.util.cache.CacheKey;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
|
import art.arcane.iris.spi.IrisServices;
|
||||||
import art.arcane.iris.util.common.data.IrisCustomData;
|
import art.arcane.iris.util.common.data.IrisCustomData;
|
||||||
import art.arcane.volmlib.util.collection.KMap;
|
import art.arcane.volmlib.util.collection.KMap;
|
||||||
import art.arcane.volmlib.util.math.RNG;
|
import art.arcane.volmlib.util.math.RNG;
|
||||||
@@ -32,6 +33,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.ServerLoadEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -57,12 +59,33 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
|||||||
BlockProperty.ofDouble("pitch", 0, 0, 360f, false, true),
|
BlockProperty.ofDouble("pitch", 0, 0, 360f, false, true),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private volatile boolean contentLoaded;
|
||||||
|
|
||||||
public CraftEngineDataProvider() {
|
public CraftEngineDataProvider() {
|
||||||
super("CraftEngine");
|
super("CraftEngine");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
contentLoaded = !CraftEngineBlocks.loadedBlocks().isEmpty() || !CraftEngineItems.loadedItems().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLoadingContent() {
|
||||||
|
return !contentLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerLoad(ServerLoadEvent event) {
|
||||||
|
markContentLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markContentLoaded() {
|
||||||
|
if (contentLoaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
contentLoaded = true;
|
||||||
|
IrisServices.get(ExternalDataSVC.class).onProviderContentLoaded(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,6 +125,7 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onReload(CraftEngineReloadEvent event) {
|
public void onReload(CraftEngineReloadEvent event) {
|
||||||
INMS.get().forgetBlockRules();
|
INMS.get().forgetBlockRules();
|
||||||
|
markContentLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ import art.arcane.iris.core.link.Identifier;
|
|||||||
import art.arcane.iris.core.link.data.DataType;
|
import art.arcane.iris.core.link.data.DataType;
|
||||||
import art.arcane.iris.core.nms.container.BlockProperty;
|
import art.arcane.iris.core.nms.container.BlockProperty;
|
||||||
import art.arcane.iris.core.nms.container.Pair;
|
import art.arcane.iris.core.nms.container.Pair;
|
||||||
|
import art.arcane.iris.core.tools.IrisToolbelt;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
|
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
|
||||||
|
import art.arcane.iris.util.common.scheduling.J;
|
||||||
import art.arcane.volmlib.util.collection.KList;
|
import art.arcane.volmlib.util.collection.KList;
|
||||||
import art.arcane.volmlib.util.collection.KMap;
|
import art.arcane.volmlib.util.collection.KMap;
|
||||||
import art.arcane.iris.util.common.plugin.IrisService;
|
import art.arcane.iris.util.common.plugin.IrisService;
|
||||||
@@ -50,6 +53,7 @@ import java.util.MissingResourceException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ExternalDataSVC implements IrisService, CustomBlockSource {
|
public class ExternalDataSVC implements IrisService, CustomBlockSource {
|
||||||
@@ -68,6 +72,52 @@ public class ExternalDataSVC implements IrisService, CustomBlockSource {
|
|||||||
|
|
||||||
private final KList<ExternalDataProvider> providers = new KList<>();
|
private final KList<ExternalDataProvider> providers = new KList<>();
|
||||||
private final KList<ExternalDataProvider> activeProviders = new KList<>();
|
private final KList<ExternalDataProvider> activeProviders = new KList<>();
|
||||||
|
private final AtomicBoolean placeholdersHandedOut = new AtomicBoolean();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a key that no provider claims may still belong to a provider that has not loaded its
|
||||||
|
* content; if so, the caller gets a placeholder via {@link #placeholderWhileProvidersLoad()}.
|
||||||
|
*/
|
||||||
|
public boolean isAwaitingProviderContent() {
|
||||||
|
return activeProviders.stream().anyMatch(ExternalDataProvider::isLoadingContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Records that a block was resolved to a placeholder, so the engines using it reload once providers have loaded. */
|
||||||
|
public void placeholderWhileProvidersLoad() {
|
||||||
|
placeholdersHandedOut.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reloads the Iris worlds that resolved a block while a provider was still loading, now that it has loaded. */
|
||||||
|
public void onProviderContentLoaded(ExternalDataProvider provider) {
|
||||||
|
if (isAwaitingProviderContent() || !placeholdersHandedOut.getAndSet(false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
J.s(() -> {
|
||||||
|
List<Engine> engines = runningEngines();
|
||||||
|
IrisLogging.info("%s loaded its blocks; reloading %d Iris world(s) that used them.",
|
||||||
|
provider.getPluginId(), engines.size());
|
||||||
|
J.a(() -> engines.forEach(ExternalDataSVC::reloadAfterProviderContent));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Engine> runningEngines() {
|
||||||
|
return Bukkit.getWorlds().stream()
|
||||||
|
.filter(IrisToolbelt::isIrisWorld)
|
||||||
|
.map(IrisToolbelt::access)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(PlatformChunkGenerator::getEngine)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void reloadAfterProviderContent(Engine engine) {
|
||||||
|
try {
|
||||||
|
engine.hotloadSilently();
|
||||||
|
} catch (RuntimeException failure) {
|
||||||
|
IrisLogging.reportError("Could not reload Iris world " + engine.getWorld().name()
|
||||||
|
+ " after its plugin blocks loaded.", failure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ public final class BukkitBlockResolution {
|
|||||||
if (bd.isPresent() && shouldPreventLeafDecay()) {
|
if (bd.isPresent() && shouldPreventLeafDecay()) {
|
||||||
return external.withoutDecay(bd.get());
|
return external.withoutDecay(bd.get());
|
||||||
}
|
}
|
||||||
|
if (bd.isEmpty() && external.isAwaitingProviderContent()) {
|
||||||
|
external.placeholderWhileProvidersLoad();
|
||||||
|
return BukkitBlockResolution.getAir();
|
||||||
|
}
|
||||||
return bd.orElse(null);
|
return bd.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user