From d36384881bc61201d69341b9f1292d052ebb022a Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Sun, 25 Jun 2023 22:15:45 +1000 Subject: [PATCH] Start cleanup of WorldEdit-CLI data versions --- .../sk89q/worldedit/cli/CLIBlockRegistry.java | 5 ++- .../sk89q/worldedit/cli/CLICommandSender.java | 5 +-- .../sk89q/worldedit/cli/CLIConfiguration.java | 4 -- .../com/sk89q/worldedit/cli/CLIPlatform.java | 6 --- .../com/sk89q/worldedit/cli/CLIWorldEdit.java | 14 ++++-- .../sk89q/worldedit/cli/data/DataFile.java | 43 +++++++++++++++++++ .../worldedit/cli/data/FileRegistries.java | 21 --------- 7 files changed, 58 insertions(+), 40 deletions(-) create mode 100644 worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/DataFile.java 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 46a804d8e9..97e3cec25c 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 @@ -21,6 +21,7 @@ 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; @@ -51,9 +52,9 @@ private Property createProperty(String type, String key, List values) @Nullable @Override public Map> getProperties(BlockType blockType) { - Map properties = + Map properties = CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks.get(blockType.getId()).properties; - Maps.EntryTransformer> entryTransform = + Maps.EntryTransformer> entryTransform = (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/CLICommandSender.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java index e7205b9d96..7e22ff442a 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java @@ -43,14 +43,11 @@ public class CLICommandSender implements Actor { */ private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be"); - private final CLIWorldEdit app; private final Logger sender; - public CLICommandSender(CLIWorldEdit app, Logger sender) { - checkNotNull(app); + public CLICommandSender(Logger sender) { checkNotNull(sender); - this.app = app; this.sender = sender; } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIConfiguration.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIConfiguration.java index ce935742c2..01daedc125 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIConfiguration.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIConfiguration.java @@ -29,10 +29,6 @@ public CLIConfiguration(CLIWorldEdit app) { super(app.getWorkingDir().resolve("worldedit.properties")); } - @Override - protected void loadExtra() { - } - @Override public Path getWorkingDirectoryPath() { return CLIWorldEdit.inst.getWorkingDir(); diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIPlatform.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIPlatform.java index e0a2d4123d..764d0a27d3 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIPlatform.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIPlatform.java @@ -25,7 +25,6 @@ import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Preference; import com.sk89q.worldedit.util.SideEffect; -import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.registry.Registries; @@ -67,11 +66,6 @@ public void setDataVersion(int dataVersion) { this.dataVersion = dataVersion; } - @Override - public DataFixer getDataFixer() { - return null; - } - @Override public boolean isValidMobType(String type) { return EntityTypes.get(type) != null; 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 d527790157..e93b82dd73 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 @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.cli.data.DataFile; import com.sk89q.worldedit.cli.data.FileRegistries; import com.sk89q.worldedit.cli.schematic.ClipboardWorld; import com.sk89q.worldedit.event.platform.CommandEvent; @@ -100,7 +101,6 @@ private void setupPlatform() { WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent()); this.fileRegistries = new FileRegistries(this); - this.fileRegistries.loadDataFiles(); } private void registerCommands() { @@ -116,8 +116,11 @@ private void registerCommands() { } public void setupRegistries() { + this.fileRegistries.loadDataFiles(); + // Blocks - for (Map.Entry manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) { + BlockType.REGISTRY.clear(); + 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(); @@ -144,29 +147,34 @@ public void setupRegistries() { } } // Items + ItemType.REGISTRY.clear(); 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) { if (EntityType.REGISTRY.get(name) == null) { EntityType.REGISTRY.register(name, new EntityType(name)); } } // Biomes + BiomeType.REGISTRY.clear(); 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()) { if (BlockCategory.REGISTRY.get(name) == null) { BlockCategory.REGISTRY.register(name, new BlockCategory(name)); } } + ItemCategory.REGISTRY.clear(); for (String name : fileRegistries.getDataFile().itemtags.keySet()) { if (ItemCategory.REGISTRY.get(name) == null) { ItemCategory.REGISTRY.register(name, new ItemCategory(name)); @@ -185,7 +193,7 @@ public void onInitialized() { } } - this.commandSender = new CLICommandSender(this, LOGGER); + this.commandSender = new CLICommandSender(LOGGER); this.platform = new CLIPlatform(this); LOGGER.info("WorldEdit CLI (version " + getInternalVersion() + ") is loaded"); } 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 new file mode 100644 index 0000000000..287caf33f7 --- /dev/null +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/DataFile.java @@ -0,0 +1,43 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.cli.data; + +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 static class BlockManifest { + public String defaultstate; + public Map properties; + } + + public static class BlockProperty { + public List values; + public String type; + } +} \ No newline at end of file diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java index f716064956..f6e315ac76 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java @@ -30,8 +30,6 @@ import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; public class FileRegistries { @@ -58,23 +56,4 @@ public DataFile getDataFile() { return this.dataFile; } - public static class BlockManifest { - public String defaultstate; - public Map properties; - } - - public static class BlockProperty { - public List values; - public String type; - } - - public static class DataFile { - public Map> itemtags; - public Map> blocktags; - public Map> entitytags; - public List items; - public List entities; - public List biomes; - public Map blocks; - } }