From 281fbe69a10b6effc0146c201d5dad9a5259c9d2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 23:35:25 +0000 Subject: [PATCH 1/2] Initial plan From 90f1555b03376a2862b1ac58291ef969bad4f40f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 23:45:13 +0000 Subject: [PATCH 2/2] fix: prevent false Bad custom block errors for CraftEngine blocks on initial load CraftEngineCustomBlock.fromMap() no longer delegates to fromId() (which calls CraftEngineHook.exists()). When a YAML entry explicitly declares type: craftengine the block type is already unambiguous, so the CraftEngineCustomBlock is created directly from the id field without requiring CraftEngine's block registry to be populated yet. The fromId() path (used by the short-form creator) keeps the exists() check so it can still distinguish CraftEngine IDs from vanilla material names. Fixes: invalid runtime error on startup when CraftEngine fires its reload event after AOneBlock has already attempted to load phases. Agent-Logs-Url: https://github.com/BentoBoxWorld/AOneBlock/sessions/7e16e2d1-e9ec-4551-b155-ebb10c178074 Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com> --- .../customblock/CraftEngineCustomBlock.java | 8 +++++--- .../CraftEngineCustomBlockTest.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlock.java b/src/main/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlock.java index 0c31d30..e71c703 100644 --- a/src/main/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlock.java +++ b/src/main/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlock.java @@ -27,9 +27,11 @@ public static Optional fromId(String id) { } public static Optional fromMap(Map map) { - return Optional - .ofNullable(Objects.toString(map.get("id"), null)) - .flatMap(CraftEngineCustomBlock::fromId); + String id = Objects.toString(map.get("id"), null); + if (id == null) { + return Optional.empty(); + } + return Optional.of(new CraftEngineCustomBlock(id)); } @Override diff --git a/src/test/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlockTest.java b/src/test/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlockTest.java index cd35d31..4383f96 100644 --- a/src/test/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlockTest.java +++ b/src/test/java/world/bentobox/aoneblock/oneblocks/customblock/CraftEngineCustomBlockTest.java @@ -1,5 +1,6 @@ package world.bentobox.aoneblock.oneblocks.customblock; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.LinkedHashMap; @@ -27,4 +28,23 @@ void fromMapReturnsEmptyWhenIdMissing() { assertTrue(result.isEmpty(), "Should return empty when 'id' is missing"); } + + /** + * {@code fromMap} must succeed even when CraftEngine has not yet loaded its + * block registry (i.e. without calling {@code CraftEngineHook.exists}). + * This prevents false "Bad custom block" errors during the initial server + * start-up phase that occurs before CraftEngine fires its reload event. + */ + @Test + void fromMapReturnsPresentWhenIdProvided() { + Map map = new LinkedHashMap<>(); + map.put("type", "craftengine"); + map.put("id", "oneblock:common_loot_block"); + map.put("probability", 300); + + var result = CraftEngineCustomBlock.fromMap(map); + + assertTrue(result.isPresent(), "Should return a block when 'id' is present, regardless of CraftEngine load state"); + assertInstanceOf(CraftEngineCustomBlock.class, result.get()); + } }