diff --git a/README.md b/README.md index 59e543a8..233c0da5 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ which will not significantly load the server. Required software: -* JDK 1.8 +* JDK 1.8+ * Gradle 7+ To build minimized .jar, go to project root and write in terminal: diff --git a/build.gradle b/build.gradle index 2e3a3551..fa4b6d1e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'com.github.johnrengelman.shadow' version '7.0.0' id 'java' + id 'com.github.johnrengelman.shadow' version '7.0.0' } group 'ru.nanit' -version '1.3.2' +version '1.4' repositories { mavenCentral() @@ -20,13 +20,13 @@ dependencies { implementation 'com.grack:nanojson:1.7' } -jar { +shadowJar { + from 'LICENSE' + manifest { attributes('Main-Class': 'ru.nanit.limbo.NanoLimbo') } -} -shadowJar { minimize() } diff --git a/src/main/java/ru/nanit/limbo/LimboConstants.java b/src/main/java/ru/nanit/limbo/LimboConstants.java index a4f79293..0c3d5b24 100644 --- a/src/main/java/ru/nanit/limbo/LimboConstants.java +++ b/src/main/java/ru/nanit/limbo/LimboConstants.java @@ -1,8 +1,26 @@ +/* + * 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; public final class LimboConstants { public static final String VELOCITY_INFO_CHANNEL = "velocity:player_info"; + public static final String BRAND_CHANNEL = "minecraft:brand"; private LimboConstants() {} diff --git a/src/main/java/ru/nanit/limbo/NanoLimbo.java b/src/main/java/ru/nanit/limbo/NanoLimbo.java index 313ae361..0ea15d47 100644 --- a/src/main/java/ru/nanit/limbo/NanoLimbo.java +++ b/src/main/java/ru/nanit/limbo/NanoLimbo.java @@ -1,3 +1,20 @@ +/* + * 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; import ru.nanit.limbo.server.LimboServer; diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index 17cef9fd..76d717e5 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -1,3 +1,20 @@ +/* + * 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.configuration; import org.spongepowered.configurate.ConfigurationNode; @@ -6,6 +23,7 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import ru.nanit.limbo.server.data.*; import ru.nanit.limbo.util.Colors; +import ru.nanit.limbo.world.Location; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -24,8 +42,11 @@ public final class LimboConfig { private int maxPlayers; private PingData pingData; + private boolean useSchematic; + private Path schematicPath; + private String dimensionType; - private Position spawnPosition; + private Location spawnPosition; private int gameMode; private boolean useBrandName; @@ -61,14 +82,18 @@ public void load() throws Exception { 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(Position.class); + spawnPosition = conf.node("spawnPosition").get(Location.class); gameMode = conf.node("gameMode").getInt(); useBrandName = conf.node("brandName", "enable").getBoolean(); useJoinMessage = conf.node("joinMessage", "enable").getBoolean(); 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(); @@ -113,7 +138,7 @@ private TypeSerializerCollection getSerializers() { .register(PingData.class, new PingData.Serializer()) .register(BossBar.class, new BossBar.Serializer()) .register(Title.class, new Title.Serializer()) - .register(Position.class, new Position.Serializer()) + .register(Location.class, new Location.Serializer()) .build(); } @@ -129,11 +154,19 @@ public PingData getPingData() { return pingData; } + public boolean isUseSchematic() { + return useSchematic; + } + + public Path getSchematicPath() { + return schematicPath; + } + public String getDimensionType() { return dimensionType; } - public Position getSpawnPosition() { + public Location getSpawnPosition() { return spawnPosition; } diff --git a/src/main/java/ru/nanit/limbo/configuration/SocketAddressSerializer.java b/src/main/java/ru/nanit/limbo/configuration/SocketAddressSerializer.java index f5ff6269..18e737e6 100644 --- a/src/main/java/ru/nanit/limbo/configuration/SocketAddressSerializer.java +++ b/src/main/java/ru/nanit/limbo/configuration/SocketAddressSerializer.java @@ -1,3 +1,20 @@ +/* + * 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.configuration; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java b/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java index 879eca16..f564760b 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java @@ -1,3 +1,20 @@ +/* + * 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.connection; import io.netty.channel.Channel; diff --git a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java index c3969ad7..ea9eb1e5 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java @@ -1,3 +1,20 @@ +/* + * 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.connection; import com.grack.nanojson.JsonArray; @@ -421,7 +438,7 @@ public static void initPackets(LimboServer server) { if (server.getConfig().isUseBrandName()){ PacketPluginMessage pluginMessage = new PacketPluginMessage(); - pluginMessage.setChannel("minecraft:brand"); + pluginMessage.setChannel(LimboConstants.BRAND_CHANNEL); pluginMessage.setMessage(server.getConfig().getBrandName()); PACKET_PLUGIN_MESSAGE = PacketSnapshot.of(pluginMessage); } diff --git a/src/main/java/ru/nanit/limbo/connection/GameProfile.java b/src/main/java/ru/nanit/limbo/connection/GameProfile.java index 754eebdc..7d3dde77 100644 --- a/src/main/java/ru/nanit/limbo/connection/GameProfile.java +++ b/src/main/java/ru/nanit/limbo/connection/GameProfile.java @@ -1,3 +1,20 @@ +/* + * 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.connection; import java.util.UUID; diff --git a/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java b/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java index f4510bd0..cdc07025 100644 --- a/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java +++ b/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java @@ -1,3 +1,20 @@ +/* + * 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.connection.pipeline; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/ru/nanit/limbo/connection/pipeline/PacketEncoder.java b/src/main/java/ru/nanit/limbo/connection/pipeline/PacketEncoder.java index 65f68035..78e5f4c0 100644 --- a/src/main/java/ru/nanit/limbo/connection/pipeline/PacketEncoder.java +++ b/src/main/java/ru/nanit/limbo/connection/pipeline/PacketEncoder.java @@ -1,3 +1,20 @@ +/* + * 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.connection.pipeline; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntByteDecoder.java b/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntByteDecoder.java index 624c8f6b..2f9a611b 100644 --- a/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntByteDecoder.java +++ b/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntByteDecoder.java @@ -1,3 +1,20 @@ +/* + * 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.connection.pipeline; import io.netty.util.ByteProcessor; diff --git a/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntFrameDecoder.java b/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntFrameDecoder.java index 4ea28c7b..861fb64b 100644 --- a/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntFrameDecoder.java +++ b/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntFrameDecoder.java @@ -1,3 +1,20 @@ +/* + * 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.connection.pipeline; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntLengthEncoder.java b/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntLengthEncoder.java index 0a07fd37..940c42fd 100644 --- a/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntLengthEncoder.java +++ b/src/main/java/ru/nanit/limbo/connection/pipeline/VarIntLengthEncoder.java @@ -1,3 +1,20 @@ +/* + * 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.connection.pipeline; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/ru/nanit/limbo/protocol/ByteMessage.java b/src/main/java/ru/nanit/limbo/protocol/ByteMessage.java index 54c3c003..49facd17 100644 --- a/src/main/java/ru/nanit/limbo/protocol/ByteMessage.java +++ b/src/main/java/ru/nanit/limbo/protocol/ByteMessage.java @@ -1,3 +1,20 @@ +/* + * 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.protocol; import io.netty.buffer.*; @@ -143,9 +160,7 @@ public void writeLongArray(long[] array) { } public void writeCompoundTagArray(CompoundBinaryTag[] compoundTags) { - try { - ByteBufOutputStream stream = new ByteBufOutputStream(buf); - + try (ByteBufOutputStream stream = new ByteBufOutputStream(buf)) { writeVarInt(compoundTags.length); for (CompoundBinaryTag tag : compoundTags) { @@ -157,16 +172,16 @@ public void writeCompoundTagArray(CompoundBinaryTag[] compoundTags) { } public CompoundBinaryTag readCompoundTag() { - try { - return BinaryTagIO.reader().read((InputStream) new ByteBufInputStream(buf)); + try (ByteBufInputStream stream = new ByteBufInputStream(buf)) { + return BinaryTagIO.reader().read((InputStream) stream); } catch (IOException thrown) { throw new DecoderException("Cannot read NBT CompoundTag"); } } public void writeCompoundTag(CompoundBinaryTag compoundTag) { - try { - BinaryTagIO.writer().write(compoundTag, (OutputStream) new ByteBufOutputStream(buf)); + try (ByteBufOutputStream stream = new ByteBufOutputStream(buf)) { + BinaryTagIO.writer().write(compoundTag, (OutputStream) stream); } catch (IOException e) { throw new EncoderException("Cannot write NBT CompoundTag"); } diff --git a/src/main/java/ru/nanit/limbo/protocol/Packet.java b/src/main/java/ru/nanit/limbo/protocol/Packet.java index 6ec59a72..3df6dcf2 100644 --- a/src/main/java/ru/nanit/limbo/protocol/Packet.java +++ b/src/main/java/ru/nanit/limbo/protocol/Packet.java @@ -1,3 +1,20 @@ +/* + * 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.protocol; import ru.nanit.limbo.protocol.registry.Version; diff --git a/src/main/java/ru/nanit/limbo/protocol/PacketIn.java b/src/main/java/ru/nanit/limbo/protocol/PacketIn.java index 639d0c2d..ed451974 100644 --- a/src/main/java/ru/nanit/limbo/protocol/PacketIn.java +++ b/src/main/java/ru/nanit/limbo/protocol/PacketIn.java @@ -1,3 +1,20 @@ +/* + * 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.protocol; import ru.nanit.limbo.protocol.registry.Version; diff --git a/src/main/java/ru/nanit/limbo/protocol/PacketOut.java b/src/main/java/ru/nanit/limbo/protocol/PacketOut.java index 78a4a4d0..9d7d9c42 100644 --- a/src/main/java/ru/nanit/limbo/protocol/PacketOut.java +++ b/src/main/java/ru/nanit/limbo/protocol/PacketOut.java @@ -1,3 +1,20 @@ +/* + * 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.protocol; import ru.nanit.limbo.protocol.registry.Version; diff --git a/src/main/java/ru/nanit/limbo/protocol/PacketSnapshot.java b/src/main/java/ru/nanit/limbo/protocol/PacketSnapshot.java index b6e0cbcd..d61c0ed3 100644 --- a/src/main/java/ru/nanit/limbo/protocol/PacketSnapshot.java +++ b/src/main/java/ru/nanit/limbo/protocol/PacketSnapshot.java @@ -1,3 +1,20 @@ +/* + * 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.protocol; import ru.nanit.limbo.protocol.registry.Version; @@ -5,14 +22,19 @@ import java.util.HashMap; import java.util.Map; +/** + * PacketSnapshot encodes packet to byt array for each MC version. + * Some versions have same snapshot, so there are mappings + * to avoid storing same bytes array for different versions + */ public class PacketSnapshot implements PacketOut { private final PacketOut packet; - private final Map versionMessages; + private final Map versionMessages = new HashMap<>(); + private final Map mappings = new HashMap<>(); public PacketSnapshot(PacketOut packet) { this.packet = packet; - this.versionMessages = new HashMap<>(); } public PacketOut getWrappedPacket() { @@ -20,11 +42,24 @@ public PacketOut getWrappedPacket() { } public PacketSnapshot encodePacket() { + Map hashes = new HashMap<>(); + for (Version version : Version.values()) { + if (version.equals(Version.UNDEFINED)) continue; + ByteMessage encodedMessage = ByteMessage.create(); packet.encode(encodedMessage, version); - byte[] message = encodedMessage.toByteArray(); - versionMessages.put(version, message); + + int hash = encodedMessage.hashCode(); + Version hashed = hashes.get(hash); + + if (hashed != null) { + mappings.put(version, hashed); + } else { + hashes.put(hash, version); + versionMessages.put(version, encodedMessage.toByteArray()); + } + encodedMessage.release(); } @@ -33,11 +68,11 @@ public PacketSnapshot encodePacket() { @Override public void encode(ByteMessage msg, Version version) { - byte[] message = versionMessages.get(version); + Version mapped = mappings.get(version); + byte[] message = versionMessages.get(mapped); - if (message != null) { + if (message != null) msg.writeBytes(message); - } } @Override diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/PacketHandshake.java b/src/main/java/ru/nanit/limbo/protocol/packets/PacketHandshake.java index c98b9863..31c475b5 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/PacketHandshake.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/PacketHandshake.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketDisconnect.java b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketDisconnect.java index 2981326a..2ba8b851 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketDisconnect.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketDisconnect.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.login; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginRequest.java b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginRequest.java index 8a45c995..68b80c44 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginRequest.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginRequest.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.login; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginResponse.java b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginResponse.java index 1059a4b8..126ca29a 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginResponse.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginPluginResponse.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.login; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginStart.java b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginStart.java index 3f768fa8..4c8ea4cc 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginStart.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginStart.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.login; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java index 9acd9a47..61999ba5 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.login; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketBossBar.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketBossBar.java index 6addcfea..8361ad20 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketBossBar.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketBossBar.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketChatMessage.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketChatMessage.java index c7b1f1e6..ce1756e9 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketChatMessage.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketChatMessage.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java index c804b51f..fa4cf6f3 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketJoinGame.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketJoinGame.java index 3417575f..fdc33983 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketJoinGame.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketJoinGame.java @@ -1,9 +1,26 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; import ru.nanit.limbo.protocol.PacketOut; import ru.nanit.limbo.protocol.registry.Version; -import ru.nanit.limbo.world.DimensionRegistry; +import ru.nanit.limbo.world.dimension.DimensionRegistry; public class PacketJoinGame implements PacketOut { diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketKeepAlive.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketKeepAlive.java index 5c5b79ad..a92d63a8 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketKeepAlive.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketKeepAlive.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerAbilities.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerAbilities.java index 5d7fe1d2..49e80688 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerAbilities.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerAbilities.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java index 45f57096..9b211bd1 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java index 4775b7cf..c195f492 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java index 84cf6409..e11c4523 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleLegacy.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleLegacy.java index cb7458fc..87a9fe80 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleLegacy.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleLegacy.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetSubTitle.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetSubTitle.java index 6c7a708b..845412ab 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetSubTitle.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetSubTitle.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetTitle.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetTitle.java index 764fa5a0..8c327161 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetTitle.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleSetTitle.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleTimes.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleTimes.java index e9f0c639..5e46dfff 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleTimes.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketTitleTimes.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.play; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusPing.java b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusPing.java index 7ac1d8ce..3bc39ee7 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusPing.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusPing.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.status; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java index ff3b92ef..ce9759c8 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.status; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java index b15e41fe..fb7d5111 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.packets.status; import ru.nanit.limbo.protocol.ByteMessage; diff --git a/src/main/java/ru/nanit/limbo/protocol/registry/State.java b/src/main/java/ru/nanit/limbo/protocol/registry/State.java index 24aec919..65ab4649 100644 --- a/src/main/java/ru/nanit/limbo/protocol/registry/State.java +++ b/src/main/java/ru/nanit/limbo/protocol/registry/State.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.registry; import ru.nanit.limbo.protocol.Packet; diff --git a/src/main/java/ru/nanit/limbo/protocol/registry/Version.java b/src/main/java/ru/nanit/limbo/protocol/registry/Version.java index bb4d19cc..68b5e263 100644 --- a/src/main/java/ru/nanit/limbo/protocol/registry/Version.java +++ b/src/main/java/ru/nanit/limbo/protocol/registry/Version.java @@ -1,3 +1,20 @@ +/* + * 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.protocol.registry; import java.util.HashMap; diff --git a/src/main/java/ru/nanit/limbo/server/Connections.java b/src/main/java/ru/nanit/limbo/server/Connections.java index 0713516b..0cc4a7b3 100644 --- a/src/main/java/ru/nanit/limbo/server/Connections.java +++ b/src/main/java/ru/nanit/limbo/server/Connections.java @@ -1,3 +1,20 @@ +/* + * 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.server; import ru.nanit.limbo.connection.ClientConnection; diff --git a/src/main/java/ru/nanit/limbo/server/LimboServer.java b/src/main/java/ru/nanit/limbo/server/LimboServer.java index 12dcb34f..bacbdae2 100644 --- a/src/main/java/ru/nanit/limbo/server/LimboServer.java +++ b/src/main/java/ru/nanit/limbo/server/LimboServer.java @@ -1,3 +1,20 @@ +/* + * 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.server; import io.netty.bootstrap.ServerBootstrap; @@ -14,7 +31,7 @@ import ru.nanit.limbo.connection.ClientChannelInitializer; import ru.nanit.limbo.connection.ClientConnection; import ru.nanit.limbo.util.Logger; -import ru.nanit.limbo.world.DimensionRegistry; +import ru.nanit.limbo.world.dimension.DimensionRegistry; import java.nio.file.Paths; import java.util.concurrent.ScheduledFuture; diff --git a/src/main/java/ru/nanit/limbo/server/data/BossBar.java b/src/main/java/ru/nanit/limbo/server/data/BossBar.java index b42795b9..d77e89df 100644 --- a/src/main/java/ru/nanit/limbo/server/data/BossBar.java +++ b/src/main/java/ru/nanit/limbo/server/data/BossBar.java @@ -1,3 +1,20 @@ +/* + * 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.server.data; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/src/main/java/ru/nanit/limbo/server/data/InfoForwarding.java b/src/main/java/ru/nanit/limbo/server/data/InfoForwarding.java index 711788ab..f96869f9 100644 --- a/src/main/java/ru/nanit/limbo/server/data/InfoForwarding.java +++ b/src/main/java/ru/nanit/limbo/server/data/InfoForwarding.java @@ -1,3 +1,20 @@ +/* + * 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.server.data; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/src/main/java/ru/nanit/limbo/server/data/PingData.java b/src/main/java/ru/nanit/limbo/server/data/PingData.java index 477deea4..435f13e4 100644 --- a/src/main/java/ru/nanit/limbo/server/data/PingData.java +++ b/src/main/java/ru/nanit/limbo/server/data/PingData.java @@ -1,3 +1,20 @@ +/* + * 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.server.data; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/src/main/java/ru/nanit/limbo/server/data/Position.java b/src/main/java/ru/nanit/limbo/server/data/Position.java deleted file mode 100644 index d28902b0..00000000 --- a/src/main/java/ru/nanit/limbo/server/data/Position.java +++ /dev/null @@ -1,75 +0,0 @@ -package ru.nanit.limbo.server.data; - -import org.checkerframework.checker.nullness.qual.Nullable; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.serialize.TypeSerializer; - -import java.lang.reflect.Type; - -public class Position { - - private double x; - private double y; - private double z; - private float yaw; - private float pitch; - - public double getX() { - return x; - } - - public double getY() { - return y; - } - - public double getZ() { - return z; - } - - public float getYaw() { - return yaw; - } - - public float getPitch() { - return pitch; - } - - public void setX(double x) { - this.x = x; - } - - public void setY(double y) { - this.y = y; - } - - public void setZ(double z) { - this.z = z; - } - - public void setYaw(float yaw) { - this.yaw = yaw; - } - - public void setPitch(float pitch) { - this.pitch = pitch; - } - - public static class Serializer implements TypeSerializer { - - @Override - public Position deserialize(Type type, ConfigurationNode node) { - Position position = new Position(); - position.setX(node.node("x").getDouble()); - position.setY(node.node("y").getDouble()); - position.setZ(node.node("z").getDouble()); - position.setYaw(node.node("yaw").getFloat()); - position.setPitch(node.node("pitch").getFloat()); - return position; - } - - @Override - public void serialize(Type type, @Nullable Position obj, ConfigurationNode node) { - - } - } -} diff --git a/src/main/java/ru/nanit/limbo/server/data/Title.java b/src/main/java/ru/nanit/limbo/server/data/Title.java index 3519a25d..28f94cd2 100644 --- a/src/main/java/ru/nanit/limbo/server/data/Title.java +++ b/src/main/java/ru/nanit/limbo/server/data/Title.java @@ -1,3 +1,20 @@ +/* + * 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.server.data; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/src/main/java/ru/nanit/limbo/util/Colors.java b/src/main/java/ru/nanit/limbo/util/Colors.java index 5dda2552..41562e7e 100644 --- a/src/main/java/ru/nanit/limbo/util/Colors.java +++ b/src/main/java/ru/nanit/limbo/util/Colors.java @@ -1,3 +1,20 @@ +/* + * 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.util; public final class Colors { diff --git a/src/main/java/ru/nanit/limbo/util/Logger.java b/src/main/java/ru/nanit/limbo/util/Logger.java index a7427d3e..947aacb3 100644 --- a/src/main/java/ru/nanit/limbo/util/Logger.java +++ b/src/main/java/ru/nanit/limbo/util/Logger.java @@ -1,3 +1,20 @@ +/* + * 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.util; import java.time.LocalTime; diff --git a/src/main/java/ru/nanit/limbo/util/UuidUtil.java b/src/main/java/ru/nanit/limbo/util/UuidUtil.java index a3868a8b..54019a76 100644 --- a/src/main/java/ru/nanit/limbo/util/UuidUtil.java +++ b/src/main/java/ru/nanit/limbo/util/UuidUtil.java @@ -1,3 +1,20 @@ +/* + * 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.util; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/ru/nanit/limbo/world/BlockData.java b/src/main/java/ru/nanit/limbo/world/BlockData.java new file mode 100644 index 00000000..9e8e03bb --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/BlockData.java @@ -0,0 +1,51 @@ +/* + * 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 new file mode 100644 index 00000000..01eeb4d2 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/BlockEntity.java @@ -0,0 +1,45 @@ +/* + * 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 new file mode 100644 index 00000000..0f5360e1 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/BlockMappings.java @@ -0,0 +1,68 @@ +/* + * 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/Dimension.java b/src/main/java/ru/nanit/limbo/world/Dimension.java deleted file mode 100644 index 15d87509..00000000 --- a/src/main/java/ru/nanit/limbo/world/Dimension.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.nanit.limbo.world; - -import net.kyori.adventure.nbt.CompoundBinaryTag; - -public class Dimension { - - private final int id; - private final String name; - private final CompoundBinaryTag data; - - public Dimension(int id, String name, CompoundBinaryTag data) { - this.id = id; - this.name = name; - this.data = data; - } - - public int getId() { - return id; - } - - public String getName() { - return name; - } - - public CompoundBinaryTag getData() { - return data; - } -} diff --git a/src/main/java/ru/nanit/limbo/world/Location.java b/src/main/java/ru/nanit/limbo/world/Location.java new file mode 100644 index 00000000..53156094 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/Location.java @@ -0,0 +1,106 @@ +/* + * 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 org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.TypeSerializer; + +import java.lang.reflect.Type; + +public class Location { + + private final double x; + private final double y; + private final double z; + private final float yaw; + private final float pitch; + + Location(double x, double y, double z, float yaw, float pitch) { + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + Location(double x, double y, double z) { + this(x, y, z, 0.0F, 0.0F); + } + + public double getX() { + return x; + } + + public int getBlockX() { + return (int) x; + } + + public double getY() { + return y; + } + + public int getBlockY() { + return (int) y; + } + + public double getZ() { + return z; + } + + public int getBlockZ() { + return (int) z; + } + + public float getYaw() { + return yaw; + } + + public float getPitch() { + return pitch; + } + + public static Location of(double x, double y, double z) { + return new Location(x, y, z); + } + + public static Location of(double x, double y, double z, float yaw, float pitch) { + return new Location(x, y, z, yaw, pitch); + } + + public static Location pos(int x, int y, int z) { + return new Location(x, y, z); + } + + public static class Serializer implements TypeSerializer { + + @Override + public Location deserialize(Type type, ConfigurationNode node) { + double x = node.node("x").getDouble(0); + double y = node.node("y").getDouble(0); + double z = node.node("z").getDouble(0); + float yaw = node.node("yaw").getFloat(0.0F); + float pitch = node.node("pitch").getFloat(0.0F); + + return new Location(x, y, z, yaw, pitch); + } + + @Override + public void serialize(Type type, @Nullable Location obj, ConfigurationNode node) { } + } +} diff --git a/src/main/java/ru/nanit/limbo/world/dimension/Dimension.java b/src/main/java/ru/nanit/limbo/world/dimension/Dimension.java new file mode 100644 index 00000000..4198688b --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/dimension/Dimension.java @@ -0,0 +1,45 @@ +/* + * 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.dimension; + +import net.kyori.adventure.nbt.CompoundBinaryTag; + +public class Dimension { + + private final int id; + private final String name; + private final CompoundBinaryTag data; + + public Dimension(int id, String name, CompoundBinaryTag data) { + this.id = id; + this.name = name; + this.data = data; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public CompoundBinaryTag getData() { + return data; + } +} diff --git a/src/main/java/ru/nanit/limbo/world/DimensionRegistry.java b/src/main/java/ru/nanit/limbo/world/dimension/DimensionRegistry.java similarity index 70% rename from src/main/java/ru/nanit/limbo/world/DimensionRegistry.java rename to src/main/java/ru/nanit/limbo/world/dimension/DimensionRegistry.java index 8c348801..60c07b37 100644 --- a/src/main/java/ru/nanit/limbo/world/DimensionRegistry.java +++ b/src/main/java/ru/nanit/limbo/world/dimension/DimensionRegistry.java @@ -1,4 +1,21 @@ -package ru.nanit.limbo.world; +/* + * 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.dimension; import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.ListBinaryTag; @@ -72,9 +89,15 @@ private CompoundBinaryTag readCodecFile(String resPath) throws IOException { return TagStringIO.get().asCompound(streamToString(in)); } - private String streamToString(InputStream in) { - return new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)) - .lines() + private String streamToString(InputStream in) throws IOException { + InputStreamReader isReader = new InputStreamReader(in, StandardCharsets.UTF_8); + BufferedReader bufReader = new BufferedReader(isReader); + String content = bufReader.lines() .collect(Collectors.joining("\n")); + + isReader.close(); + bufReader.close(); + + return content; } } diff --git a/src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java b/src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java new file mode 100644 index 00000000..24ccf1e8 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java @@ -0,0 +1,73 @@ +/* + * 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 new file mode 100644 index 00000000..24d01021 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/schematic/Schematic.java @@ -0,0 +1,39 @@ +/* + * 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 new file mode 100644 index 00000000..70596a04 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/schematic/SchematicLoader.java @@ -0,0 +1,139 @@ +/* + * 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 new file mode 100644 index 00000000..70614b60 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/schematic/versions/LegacySchematic.java @@ -0,0 +1,94 @@ +/* + * 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 new file mode 100644 index 00000000..bc6010c2 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/world/schematic/versions/SpongeSchematic.java @@ -0,0 +1,79 @@ +/* + * 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/main/resources/LICENSE-configurate-yaml b/src/main/resources/LICENSE-configurate-yaml new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/src/main/resources/LICENSE-configurate-yaml @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/src/main/resources/LICENSE-netty b/src/main/resources/LICENSE-netty new file mode 100644 index 00000000..e25e752c --- /dev/null +++ b/src/main/resources/LICENSE-netty @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/src/test/java/SchematicTest.java b/src/test/java/SchematicTest.java new file mode 100644 index 00000000..157e4346 --- /dev/null +++ b/src/test/java/SchematicTest.java @@ -0,0 +1,35 @@ +/* + * 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 new file mode 100644 index 00000000..0a800b50 Binary files /dev/null and b/src/test/resources/spawn.schem differ diff --git a/src/test/resources/test.schematic b/src/test/resources/test.schematic new file mode 100644 index 00000000..4119765f Binary files /dev/null and b/src/test/resources/test.schematic differ