Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public static Optional<CraftEngineCustomBlock> fromId(String id) {
}

public static Optional<CraftEngineCustomBlock> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String, Object> 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());
}
}
Loading