From 0a76f7915a6f5dcc885c507f1470d28c4e18a7b4 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 24 Nov 2026 01:16:48 +0100 Subject: [PATCH] Check world identity and existing blocks across native storage migration --- tools/NetworkCodecProbe.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/NetworkCodecProbe.java b/tools/NetworkCodecProbe.java index 96594cab..7e1599d1 100644 --- a/tools/NetworkCodecProbe.java +++ b/tools/NetworkCodecProbe.java @@ -28,6 +28,23 @@ public final class NetworkCodecProbe extends JavaPlugin { ItemStack[] inventory={new ItemStack(Material.DIRT,64),spice,armour,bread,new ItemStack(Material.COOKED_RABBIT,12),null,null};fixture=new JsonObject();fixture.addProperty("synthetic",true);fixture.addProperty("sourceVersion",Bukkit.getVersion());fixture.addProperty("inventory",(String)encode.invoke(codec,(Object)inventory));var nativePayloads=new JsonArray();var expected=new JsonArray();for(var item:inventory){expected.add(describe(item));nativePayloads.add(item==null?JsonNull.INSTANCE:new JsonPrimitive(Base64.getEncoder().encodeToString(item.serializeAsBytes())));}fixture.add("expected",expected);fixture.add("nativePayloads",nativePayloads);Files.writeString(path,JSON.toJson(fixture)); }else fixture=JsonParser.parseString(Files.readString(path)).getAsJsonObject(); check(fixture.get("synthetic").getAsBoolean(),"Only synthetic inventory fixtures are allowed"); + if(Boolean.getBoolean("dune.codec.worldMigration")){ + World world=Bukkit.getWorlds().getFirst(); + if(mode.equals("export")){ + world.getBlockAt(13,80,13).setType(Material.DIAMOND_BLOCK); + world.getBlockAt(14,80,13).setType(Material.GOLD_BLOCK); + world.setGameRule(GameRule.WATER_SOURCE_CONVERSION,false); + world.setGameRule(GameRule.DO_FIRE_TICK,false); + JsonObject marker=new JsonObject();marker.addProperty("name",world.getName());marker.addProperty("uid",world.getUID().toString());fixture.add("world",marker);Files.writeString(path,JSON.toJson(fixture));world.save(); + }else{ + JsonObject marker=fixture.getAsJsonObject("world");check(marker!=null,"Missing synthetic world fixture"); + check(world.getName().equals(marker.get("name").getAsString()),"Legacy world name changed"); + check(world.getUID().toString().equals(marker.get("uid").getAsString()),"World identity changed"); + check(world.getBlockAt(13,80,13).getType()==Material.DIAMOND_BLOCK&&world.getBlockAt(14,80,13).getType()==Material.GOLD_BLOCK,"Existing blocks changed during storage migration"); + check(Boolean.FALSE.equals(world.getGameRuleValue(GameRule.WATER_SOURCE_CONVERSION))&&Boolean.FALSE.equals(world.getGameRuleValue(GameRule.DO_FIRE_TICK)),"World gamerules changed"); + getLogger().info("WORLD_MIGRATION_SUCCESS legacyName=true identity=true existingBlocks=true gamerules=true"); + } + } ItemStack[] decoded=(ItemStack[])decode.invoke(codec,fixture.get("inventory").getAsString());var expected=fixture.getAsJsonArray("expected");var payloads=fixture.getAsJsonArray("nativePayloads");check(decoded.length==expected.size(),"Inventory slot count changed"); for(int i=0;i