Validate pack block keys against plugin blocks once they have loaded

This commit is contained in:
piexel committed 2026-11-10 17:32:13 +01:00
1 parent 5ea1a69190
commit bfd2a762c7
3 files changed
+114 -23

No files matched your search

@@ -43,10 +43,12 @@ import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.MissingResourceException;
@@ -73,6 +75,8 @@ public class ExternalDataSVC implements IrisService, CustomBlockSource {
private final KList<ExternalDataProvider> providers = new KList<>();
private final KList<ExternalDataProvider> activeProviders = new KList<>();
private final AtomicBoolean placeholdersHandedOut = new AtomicBoolean();
private final List<Runnable> actionsAwaitingProviderContent = new ArrayList<>();
private volatile boolean serverLoaded;
/**
* Whether a key that no provider claims may still belong to a provider that has not loaded its
@@ -87,8 +91,40 @@ public class ExternalDataSVC implements IrisService, CustomBlockSource {
placeholdersHandedOut.set(true);
}
/**
* Runs {@code action} on the main thread once the server has started and every provider has loaded its blocks and
* items, so whatever it checks against the block registry sees them.
*/
public void afterProviderContentLoads(Runnable action) {
synchronized (actionsAwaitingProviderContent) {
actionsAwaitingProviderContent.add(action);
}
runActionsIfProviderContentLoaded();
}
@EventHandler
public void onServerLoad(ServerLoadEvent event) {
serverLoaded = true;
runActionsIfProviderContentLoaded();
}
private void runActionsIfProviderContentLoaded() {
if (!serverLoaded || isAwaitingProviderContent()) {
return;
}
List<Runnable> actions;
synchronized (actionsAwaitingProviderContent) {
actions = List.copyOf(actionsAwaitingProviderContent);
actionsAwaitingProviderContent.clear();
}
if (!actions.isEmpty()) {
J.s(() -> actions.forEach(Runnable::run));
}
}
/** Reloads the Iris worlds that resolved a block while a provider was still loading, now that it has loaded. */
public void onProviderContentLoaded(ExternalDataProvider provider) {
runActionsIfProviderContentLoaded();
if (isAwaitingProviderContent() || !placeholdersHandedOut.getAndSet(false)) {
return;
}
@@ -132,6 +132,7 @@ public final class BukkitRegistries implements PlatformRegistries {
keys.add(material.getKey().toString());
}
}
keys.addAll(externalKeys(DataType.BLOCK));
return keys;
}
@@ -157,15 +158,18 @@ public final class BukkitRegistries implements PlatformRegistries {
keys.add(material.getKey().toString());
}
}
ExternalDataSVC external = IrisServices.getOrNull(ExternalDataSVC.class);
if (external != null) {
for (Identifier identifier : external.getAllIdentifiers(DataType.ITEM)) {
keys.add(identifier.toString());
}
}
keys.addAll(externalKeys(DataType.ITEM));
return keys;
}
private static List<String> externalKeys(DataType type) {
ExternalDataSVC external = IrisServices.getOrNull(ExternalDataSVC.class);
if (external == null) {
return List.of();
}
return external.getAllIdentifiers(type).stream().map(Identifier::toString).toList();
}
@Override
public List<String> entityKeys() {
List<String> keys = new ArrayList<>();