Skip to content

Commit

Permalink
Start cleanup of WorldEdit-CLI data versions
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Jul 2, 2023
1 parent 6770ada commit d363848
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,9 +52,9 @@ private Property<?> createProperty(String type, String key, List<String> values)
@Nullable
@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Map<String, FileRegistries.BlockProperty> properties =
Map<String, DataFile.BlockProperty> properties =
CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks.get(blockType.getId()).properties;
Maps.EntryTransformer<String, FileRegistries.BlockProperty, Property<?>> entryTransform =
Maps.EntryTransformer<String, DataFile.BlockProperty, Property<?>> entryTransform =
(key, value) -> createProperty(value.type, key, value.values);
return ImmutableMap.copyOf(Maps.transformEntries(properties, entryTransform));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +101,6 @@ private void setupPlatform() {
WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent());

this.fileRegistries = new FileRegistries(this);
this.fileRegistries.loadDataFiles();
}

private void registerCommands() {
Expand All @@ -116,8 +116,11 @@ private void registerCommands() {
}

public void setupRegistries() {
this.fileRegistries.loadDataFiles();

// Blocks
for (Map.Entry<String, FileRegistries.BlockManifest> manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) {
BlockType.REGISTRY.clear();
for (Map.Entry<String, DataFile.BlockManifest> 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();
Expand All @@ -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));
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.cli.data;

import java.util.List;
import java.util.Map;

public class DataFile {
public Map<String, List<String>> itemtags;
public Map<String, List<String>> blocktags;
public Map<String, List<String>> entitytags;
public List<String> items;
public List<String> entities;
public List<String> biomes;
public Map<String, BlockManifest> blocks;

public static class BlockManifest {
public String defaultstate;
public Map<String, BlockProperty> properties;
}

public static class BlockProperty {
public List<String> values;
public String type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -58,23 +56,4 @@ public DataFile getDataFile() {
return this.dataFile;
}

public static class BlockManifest {
public String defaultstate;
public Map<String, BlockProperty> properties;
}

public static class BlockProperty {
public List<String> values;
public String type;
}

public static class DataFile {
public Map<String, List<String>> itemtags;
public Map<String, List<String>> blocktags;
public Map<String, List<String>> entitytags;
public List<String> items;
public List<String> entities;
public List<String> biomes;
public Map<String, BlockManifest> blocks;
}
}

0 comments on commit d363848

Please sign in to comment.