Check world identity and existing blocks across native storage migration

This commit is contained in:
Dev 2026-11-24 01:16:48 +01:00
commit 0a76f7915a

View file

@ -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<decoded.length;i++){check(describe(decoded[i]).equals(expected.get(i)),"Network inventory changed at slot "+i);if(!payloads.get(i).isJsonNull())check(describe(ItemStack.deserializeBytes(Base64.getDecoder().decode(payloads.get(i).getAsString()))).equals(expected.get(i)),"Exchange payload changed at slot "+i);}
var receipt=new JsonObject();receipt.addProperty("mode",mode);receipt.addProperty("passed",true);receipt.addProperty("databaseConnected",false);receipt.addProperty("sourceVersion",fixture.get("sourceVersion").getAsString());receipt.addProperty("targetVersion",Bukkit.getVersion());receipt.addProperty("slots",decoded.length);Files.writeString(Path.of("codec-result.json"),JSON.toJson(receipt));getLogger().info("NETWORK_CODEC_SUCCESS "+JSON.toJson(receipt).replace('\n',' '));