From fdb7ada29519a2a95fe3c39238aa80d9a1ab4872 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 31 Jul 2018 12:11:10 +1000 Subject: [PATCH] Added some error handling for legacy conversions of schematics. --- .../extent/clipboard/io/SchematicReader.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index a1f32ee01..4e83fb301 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -43,6 +43,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.storage.NBTConversions; @@ -199,9 +200,11 @@ public class SchematicReader implements ClipboardReader { int index = y * width * length + z * width + x; BlockState block = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]); - for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) { - if (handler.isAffectedBlock(block)) { - handler.updateNBT(block, values); + if (block != null) { + for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) { + if (handler.isAffectedBlock(block)) { + handler.updateNBT(block, values); + } } } @@ -223,10 +226,14 @@ public class SchematicReader implements ClipboardReader { BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]); try { - if (tileEntitiesMap.containsKey(pt)) { - clipboard.setBlock(region.getMinimumPoint().add(pt), new BaseBlock(state, new CompoundTag(tileEntitiesMap.get(pt)))); + if (state != null) { + if (tileEntitiesMap.containsKey(pt)) { + clipboard.setBlock(region.getMinimumPoint().add(pt), new BaseBlock(state, new CompoundTag(tileEntitiesMap.get(pt)))); + } else { + clipboard.setBlock(region.getMinimumPoint().add(pt), state); + } } else { - clipboard.setBlock(region.getMinimumPoint().add(pt), state); + log.warning("Unknown block when pasting schematic: " + blocks[index] + ":" + blockData[index] + ". Please report this issue."); } } catch (WorldEditException e) { switch (failedBlockSets) { @@ -259,8 +266,13 @@ public class SchematicReader implements ClipboardReader { Location location = NBTConversions.toLocation(clipboard, compound.getListTag("Pos"), compound.getListTag("Rotation")); if (!id.isEmpty()) { - BaseEntity state = new BaseEntity(EntityTypes.get(id), compound); - clipboard.createEntity(location, state); + EntityType entityType = EntityTypes.get(id.toLowerCase()); + if (entityType != null) { + BaseEntity state = new BaseEntity(entityType, compound); + clipboard.createEntity(location, state); + } else { + log.warning("Unknown entity when pasting schematic: " + id.toLowerCase()); + } } } }