9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-19 15:09:18 +00:00

update ItemsAdder namespaces on load data

This commit is contained in:
Julian Krings
2025-08-21 13:50:21 +02:00
parent 6e738e69e7
commit 8662f3b47a
3 changed files with 23 additions and 27 deletions

View File

@@ -7,11 +7,12 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.data.IrisCustomData; import com.volmit.iris.util.data.IrisCustomData;
import com.volmit.iris.util.scheduling.J;
import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.CustomStack;
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
import org.bukkit.block.Block; 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.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -31,12 +32,12 @@ public class ItemAdderDataProvider extends ExternalDataProvider {
@Override @Override
public void init() { public void init() {
try {
updateNamespaces(); updateNamespaces();
} catch (Throwable e) {
Iris.warn("Failed to update ItemAdder namespaces: " + e.getMessage());
J.s(this::updateNamespaces, 20);
} }
@EventHandler
public void onLoadData(ItemsAdderLoadDataEvent event) {
updateNamespaces();
} }
@NotNull @NotNull
@@ -68,33 +69,36 @@ public class ItemAdderDataProvider extends ExternalDataProvider {
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) { public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
return switch (dataType) { return switch (dataType) {
case ENTITY -> List.of(); case ENTITY -> List.of();
case ITEM -> updateNamespaces(dataType, CustomStack.getNamespacedIdsInRegistry() case ITEM -> CustomStack.getNamespacedIdsInRegistry()
.stream() .stream()
.map(Identifier::fromString) .map(Identifier::fromString)
.toList()); .toList();
case BLOCK -> updateNamespaces(dataType, CustomBlock.getNamespacedIdsInRegistry() case BLOCK -> CustomBlock.getNamespacedIdsInRegistry()
.stream() .stream()
.map(Identifier::fromString) .map(Identifier::fromString)
.toList()); .toList();
}; };
} }
private void updateNamespaces() { private void updateNamespaces() {
getTypes(DataType.ITEM); try {
getTypes(DataType.BLOCK); updateNamespaces(DataType.ITEM);
updateNamespaces(DataType.BLOCK);
} catch (Throwable e) {
Iris.warn("Failed to update ItemAdder namespaces: " + e.getMessage());
}
} }
private Collection<Identifier> updateNamespaces(DataType dataType, Collection<Identifier> ids) { private void updateNamespaces(DataType dataType) {
var namespaces = ids.stream().map(Identifier::namespace).collect(Collectors.toSet()); var namespaces = getTypes(dataType).stream().map(Identifier::namespace).collect(Collectors.toSet());
var currentNamespaces = dataType == DataType.ITEM ? itemNamespaces : blockNamespaces; var currentNamespaces = dataType == DataType.ITEM ? itemNamespaces : blockNamespaces;
currentNamespaces.removeIf(n -> !namespaces.contains(n)); currentNamespaces.removeIf(n -> !namespaces.contains(n));
currentNamespaces.addAll(namespaces); currentNamespaces.addAll(namespaces);
return ids;
} }
@Override @Override
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) { public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
if (dataType == DataType.ENTITY) return false; if (dataType == DataType.ENTITY) return false;
return dataType == DataType.ITEM ? this.itemNamespaces.contains(id.namespace()) : this.blockNamespaces.contains(id.namespace()); return dataType == DataType.ITEM ? itemNamespaces.contains(id.namespace()) : blockNamespaces.contains(id.namespace());
} }
} }

View File

@@ -26,11 +26,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.concurrent.atomic.AtomicBoolean;
public class NexoDataProvider extends ExternalDataProvider { public class NexoDataProvider extends ExternalDataProvider {
private final AtomicBoolean failed = new AtomicBoolean(false);
public NexoDataProvider() { public NexoDataProvider() {
super("Nexo"); super("Nexo");
} }
@@ -125,9 +122,4 @@ public class NexoDataProvider extends ExternalDataProvider {
if (dataType == DataType.ENTITY) return false; if (dataType == DataType.ENTITY) return false;
return "nexo".equalsIgnoreCase(id.namespace()); return "nexo".equalsIgnoreCase(id.namespace());
} }
@Override
public boolean isReady() {
return super.isReady() && !failed.get();
}
} }

View File

@@ -69,8 +69,8 @@ public class ExternalDataSVC implements IrisService {
@EventHandler @EventHandler
public void onPluginEnable(PluginEnableEvent e) { public void onPluginEnable(PluginEnableEvent e) {
if (activeProviders.stream().noneMatch(p -> p.getPlugin().equals(e.getPlugin()))) { if (activeProviders.stream().noneMatch(p -> e.getPlugin().equals(p.getPlugin()))) {
providers.stream().filter(p -> p.isReady() && p.getPlugin().equals(e.getPlugin())).findFirst().ifPresent(edp -> { providers.stream().filter(p -> p.isReady() && e.getPlugin().equals(p.getPlugin())).findFirst().ifPresent(edp -> {
activeProviders.add(edp); activeProviders.add(edp);
edp.init(); edp.init();
Iris.instance.registerListener(edp); Iris.instance.registerListener(edp);