From 51447f447a370a09af042f46f773028741d65798 Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Sun, 2 Jul 2023 21:01:13 +1000 Subject: [PATCH] Use a record for the data file --- .../cli/CLIBlockCategoryRegistry.java | 2 +- .../sk89q/worldedit/cli/CLIBlockRegistry.java | 5 ++-- .../cli/CLIItemCategoryRegistry.java | 2 +- .../com/sk89q/worldedit/cli/CLIWorldEdit.java | 14 +++++------ .../sk89q/worldedit/cli/data/DataFile.java | 23 ++++++++----------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockCategoryRegistry.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockCategoryRegistry.java index 0a751d2dfb..c77821518c 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockCategoryRegistry.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockCategoryRegistry.java @@ -30,7 +30,7 @@ public class CLIBlockCategoryRegistry implements BlockCategoryRegistry { @Override public Set getCategorisedByName(String category) { - return CLIWorldEdit.inst.getFileRegistries().getDataFile().blocktags.getOrDefault(category, Collections.emptyList()).stream() + return CLIWorldEdit.inst.getFileRegistries().getDataFile().blocktags().getOrDefault(category, Collections.emptyList()).stream() .map(BlockType.REGISTRY::get) .collect(Collectors.toSet()); } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java index 97e3cec25c..8a1cf9c73f 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.sk89q.worldedit.cli.data.DataFile; -import com.sk89q.worldedit.cli.data.FileRegistries; import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.EnumProperty; @@ -53,9 +52,9 @@ private Property createProperty(String type, String key, List values) @Override public Map> getProperties(BlockType blockType) { Map properties = - CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks.get(blockType.getId()).properties; + CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks().get(blockType.getId()).properties(); Maps.EntryTransformer> entryTransform = - (key, value) -> createProperty(value.type, key, value.values); + (key, value) -> createProperty(value.type(), key, value.values()); return ImmutableMap.copyOf(Maps.transformEntries(properties, entryTransform)); } } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIItemCategoryRegistry.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIItemCategoryRegistry.java index abd64d540e..efd79ccca3 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIItemCategoryRegistry.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIItemCategoryRegistry.java @@ -29,7 +29,7 @@ public class CLIItemCategoryRegistry implements ItemCategoryRegistry { @Override public Set getCategorisedByName(String category) { - return CLIWorldEdit.inst.getFileRegistries().getDataFile().itemtags.get(category).stream() + return CLIWorldEdit.inst.getFileRegistries().getDataFile().itemtags().get(category).stream() .map(ItemType.REGISTRY::get) .collect(Collectors.toSet()); } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java index e93b82dd73..a1073f307b 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java @@ -120,7 +120,7 @@ public void setupRegistries() { // Blocks BlockType.REGISTRY.clear(); - for (Map.Entry manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) { + for (Map.Entry manifestEntry : fileRegistries.getDataFile().blocks().entrySet()) { if (BlockType.REGISTRY.get(manifestEntry.getKey()) == null) { BlockType.REGISTRY.register(manifestEntry.getKey(), new BlockType(manifestEntry.getKey(), input -> { ParserContext context = new ParserContext(); @@ -129,7 +129,7 @@ public void setupRegistries() { context.setRestricted(false); try { FuzzyBlockState state = (FuzzyBlockState) WorldEdit.getInstance().getBlockFactory().parseFromInput( - manifestEntry.getValue().defaultstate, + manifestEntry.getValue().defaultstate(), context ).toImmutableState(); BlockState defaultState = input.getBlockType().getAllStates().get(0); @@ -148,34 +148,34 @@ public void setupRegistries() { } // Items ItemType.REGISTRY.clear(); - for (String name : fileRegistries.getDataFile().items) { + for (String name : fileRegistries.getDataFile().items()) { if (ItemType.REGISTRY.get(name) == null) { ItemType.REGISTRY.register(name, new ItemType(name)); } } // Entities EntityType.REGISTRY.clear(); - for (String name : fileRegistries.getDataFile().entities) { + for (String name : fileRegistries.getDataFile().entities()) { if (EntityType.REGISTRY.get(name) == null) { EntityType.REGISTRY.register(name, new EntityType(name)); } } // Biomes BiomeType.REGISTRY.clear(); - for (String name : fileRegistries.getDataFile().biomes) { + for (String name : fileRegistries.getDataFile().biomes()) { if (BiomeType.REGISTRY.get(name) == null) { BiomeType.REGISTRY.register(name, new BiomeType(name)); } } // Tags BlockCategory.REGISTRY.clear(); - for (String name : fileRegistries.getDataFile().blocktags.keySet()) { + for (String name : fileRegistries.getDataFile().blocktags().keySet()) { if (BlockCategory.REGISTRY.get(name) == null) { BlockCategory.REGISTRY.register(name, new BlockCategory(name)); } } ItemCategory.REGISTRY.clear(); - for (String name : fileRegistries.getDataFile().itemtags.keySet()) { + for (String name : fileRegistries.getDataFile().itemtags().keySet()) { if (ItemCategory.REGISTRY.get(name) == null) { ItemCategory.REGISTRY.register(name, new ItemCategory(name)); } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/DataFile.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/DataFile.java index 287caf33f7..48388e8375 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/DataFile.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/DataFile.java @@ -22,22 +22,17 @@ import java.util.List; import java.util.Map; -public class DataFile { - public Map> itemtags; - public Map> blocktags; - public Map> entitytags; - public List items; - public List entities; - public List biomes; - public Map blocks; +public record DataFile(Map> itemtags, + Map> blocktags, + Map> entitytags, + List items, + List entities, + List biomes, + Map blocks) { - public static class BlockManifest { - public String defaultstate; - public Map properties; + public record BlockManifest(String defaultstate, Map properties) { } - public static class BlockProperty { - public List values; - public String type; + public record BlockProperty(List values, String type) { } } \ No newline at end of file