diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index 76d717e..c55daed 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -42,9 +42,6 @@ public final class LimboConfig { private int maxPlayers; private PingData pingData; - private boolean useSchematic; - private Path schematicPath; - private String dimensionType; private Location spawnPosition; private int gameMode; @@ -82,7 +79,6 @@ public final class LimboConfig { address = conf.node("bind").get(SocketAddress.class); maxPlayers = conf.node("maxPlayers").getInt(); pingData = conf.node("ping").get(PingData.class); - //useSchematic = conf.node("world", "enable").getBoolean(false); dimensionType = conf.node("dimension").getString(); spawnPosition = conf.node("spawnPosition").get(Location.class); gameMode = conf.node("gameMode").getInt(); @@ -91,9 +87,6 @@ public final class LimboConfig { useBossBar = conf.node("bossBar", "enable").getBoolean(); useTitle = conf.node("title", "enable").getBoolean(); - /*if (useSchematic) - schematicPath = Paths.get(conf.node("world", "path").getString("./spawn.schem"));*/ - if(useBrandName) brandName = conf.node("brandName", "content").getString(); @@ -154,14 +147,6 @@ public final class LimboConfig { return pingData; } - public boolean isUseSchematic() { - return useSchematic; - } - - public Path getSchematicPath() { - return schematicPath; - } - public String getDimensionType() { return dimensionType; } diff --git a/src/main/java/ru/nanit/limbo/world/BlockData.java b/src/main/java/ru/nanit/limbo/world/BlockData.java deleted file mode 100644 index 9e8e03b..0000000 --- a/src/main/java/ru/nanit/limbo/world/BlockData.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world; - -public class BlockData { - - private final String state; - private final int id; - private final byte data; - - public BlockData(String state, int id, byte data) { - this.state = state; - this.id = id; - this.data = data; - } - - public BlockData(String state) { - this(state, 0, (byte) 0); - } - - public BlockData(int id, byte data) { - this(null, id, data); - } - - public String getState() { - return state; - } - - public int getId() { - return id; - } - - public byte getData() { - return data; - } -} diff --git a/src/main/java/ru/nanit/limbo/world/BlockEntity.java b/src/main/java/ru/nanit/limbo/world/BlockEntity.java deleted file mode 100644 index 01eeb4d..0000000 --- a/src/main/java/ru/nanit/limbo/world/BlockEntity.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world; - -import net.kyori.adventure.nbt.CompoundBinaryTag; - -public class BlockEntity { - - private final Location pos; - private final String id; - private final CompoundBinaryTag data; - - public BlockEntity(Location pos, String id, CompoundBinaryTag data) { - this.pos = pos; - this.id = id; - this.data = data; - } - - public Location getPos() { - return pos; - } - - public String getId() { - return id; - } - - public CompoundBinaryTag getData() { - return data; - } -} diff --git a/src/main/java/ru/nanit/limbo/world/BlockMappings.java b/src/main/java/ru/nanit/limbo/world/BlockMappings.java deleted file mode 100644 index 0f5360e..0000000 --- a/src/main/java/ru/nanit/limbo/world/BlockMappings.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world; - -import ru.nanit.limbo.protocol.registry.Version; - -import java.util.HashMap; -import java.util.Map; - -public final class BlockMappings { - - private final Map idToState = new HashMap<>(); - private final Map stateToId = new HashMap<>(); - - public BlockData convert(int id, byte data, Version version) { - if (version.less(Version.V1_13)) - return new BlockData(id, data); - - String state = idToState.get(toId(id, data)); - - return state != null ? new BlockData(state) : null; - } - - public BlockData convert(String state, Version version) { - if (state == null) return null; - - if (version.moreOrEqual(Version.V1_13)) { - return new BlockData(state); - } - - String id = stateToId.get(state); - - if (id != null) { - String[] arr = id.split(":"); - int blockId = Integer.parseInt(arr[0]); - byte data = Byte.parseByte(arr[1]); - - return new BlockData(blockId, data); - } - - return null; - } - - public void register(int id, byte data, String state) { - String strId = toId(id, data); - idToState.put(strId, state); - stateToId.put(state, strId); - } - - private String toId(int id, byte data) { - return id + ":" + data; - } -} diff --git a/src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java b/src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java deleted file mode 100644 index 24ccf1e..0000000 --- a/src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world.schematic; - -import ru.nanit.limbo.world.BlockEntity; -import ru.nanit.limbo.world.BlockMappings; - -import java.util.List; - -public abstract class AbstractSchematic implements Schematic { - - protected final BlockMappings mappings; - - private int width; - private int height; - private int length; - private List blockEntities; - - public AbstractSchematic(BlockMappings mappings) { - this.mappings = mappings; - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLength() { - return length; - } - - @Override - public List getBlockEntities() { - return blockEntities; - } - - public void setWidth(int width) { - this.width = width; - } - - public void setHeight(int height) { - this.height = height; - } - - public void setLength(int length) { - this.length = length; - } - - public void setBlockEntities(List blockEntities) { - this.blockEntities = blockEntities; - } -} diff --git a/src/main/java/ru/nanit/limbo/world/schematic/Schematic.java b/src/main/java/ru/nanit/limbo/world/schematic/Schematic.java deleted file mode 100644 index 24d0102..0000000 --- a/src/main/java/ru/nanit/limbo/world/schematic/Schematic.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world.schematic; - -import ru.nanit.limbo.protocol.registry.Version; -import ru.nanit.limbo.world.BlockData; -import ru.nanit.limbo.world.BlockEntity; -import ru.nanit.limbo.world.Location; - -import java.util.List; - -public interface Schematic { - - int getWidth(); - - int getHeight(); - - int getLength(); - - List getBlockEntities(); - - BlockData getBlock(Location loc, Version version); - -} diff --git a/src/main/java/ru/nanit/limbo/world/schematic/SchematicLoader.java b/src/main/java/ru/nanit/limbo/world/schematic/SchematicLoader.java deleted file mode 100644 index 70596a0..0000000 --- a/src/main/java/ru/nanit/limbo/world/schematic/SchematicLoader.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world.schematic; - -import net.kyori.adventure.nbt.BinaryTag; -import net.kyori.adventure.nbt.BinaryTagIO; -import net.kyori.adventure.nbt.CompoundBinaryTag; -import ru.nanit.limbo.world.BlockEntity; -import ru.nanit.limbo.world.BlockMappings; -import ru.nanit.limbo.world.Location; -import ru.nanit.limbo.world.schematic.versions.LegacySchematic; -import ru.nanit.limbo.world.schematic.versions.SpongeSchematic; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class SchematicLoader { - - private final BlockMappings mappings; - - public SchematicLoader(BlockMappings mappings) { - this.mappings = mappings; - } - - public Schematic load(Path file) throws IOException { - return load(Files.newInputStream(file)); - } - - public Schematic load(InputStream stream) throws IOException { - CompoundBinaryTag nbt = BinaryTagIO.unlimitedReader().read(stream, BinaryTagIO.Compression.GZIP); - - if (nbt.keySet().contains("BlockData")) { - return loadSponge(nbt); - } else { - return loadLegacy(nbt); - } - } - - // Specification: https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-2.md - private Schematic loadSponge(CompoundBinaryTag nbt) { - SpongeSchematic schematic = new SpongeSchematic(mappings); - - schematic.setDataVersion(nbt.getInt("DataVersion")); - - schematic.setWidth(nbt.getShort("Width")); - schematic.setHeight(nbt.getShort("Height")); - schematic.setLength(nbt.getShort("Length")); - - schematic.setPaletteMax(nbt.getInt("PaletteMax")); - - Map palette = new HashMap<>(); - CompoundBinaryTag paletteNbt = nbt.getCompound("Palette"); - - for (String key : paletteNbt.keySet()) { - palette.put(paletteNbt.getInt(key), key); - } - - schematic.setPalette(palette); - schematic.setBlockData(nbt.getByteArray("BlockData")); - - List blockEntities = new LinkedList<>(); - - for (BinaryTag tag : nbt.getList("BlockEntities")) { - if (tag instanceof CompoundBinaryTag) { - CompoundBinaryTag data = (CompoundBinaryTag) tag; - - int[] posArr = data.getIntArray("Pos"); - Location pos = Location.pos(posArr[0], posArr[1], posArr[2]); - String id = data.getString("Id"); - CompoundBinaryTag extra = data.getCompound("Extra"); - - blockEntities.add(new BlockEntity(pos, id, extra)); - } - } - - schematic.setBlockEntities(blockEntities); - - return schematic; - } - - private Schematic loadLegacy(CompoundBinaryTag nbt) { - LegacySchematic schematic = new LegacySchematic(mappings); - - schematic.setWidth(nbt.getShort("Width")); - schematic.setHeight(nbt.getShort("Height")); - schematic.setLength(nbt.getShort("Length")); - - schematic.setMaterials(LegacySchematic.Materials.from(nbt.getString("Materials"))); - - schematic.setBlocks(nbt.getByteArray("Blocks")); - schematic.setAddBlocks(nbt.getByteArray("AddBlocks")); - schematic.setData(nbt.getByteArray("Data")); - - List blockEntities = new LinkedList<>(); - - for (BinaryTag tag : nbt.getList("TileEntities")) { - if (tag instanceof CompoundBinaryTag) { - CompoundBinaryTag data = (CompoundBinaryTag) tag; - - String id = data.getString("id"); - int x = data.getInt("x"); - int y = data.getInt("y"); - int z = data.getInt("z"); - - data.remove("id"); - data.remove("x"); - data.remove("y"); - data.remove("z"); - - blockEntities.add(new BlockEntity(Location.pos(x, y, z), id, data)); - } - } - - schematic.setBlockEntities(blockEntities); - - return schematic; - } -} diff --git a/src/main/java/ru/nanit/limbo/world/schematic/versions/LegacySchematic.java b/src/main/java/ru/nanit/limbo/world/schematic/versions/LegacySchematic.java deleted file mode 100644 index 70614b6..0000000 --- a/src/main/java/ru/nanit/limbo/world/schematic/versions/LegacySchematic.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world.schematic.versions; - -import ru.nanit.limbo.protocol.registry.Version; -import ru.nanit.limbo.world.BlockData; -import ru.nanit.limbo.world.BlockMappings; -import ru.nanit.limbo.world.Location; -import ru.nanit.limbo.world.schematic.AbstractSchematic; - -/** - * Legacy schematic format (1.12-) - */ -public class LegacySchematic extends AbstractSchematic { - - private Materials materials; - private byte[] blocks; - private byte[] addBlocks; - private byte[] data; - - public LegacySchematic(BlockMappings mappings) { - super(mappings); - } - - @Override - public BlockData getBlock(Location loc, Version version) { - int index = (loc.getBlockY() * getLength() + loc.getBlockZ()) * getWidth() + loc.getBlockX(); - byte id = this.blocks[index]; - byte data = this.data[index]; - - return mappings.convert(id, data, version); - } - - public void setMaterials(Materials materials) { - this.materials = materials; - } - - public void setBlocks(byte[] blocks) { - this.blocks = blocks; - } - - public void setAddBlocks(byte[] addBlocks) { - this.addBlocks = addBlocks; - } - - public void setData(byte[] data) { - this.data = data; - } - - @Override - public String toString() { - return "Schematic{" + - "width=" + getWidth() + - ", height=" + getHeight() + - ", length=" + getLength() + - ", materials=" + materials + - ", blocks length=" + blocks.length + - ", addBlocks length=" + addBlocks.length + - ", data length=" + data.length + - ", blockEntities=" + getBlockEntities() + - '}'; - } - - public enum Materials { - - CLASSIC, - ALPHA, - POCKET; - - public static Materials from(String value) { - switch (value.toLowerCase()) { - case "classic": return CLASSIC; - case "alpha": return ALPHA; - case "pocket": return POCKET; - default: throw new IllegalArgumentException("Invalid materials type"); - } - } - } -} diff --git a/src/main/java/ru/nanit/limbo/world/schematic/versions/SpongeSchematic.java b/src/main/java/ru/nanit/limbo/world/schematic/versions/SpongeSchematic.java deleted file mode 100644 index bc6010c..0000000 --- a/src/main/java/ru/nanit/limbo/world/schematic/versions/SpongeSchematic.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 ru.nanit.limbo.world.schematic.versions; - -import ru.nanit.limbo.protocol.registry.Version; -import ru.nanit.limbo.world.BlockData; -import ru.nanit.limbo.world.BlockMappings; -import ru.nanit.limbo.world.Location; -import ru.nanit.limbo.world.schematic.AbstractSchematic; - -import java.util.Map; - -/** - * Modern schematic format (Sponge second specification) - */ -public class SpongeSchematic extends AbstractSchematic { - - private int dataVersion; - private int paletteMax; - private Map palette; - private byte[] blockData; - - public SpongeSchematic(BlockMappings mappings) { - super(mappings); - } - - @Override - public BlockData getBlock(Location loc, Version version) { - int index = loc.getBlockX() + loc.getBlockZ() * getWidth() + loc.getBlockY() * getWidth() * getLength(); - int id = blockData[index]; - String state = palette.get(id); - return mappings.convert(state, version); - } - - public void setDataVersion(int dataVersion) { - this.dataVersion = dataVersion; - } - - public void setPaletteMax(int paletteMax) { - this.paletteMax = paletteMax; - } - - public void setPalette(Map palette) { - this.palette = palette; - } - - public void setBlockData(byte[] blockData) { - this.blockData = blockData; - } - - @Override - public String toString() { - return "SpongeSchematic{" + - "dataVersion=" + dataVersion + - ", width=" + getWidth() + - ", height=" + getHeight() + - ", length=" + getLength() + - ", paletteMax=" + paletteMax + - ", palette=" + palette + - ", blockData bytes=" + blockData.length + - ", blockEntities=" + getBlockEntities() + - '}'; - } -} diff --git a/src/test/java/SchematicTest.java b/src/test/java/SchematicTest.java deleted file mode 100644 index 157e434..0000000 --- a/src/test/java/SchematicTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * 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 . - */ - -import org.junit.jupiter.api.Test; -import ru.nanit.limbo.world.BlockMappings; -import ru.nanit.limbo.world.schematic.SchematicLoader; - -import java.io.IOException; -import java.io.InputStream; - -public class SchematicTest { - - @Test - public void testLoading() throws IOException { - BlockMappings mappings = new BlockMappings(); - SchematicLoader loader = new SchematicLoader(mappings); - InputStream stream = getClass().getResourceAsStream("spawn.schem"); - - System.out.println(loader.load(stream)); - } -} diff --git a/src/test/resources/spawn.schem b/src/test/resources/spawn.schem deleted file mode 100644 index 0a800b5..0000000 Binary files a/src/test/resources/spawn.schem and /dev/null differ diff --git a/src/test/resources/test.schematic b/src/test/resources/test.schematic deleted file mode 100644 index 4119765..0000000 Binary files a/src/test/resources/test.schematic and /dev/null differ