diff --git a/README.md b/README.md index c537db33..393f319f 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ The general features: Symbol `X` means all minor versions. +- [x] 1.7.X - [x] 1.8.X - [x] 1.9.X - [x] 1.10.X @@ -35,6 +36,8 @@ Symbol `X` means all minor versions. - [x] 1.18.X - [x] 1.19 - [x] 1.19.1 +- [x] 1.19.2 +- [x] 1.19.3 The server **doesn't** support snapshots. @@ -87,7 +90,7 @@ Required software: To build minimized .jar, go to project root and write in terminal: ``` -gradlew shadowJar +./gradlew shadowJar ``` ### Contacts diff --git a/api/build.gradle b/api/build.gradle index 13518414..0423fc02 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -8,6 +8,6 @@ dependencies { shadowJar{ manifest { - attributes 'Main-Class': 'ru.nanit.limbo.NanoLimbo' + attributes 'Main-Class': 'ua.nanit.limbo.NanoLimbo' } } \ No newline at end of file diff --git a/api/src/main/java/ua/nanit/limbo/configuration/LimboConfig.java b/api/src/main/java/ua/nanit/limbo/configuration/LimboConfig.java index 253015b0..ab4fe50b 100644 --- a/api/src/main/java/ua/nanit/limbo/configuration/LimboConfig.java +++ b/api/src/main/java/ua/nanit/limbo/configuration/LimboConfig.java @@ -6,7 +6,6 @@ import ua.nanit.limbo.server.data.InfoForwarding; import ua.nanit.limbo.server.data.PingData; import ua.nanit.limbo.server.data.Title; -import ua.nanit.limbo.world.Location; public interface LimboConfig { SocketAddress getAddress(); @@ -17,8 +16,6 @@ public interface LimboConfig { String getDimensionType(); - Location getSpawnPosition(); - int getGameMode(); InfoForwarding getInfoForwarding(); diff --git a/api/src/main/java/ua/nanit/limbo/configuration/YamlLimboConfig.java b/api/src/main/java/ua/nanit/limbo/configuration/YamlLimboConfig.java index a2f12e3b..4ce984b0 100644 --- a/api/src/main/java/ua/nanit/limbo/configuration/YamlLimboConfig.java +++ b/api/src/main/java/ua/nanit/limbo/configuration/YamlLimboConfig.java @@ -36,7 +36,6 @@ import ua.nanit.limbo.server.data.PingData; import ua.nanit.limbo.server.data.Title; import ua.nanit.limbo.util.Colors; -import ua.nanit.limbo.world.Location; public final class YamlLimboConfig implements LimboConfig { @@ -48,7 +47,6 @@ public final class YamlLimboConfig implements LimboConfig { private PingData pingData; private String dimensionType; - private Location spawnPosition; private int gameMode; private boolean useBrandName; @@ -99,7 +97,6 @@ public YamlLimboConfig load() throws Exception { if (dimensionType.equalsIgnoreCase("end")) { dimensionType = "the_end"; } - spawnPosition = conf.node("spawnPosition").get(Location.class); gameMode = conf.node("gameMode").getInt(); useBrandName = conf.node("brandName", "enable").getBoolean(); useJoinMessage = conf.node("joinMessage", "enable").getBoolean(); @@ -159,7 +156,6 @@ private TypeSerializerCollection getSerializers() { .register(PingData.class, new PingData.Serializer()) .register(BossBar.class, new BossBar.Serializer()) .register(Title.class, new Title.Serializer()) - .register(Location.class, new Location.Serializer()) .build(); } @@ -183,11 +179,6 @@ public String getDimensionType() { return dimensionType; } - @Override - public Location getSpawnPosition() { - return spawnPosition; - } - @Override public int getGameMode() { return gameMode; @@ -287,4 +278,4 @@ public int getBossGroupSize() { public int getWorkerGroupSize() { return workerGroupSize; } -} +} \ No newline at end of file diff --git a/api/src/main/java/ua/nanit/limbo/connection/ClientConnection.java b/api/src/main/java/ua/nanit/limbo/connection/ClientConnection.java index 57f4686a..aef7912f 100644 --- a/api/src/main/java/ua/nanit/limbo/connection/ClientConnection.java +++ b/api/src/main/java/ua/nanit/limbo/connection/ClientConnection.java @@ -17,6 +17,19 @@ package ua.nanit.limbo.connection; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.security.InvalidKeyException; +import java.security.MessageDigest; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +import org.jetbrains.annotations.NotNull; + import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; @@ -26,32 +39,17 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; - -import org.jetbrains.annotations.NotNull; - import ua.nanit.limbo.connection.pipeline.PacketDecoder; import ua.nanit.limbo.connection.pipeline.PacketEncoder; import ua.nanit.limbo.protocol.ByteMessage; import ua.nanit.limbo.protocol.Packet; -import ru.nanit.limbo.protocol.packets.login.*; -import ru.nanit.limbo.protocol.packets.play.*; +import ua.nanit.limbo.protocol.packets.login.PacketDisconnect; +import ua.nanit.limbo.protocol.packets.play.PacketKeepAlive; import ua.nanit.limbo.protocol.registry.State; import ua.nanit.limbo.protocol.registry.Version; import ua.nanit.limbo.server.LimboServer; import ua.nanit.limbo.server.Logger; import ua.nanit.limbo.util.UuidUtil; -import ua.nanit.limbo.protocol.packets.login.PacketDisconnect; -import ua.nanit.limbo.protocol.packets.play.PacketKeepAlive; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; public class ClientConnection extends ChannelInboundHandlerAdapter { @@ -129,38 +127,53 @@ public void fireLoginSuccess() { return; } - writePacket(server.getPacketSnapshots().getPacketLoginSuccess()); + sendPacket(server.getPacketSnapshots().getPacketLoginSuccess()); updateState(State.PLAY); - server.getConnections().addConnection(this); - writePacket(server.getPacketSnapshots().getPacketJoinGame()); - writePacket(server.getPacketSnapshots().getPacketPlayerAbilities()); - writePacket(server.getPacketSnapshots().getPacketPlayerPos()); + Runnable sendPlayPackets = () -> { + writePacket(server.getPacketSnapshots().getPacketJoinGame()); + writePacket(server.getPacketSnapshots().getPacketPlayerAbilities()); - if (server.getConfig().isUsePlayerList() || clientVersion.equals(Version.V1_16_4)) - writePacket(server.getPacketSnapshots().getPacketPlayerInfo()); + if (clientVersion.less(Version.V1_9)) { + writePacket(server.getPacketSnapshots().getPacketPlayerPosAndLookLegacy()); + } else { + writePacket(server.getPacketSnapshots().getPacketPlayerPosAndLook()); + } - if (clientVersion.moreOrEqual(Version.V1_13)) { - writePacket(server.getPacketSnapshots().getPacketDeclareCommands()); + if (clientVersion.moreOrEqual(Version.V1_19_3)) + writePacket(server.getPacketSnapshots().getPacketSpawnPosition()); - if (server.getPacketSnapshots().getPacketPluginMessage() != null) - writePacket(server.getPacketSnapshots().getPacketPluginMessage()); - } + if (server.getConfig().isUsePlayerList() || clientVersion.equals(Version.V1_16_4)) + writePacket(server.getPacketSnapshots().getPacketPlayerInfo()); - if (server.getPacketSnapshots().getPacketBossBar() != null && clientVersion.moreOrEqual(Version.V1_9)) - writePacket(server.getPacketSnapshots().getPacketBossBar()); + if (clientVersion.moreOrEqual(Version.V1_13)) { + writePacket(server.getPacketSnapshots().getPacketDeclareCommands()); + + if (server.getPacketSnapshots().getPacketPluginMessage() != null) + writePacket(server.getPacketSnapshots().getPacketPluginMessage()); + } - if (server.getPacketSnapshots().getPacketJoinMessage() != null) - writePacket(server.getPacketSnapshots().getPacketJoinMessage()); + if (server.getPacketSnapshots().getPacketBossBar() != null && clientVersion.moreOrEqual(Version.V1_9)) + writePacket(server.getPacketSnapshots().getPacketBossBar()); - if (server.getPacketSnapshots().getPacketTitleTitle() != null) - writeTitle(); + if (server.getPacketSnapshots().getPacketJoinMessage() != null) + writePacket(server.getPacketSnapshots().getPacketJoinMessage()); - if (server.getPacketSnapshots().getPacketHeaderAndFooter() != null) - writePacket(server.getPacketSnapshots().getPacketHeaderAndFooter()); + if (server.getPacketSnapshots().getPacketTitleTitle() != null && clientVersion.moreOrEqual(Version.V1_8)) + writeTitle(); - sendKeepAlive(); + if (server.getPacketSnapshots().getPacketHeaderAndFooter() != null && clientVersion.moreOrEqual(Version.V1_8)) + writePacket(server.getPacketSnapshots().getPacketHeaderAndFooter()); + + sendKeepAlive(); + }; + + if (clientVersion.lessOrEqual(Version.V1_7_6)) { + this.channel.eventLoop().schedule(sendPlayPackets, 100, TimeUnit.MILLISECONDS); + } else { + sendPlayPackets.run(); + } } public void disconnectLogin(String reason) { diff --git a/api/src/main/java/ua/nanit/limbo/connection/PacketSnapshots.java b/api/src/main/java/ua/nanit/limbo/connection/PacketSnapshots.java index cde4f38d..9228a48e 100644 --- a/api/src/main/java/ua/nanit/limbo/connection/PacketSnapshots.java +++ b/api/src/main/java/ua/nanit/limbo/connection/PacketSnapshots.java @@ -20,7 +20,7 @@ import ua.nanit.limbo.LimboConstants; import ua.nanit.limbo.protocol.PacketSnapshot; import ua.nanit.limbo.protocol.packets.login.PacketLoginSuccess; -import ru.nanit.limbo.protocol.packets.play.*; +import ua.nanit.limbo.protocol.packets.play.*; import ua.nanit.limbo.server.LimboServer; import ua.nanit.limbo.server.data.Title; import ua.nanit.limbo.util.UuidUtil; @@ -46,15 +46,19 @@ public final class PacketSnapshots { private PacketSnapshot packetLoginSuccess; private PacketSnapshot packetJoinGame; + private PacketSnapshot packetSpawnPosition; private PacketSnapshot packetPluginMessage; private PacketSnapshot packetPlayerAbilities; private PacketSnapshot packetPlayerInfo; private PacketSnapshot packetDeclareCommands; - private PacketSnapshot packetPlayerPos; private PacketSnapshot packetJoinMessage; private PacketSnapshot packetBossBar; private PacketSnapshot packetHeaderAndFooter; + private PacketSnapshot packetPlayerPosAndLookLegacy; + // For 1.19 we need to spawn player outside world to avoid stuck in terrain loading + private PacketSnapshot packetPlayerPosAndLook; + private PacketSnapshot packetTitleTitle; private PacketSnapshot packetTitleSubtitle; private PacketSnapshot packetTitleTimes; @@ -73,6 +77,7 @@ public PacketSnapshots(LimboServer server) { loginSuccess.setUuid(uuid); PacketJoinGame joinGame = new PacketJoinGame(); + String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase(); joinGame.setEntityId(0); joinGame.setEnableRespawnScreen(true); joinGame.setFlat(false); @@ -83,7 +88,6 @@ public PacketSnapshots(LimboServer server) { joinGame.setReducedDebugInfo(true); joinGame.setDebug(false); joinGame.setViewDistance(0); - String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase(); joinGame.setWorldName(worldName); joinGame.setWorldNames(worldName); joinGame.setHashedSeed(0); @@ -94,13 +98,15 @@ public PacketSnapshots(LimboServer server) { playerAbilities.setFlags(0x02); playerAbilities.setFieldOfView(0.1F); - PacketPlayerPositionAndLook positionAndLook = new PacketPlayerPositionAndLook(); - positionAndLook.setX(server.getConfig().getSpawnPosition().getX()); - positionAndLook.setY(server.getConfig().getSpawnPosition().getY()); - positionAndLook.setZ(server.getConfig().getSpawnPosition().getZ()); - positionAndLook.setYaw(server.getConfig().getSpawnPosition().getYaw()); - positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch()); - positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt()); + int teleportId = ThreadLocalRandom.current().nextInt(); + + PacketPlayerPositionAndLook positionAndLookLegacy + = new PacketPlayerPositionAndLook(0, 64, 0, 0, 0, teleportId); + + PacketPlayerPositionAndLook positionAndLook + = new PacketPlayerPositionAndLook(0, 400, 0, 0, 0, teleportId); + + PacketSpawnPosition spawnPosition = new PacketSpawnPosition(0, 400, 0); PacketDeclareCommands declareCommands = new PacketDeclareCommands(); declareCommands.setCommands(Collections.emptyList()); @@ -112,8 +118,10 @@ public PacketSnapshots(LimboServer server) { packetLoginSuccess = PacketSnapshot.of(loginSuccess); packetJoinGame = PacketSnapshot.of(joinGame); + packetPlayerPosAndLookLegacy = PacketSnapshot.of(positionAndLookLegacy); + packetPlayerPosAndLook = PacketSnapshot.of(positionAndLook); + packetSpawnPosition = PacketSnapshot.of(spawnPosition); packetPlayerAbilities = PacketSnapshot.of(playerAbilities); - packetPlayerPos = PacketSnapshot.of(positionAndLook); packetPlayerInfo = PacketSnapshot.of(info); packetDeclareCommands = PacketSnapshot.of(declareCommands); @@ -191,6 +199,10 @@ public PacketSnapshot getPacketJoinGame() { return packetJoinGame; } + public PacketSnapshot getPacketSpawnPosition() { + return packetSpawnPosition; + } + public PacketSnapshot getPacketPluginMessage() { return packetPluginMessage; } @@ -207,10 +219,6 @@ public PacketSnapshot getPacketDeclareCommands() { return packetDeclareCommands; } - public PacketSnapshot getPacketPlayerPos() { - return packetPlayerPos; - } - public PacketSnapshot getPacketJoinMessage() { return packetJoinMessage; } @@ -223,6 +231,14 @@ public PacketSnapshot getPacketHeaderAndFooter() { return packetHeaderAndFooter; } + public PacketSnapshot getPacketPlayerPosAndLookLegacy() { + return packetPlayerPosAndLookLegacy; + } + + public PacketSnapshot getPacketPlayerPosAndLook() { + return packetPlayerPosAndLook; + } + public PacketSnapshot getPacketTitleTitle() { return packetTitleTitle; } diff --git a/api/src/main/java/ua/nanit/limbo/protocol/ByteMessage.java b/api/src/main/java/ua/nanit/limbo/protocol/ByteMessage.java index 6ff3931e..b4b0128a 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/ByteMessage.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/ByteMessage.java @@ -34,6 +34,9 @@ import java.nio.channels.ScatteringByteChannel; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.BitSet; +import java.util.EnumSet; import java.util.UUID; public class ByteMessage extends ByteBuf { @@ -190,6 +193,24 @@ public void writeCompoundTag(CompoundBinaryTag compoundTag) { } } + public > void writeEnumSet(EnumSet enumset, Class oclass) { + E[] enums = oclass.getEnumConstants(); + BitSet bits = new BitSet(enums.length); + + for (int i = 0; i < enums.length; ++i) { + bits.set(i, enumset.contains(enums[i])); + } + + writeFixedBitSet(bits, enums.length, buf); + } + + private static void writeFixedBitSet(BitSet bits, int size, ByteBuf buf) { + if (bits.length() > size) { + throw new StackOverflowError("BitSet too large (expected " + size + " got " + bits.size() + ")"); + } + buf.writeBytes(Arrays.copyOf(bits.toByteArray(), (size + 8) >> 3)); + } + /* Delegated methods */ @Override diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java index c5d74ced..a07dd2ae 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/login/PacketLoginSuccess.java @@ -40,8 +40,10 @@ public void setUsername(String username) { public void encode(ByteMessage msg, Version version) { if (version.moreOrEqual(Version.V1_16)) { msg.writeUuid(uuid); - } else { + } else if (version.moreOrEqual(Version.V1_7_6)) { msg.writeString(uuid.toString()); + } else { + msg.writeString(uuid.toString().replace("-", "")); } msg.writeString(username); if (version.moreOrEqual(Version.V1_19)) { diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketChatMessage.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketChatMessage.java index 2e1d8ad7..2883ac9c 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketChatMessage.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketChatMessage.java @@ -46,11 +46,9 @@ public void encode(ByteMessage msg, Version version) { msg.writeString(jsonData); if (version.moreOrEqual(Version.V1_19_1)) { msg.writeBoolean(position.index == PositionLegacy.ACTION_BAR.index); - } - else if (version.moreOrEqual(Version.V1_19)) { + } else if (version.moreOrEqual(Version.V1_19)) { msg.writeVarInt(position.index); - } - else { + } else if (version.moreOrEqual(Version.V1_8)) { msg.writeByte(position.index); } diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketJoinGame.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketJoinGame.java index e338dc73..b8465d29 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketJoinGame.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketJoinGame.java @@ -20,7 +20,7 @@ import ua.nanit.limbo.protocol.ByteMessage; import ua.nanit.limbo.protocol.PacketOut; import ua.nanit.limbo.protocol.registry.Version; -import ua.nanit.limbo.world.dimension.DimensionRegistry; +import ua.nanit.limbo.world.DimensionRegistry; public class PacketJoinGame implements PacketOut { @@ -99,6 +99,14 @@ public void setFlat(boolean flat) { public void encode(ByteMessage msg, Version version) { msg.writeInt(entityId); + if (version.fromTo(Version.V1_7_2, Version.V1_7_6)) { + msg.writeByte(gameMode == 3 ? 1 : gameMode); + msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId()); + msg.writeByte(0); // Difficulty + msg.writeByte(maxPlayers); + msg.writeString("flat"); // Level type + } + if (version.fromTo(Version.V1_8, Version.V1_9)) { msg.writeByte(gameMode); msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId()); diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketKeepAlive.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketKeepAlive.java index 3c5f59be..f18d398a 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketKeepAlive.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketKeepAlive.java @@ -37,8 +37,10 @@ public void setId(long id) { public void encode(ByteMessage msg, Version version) { if (version.moreOrEqual(Version.V1_12_2)) { msg.writeLong(id); - } else { + } else if (version.moreOrEqual(Version.V1_8)) { msg.writeVarInt((int) id); + } else { + msg.writeInt((int) id); } } @@ -46,8 +48,10 @@ public void encode(ByteMessage msg, Version version) { public void decode(ByteMessage msg, Version version) { if (version.moreOrEqual(Version.V1_12_2)) { this.id = msg.readLong(); - } else { + } else if (version.moreOrEqual(Version.V1_8)) { this.id = msg.readVarInt(); + } else { + this.id = msg.readInt(); } } diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java index 095a9743..a4bdd9ff 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerInfo.java @@ -21,6 +21,7 @@ import ua.nanit.limbo.protocol.PacketOut; import ua.nanit.limbo.protocol.registry.Version; +import java.util.EnumSet; import java.util.UUID; /** @@ -46,17 +47,49 @@ public void setUuid(UUID uuid) { @Override public void encode(ByteMessage msg, Version version) { - msg.writeVarInt(0); // Add player action - msg.writeVarInt(1); - msg.writeUuid(uuid); - msg.writeString(username); - msg.writeVarInt(0); - msg.writeVarInt(gameMode); - msg.writeVarInt(60); - msg.writeBoolean(false); - if (version.moreOrEqual(Version.V1_19)) { + if (version.less(Version.V1_8)) { + msg.writeString(username); + msg.writeBoolean(true); // Is online + msg.writeShort(0); + } else { + if (version.moreOrEqual(Version.V1_19_3)) { + EnumSet actions = EnumSet.noneOf(Action.class); + actions.add(Action.ADD_PLAYER); + actions.add(Action.UPDATE_LISTED); + actions.add(Action.UPDATE_GAMEMODE); + msg.writeEnumSet(actions, Action.class); + + msg.writeVarInt(1); // Array length (1 element) + msg.writeUuid(uuid); // UUID + msg.writeString(username); //Username + msg.writeVarInt(0); //Properties (0 is empty) + + msg.writeBoolean(true); //Update listed + msg.writeVarInt(gameMode); //Gamemode + return; + } + + msg.writeVarInt(0); // Add player action + msg.writeVarInt(1); + msg.writeUuid(uuid); + msg.writeString(username); + msg.writeVarInt(0); + msg.writeVarInt(gameMode); + msg.writeVarInt(60); msg.writeBoolean(false); + + if (version.moreOrEqual(Version.V1_19)) { + msg.writeBoolean(false); + } } } + public static enum Action { + ADD_PLAYER, + INITIALIZE_CHAT, + UPDATE_GAMEMODE, + UPDATE_LISTED, + UPDATE_LATENCY, + UPDATE_DISPLAY_NAME + } } diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java index f5a6272a..f907bc3d 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketPlayerPositionAndLook.java @@ -28,49 +28,34 @@ public class PacketPlayerPositionAndLook implements PacketOut { private double z; private float yaw; private float pitch; - private byte flags = 0x08; private int teleportId; - public void setX(double x) { - this.x = x; - } + public PacketPlayerPositionAndLook() {} - public void setY(double y) { + public PacketPlayerPositionAndLook(double x, double y, double z, float yaw, float pitch, int teleportId) { + this.x = x; 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 void setFlags(byte flags) { - this.flags = flags; - } - - public void setTeleportId(int teleportId) { this.teleportId = teleportId; } @Override public void encode(ByteMessage msg, Version version) { msg.writeDouble(x); - msg.writeDouble(y); + msg.writeDouble(y + (version.less(Version.V1_8) ? 1.62F : 0)); msg.writeDouble(z); msg.writeFloat(yaw); msg.writeFloat(pitch); - if (version.less(Version.V1_9)) { - msg.writeBoolean(true); // On ground + if (version.moreOrEqual(Version.V1_8)) { + msg.writeByte(0x08); } else { - msg.writeByte(flags); + msg.writeBoolean(true); + } + + if (version.moreOrEqual(Version.V1_9)) { msg.writeVarInt(teleportId); } diff --git a/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketSpawnPosition.java b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketSpawnPosition.java new file mode 100644 index 00000000..871334d0 --- /dev/null +++ b/api/src/main/java/ua/nanit/limbo/protocol/packets/play/PacketSpawnPosition.java @@ -0,0 +1,30 @@ +package ua.nanit.limbo.protocol.packets.play; + +import ua.nanit.limbo.protocol.ByteMessage; +import ua.nanit.limbo.protocol.PacketOut; +import ua.nanit.limbo.protocol.registry.Version; + +public class PacketSpawnPosition implements PacketOut { + + private long x; + private long y; + private long z; + + public PacketSpawnPosition() { } + + public PacketSpawnPosition(long x, long y, long z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void encode(ByteMessage msg, Version version) { + msg.writeLong(encodePosition(x, y ,z)); + msg.writeFloat(0); + } + + private static long encodePosition(long x, long y, long z) { + return ((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF); + } +} diff --git a/api/src/main/java/ua/nanit/limbo/protocol/registry/State.java b/api/src/main/java/ua/nanit/limbo/protocol/registry/State.java index ca6daa6e..49477d3e 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/registry/State.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/registry/State.java @@ -19,34 +19,17 @@ import ua.nanit.limbo.protocol.Packet; import ua.nanit.limbo.protocol.packets.PacketHandshake; -import ru.nanit.limbo.protocol.packets.login.*; -import ru.nanit.limbo.protocol.packets.play.*; -import ua.nanit.limbo.protocol.packets.play.PacketBossBar; -import ua.nanit.limbo.protocol.packets.play.PacketChatMessage; -import ua.nanit.limbo.protocol.packets.play.PacketJoinGame; -import ua.nanit.limbo.protocol.packets.play.PacketKeepAlive; -import ua.nanit.limbo.protocol.packets.play.PacketPlayerPositionAndLook; -import ua.nanit.limbo.protocol.packets.play.PacketPluginMessage; -import ua.nanit.limbo.protocol.packets.play.PacketTitleSetSubTitle; -import ua.nanit.limbo.protocol.packets.play.PacketTitleSetTitle; +import ua.nanit.limbo.protocol.packets.login.*; +import ua.nanit.limbo.protocol.packets.play.*; import ua.nanit.limbo.protocol.packets.status.PacketStatusPing; import ua.nanit.limbo.protocol.packets.status.PacketStatusRequest; import ua.nanit.limbo.protocol.packets.status.PacketStatusResponse; -import ua.nanit.limbo.protocol.packets.login.PacketDisconnect; -import ua.nanit.limbo.protocol.packets.login.PacketLoginPluginRequest; -import ua.nanit.limbo.protocol.packets.login.PacketLoginPluginResponse; -import ua.nanit.limbo.protocol.packets.login.PacketLoginStart; -import ua.nanit.limbo.protocol.packets.login.PacketLoginSuccess; -import ua.nanit.limbo.protocol.packets.play.PacketDeclareCommands; -import ua.nanit.limbo.protocol.packets.play.PacketPlayerAbilities; -import ua.nanit.limbo.protocol.packets.play.PacketPlayerInfo; -import ua.nanit.limbo.protocol.packets.play.PacketPlayerListHeader; -import ua.nanit.limbo.protocol.packets.play.PacketTitleLegacy; -import ua.nanit.limbo.protocol.packets.play.PacketTitleTimes; import java.util.*; import java.util.function.Supplier; +import static ua.nanit.limbo.protocol.registry.Version.*; + public enum State { HANDSHAKING(0) { @@ -94,153 +77,169 @@ public enum State { PLAY(3) { { serverBound.register(PacketKeepAlive::new, - map(0x00, Version.V1_8, Version.V1_8), - map(0x0B, Version.V1_9, Version.V1_11_1), - map(0x0C, Version.V1_12, Version.V1_12), - map(0x0B, Version.V1_12_1, Version.V1_12_2), - map(0x0E, Version.V1_13, Version.V1_13_2), - map(0x0F, Version.V1_14, Version.V1_15_2), - map(0x10, Version.V1_16, Version.V1_16_4), - map(0x0F, Version.V1_17, Version.V1_18_2), - map(0x11, Version.V1_19, Version.V1_19), - map(0x12, Version.V1_19_1, Version.V1_19_1) + map(0x00, V1_7_2, V1_8), + map(0x0B, V1_9, V1_11_1), + map(0x0C, V1_12, V1_12), + map(0x0B, V1_12_1, V1_12_2), + map(0x0E, V1_13, V1_13_2), + map(0x0F, V1_14, V1_15_2), + map(0x10, V1_16, V1_16_4), + map(0x0F, V1_17, V1_18_2), + map(0x11, V1_19, V1_19), + map(0x12, V1_19_1, V1_19_1), + map(0x11, V1_19_3, V1_19_3) ); clientBound.register(PacketDeclareCommands::new, - map(0x11, Version.V1_13, Version.V1_14_4), - map(0x12, Version.V1_15, Version.V1_15_2), - map(0x11, Version.V1_16, Version.V1_16_1), - map(0x10, Version.V1_16_2, Version.V1_16_4), - map(0x12, Version.V1_17, Version.V1_18_2), - map(0x0F, Version.V1_19, Version.V1_19_1) + map(0x11, V1_13, V1_14_4), + map(0x12, V1_15, V1_15_2), + map(0x11, V1_16, V1_16_1), + map(0x10, V1_16_2, V1_16_4), + map(0x12, V1_17, V1_18_2), + map(0x0F, V1_19, V1_19_1), + map(0x0E, V1_19_3, V1_19_3) ); clientBound.register(PacketJoinGame::new, - map(0x01, Version.V1_8, Version.V1_8), - map(0x23, Version.V1_9, Version.V1_12_2), - map(0x25, Version.V1_13, Version.V1_14_4), - map(0x26, Version.V1_15, Version.V1_15_2), - map(0x25, Version.V1_16, Version.V1_16_1), - map(0x24, Version.V1_16_2, Version.V1_16_4), - map(0x26, Version.V1_17, Version.V1_18_2), - map(0x23, Version.V1_19, Version.V1_19), - map(0x25, Version.V1_19_1, Version.V1_19_1) + map(0x01, V1_7_2, V1_8), + map(0x23, V1_9, V1_12_2), + map(0x25, V1_13, V1_14_4), + map(0x26, V1_15, V1_15_2), + map(0x25, V1_16, V1_16_1), + map(0x24, V1_16_2, V1_16_4), + map(0x26, V1_17, V1_18_2), + map(0x23, V1_19, V1_19), + map(0x25, V1_19_1, V1_19_1), + map(0x24, V1_19_3, V1_19_3) ); clientBound.register(PacketPluginMessage::new, - map(0x19, Version.V1_13, Version.V1_13_2), - map(0x18, Version.V1_14, Version.V1_14_4), - map(0x19, Version.V1_15, Version.V1_15_2), - map(0x18, Version.V1_16, Version.V1_16_1), - map(0x17, Version.V1_16_2, Version.V1_16_4), - map(0x18, Version.V1_17, Version.V1_18_2), - map(0x15, Version.V1_19, Version.V1_19), - map(0x16, Version.V1_19_1, Version.V1_19_1) + map(0x19, V1_13, V1_13_2), + map(0x18, V1_14, V1_14_4), + map(0x19, V1_15, V1_15_2), + map(0x18, V1_16, V1_16_1), + map(0x17, V1_16_2, V1_16_4), + map(0x18, V1_17, V1_18_2), + map(0x15, V1_19, V1_19), + map(0x16, V1_19_1, V1_19_1), + map(0x15, V1_19_3, V1_19_3) ); clientBound.register(PacketPlayerAbilities::new, - map(0x39, Version.V1_8, Version.V1_8), - map(0x2B, Version.V1_9, Version.V1_12), - map(0x2C, Version.V1_12_1, Version.V1_12_2), - map(0x2E, Version.V1_13, Version.V1_13_2), - map(0x31, Version.V1_14, Version.V1_14_4), - map(0x32, Version.V1_15, Version.V1_15_2), - map(0x31, Version.V1_16, Version.V1_16_1), - map(0x30, Version.V1_16_2, Version.V1_16_4), - map(0x32, Version.V1_17, Version.V1_18_2), - map(0x2F, Version.V1_19, Version.V1_19), - map(0x31, Version.V1_19_1, Version.V1_19_1) + map(0x39, V1_7_2, V1_8), + map(0x2B, V1_9, V1_12), + map(0x2C, V1_12_1, V1_12_2), + map(0x2E, V1_13, V1_13_2), + map(0x31, V1_14, V1_14_4), + map(0x32, V1_15, V1_15_2), + map(0x31, V1_16, V1_16_1), + map(0x30, V1_16_2, V1_16_4), + map(0x32, V1_17, V1_18_2), + map(0x2F, V1_19, V1_19), + map(0x31, V1_19_1, V1_19_1), + map(0x30, V1_19_3, V1_19_3) ); clientBound.register(PacketPlayerPositionAndLook::new, - map(0x08, Version.V1_8, Version.V1_8), - map(0x2E, Version.V1_9, Version.V1_12), - map(0x2F, Version.V1_12_1, Version.V1_12_2), - map(0x32, Version.V1_13, Version.V1_13_2), - map(0x35, Version.V1_14, Version.V1_14_4), - map(0x36, Version.V1_15, Version.V1_15_2), - map(0x35, Version.V1_16, Version.V1_16_1), - map(0x34, Version.V1_16_2, Version.V1_16_4), - map(0x38, Version.V1_17, Version.V1_18_2), - map(0x36, Version.V1_19, Version.V1_19), - map(0x39, Version.V1_19_1, Version.V1_19_1) + map(0x08, V1_7_2, V1_8), + map(0x2E, V1_9, V1_12), + map(0x2F, V1_12_1, V1_12_2), + map(0x32, V1_13, V1_13_2), + map(0x35, V1_14, V1_14_4), + map(0x36, V1_15, V1_15_2), + map(0x35, V1_16, V1_16_1), + map(0x34, V1_16_2, V1_16_4), + map(0x38, V1_17, V1_18_2), + map(0x36, V1_19, V1_19), + map(0x39, V1_19_1, V1_19_1), + map(0x38, V1_19_3, V1_19_3) ); clientBound.register(PacketKeepAlive::new, - map(0x00, Version.V1_8, Version.V1_8), - map(0x1F, Version.V1_9, Version.V1_12_2), - map(0x21, Version.V1_13, Version.V1_13_2), - map(0x20, Version.V1_14, Version.V1_14_4), - map(0x21, Version.V1_15, Version.V1_15_2), - map(0x20, Version.V1_16, Version.V1_16_1), - map(0x1F, Version.V1_16_2, Version.V1_16_4), - map(0x21, Version.V1_17, Version.V1_18_2), - map(0x1E, Version.V1_19, Version.V1_19), - map(0x20, Version.V1_19_1, Version.V1_19_1) + map(0x00, V1_7_2, V1_8), + map(0x1F, V1_9, V1_12_2), + map(0x21, V1_13, V1_13_2), + map(0x20, V1_14, V1_14_4), + map(0x21, V1_15, V1_15_2), + map(0x20, V1_16, V1_16_1), + map(0x1F, V1_16_2, V1_16_4), + map(0x21, V1_17, V1_18_2), + map(0x1E, V1_19, V1_19), + map(0x20, V1_19_1, V1_19_1), + map(0x1F, V1_19_3, V1_19_3) ); clientBound.register(PacketChatMessage::new, - map(0x02, Version.V1_8, Version.V1_8), - map(0x0F, Version.V1_9, Version.V1_12_2), - map(0x0E, Version.V1_13, Version.V1_14_4), - map(0x0F, Version.V1_15, Version.V1_15_2), - map(0x0E, Version.V1_16, Version.V1_16_4), - map(0x0F, Version.V1_17, Version.V1_18_2), - map(0x5F, Version.V1_19, Version.V1_19), - map(0x62, Version.V1_19_1, Version.V1_19_1) + map(0x02, V1_7_2, V1_8), + map(0x0F, V1_9, V1_12_2), + map(0x0E, V1_13, V1_14_4), + map(0x0F, V1_15, V1_15_2), + map(0x0E, V1_16, V1_16_4), + map(0x0F, V1_17, V1_18_2), + map(0x5F, V1_19, V1_19), + map(0x62, V1_19_1, V1_19_1), + map(0x60, V1_19_3, V1_19_3) ); clientBound.register(PacketBossBar::new, - map(0x0C, Version.V1_9, Version.V1_14_4), - map(0x0D, Version.V1_15, Version.V1_15_2), - map(0x0C, Version.V1_16, Version.V1_16_4), - map(0x0D, Version.V1_17, Version.V1_18_2), - map(0x0A, Version.V1_19, Version.V1_19_1) + map(0x0C, V1_9, V1_14_4), + map(0x0D, V1_15, V1_15_2), + map(0x0C, V1_16, V1_16_4), + map(0x0D, V1_17, V1_18_2), + map(0x0A, V1_19, V1_19_3) ); clientBound.register(PacketPlayerInfo::new, - map(0x38, Version.V1_8, Version.V1_8), - map(0x2D, Version.V1_9, Version.V1_12), - map(0x2E, Version.V1_12_1, Version.V1_12_2), - map(0x30, Version.V1_13, Version.V1_13_2), - map(0x33, Version.V1_14, Version.V1_14_4), - map(0x34, Version.V1_15, Version.V1_15_2), - map(0x33, Version.V1_16, Version.V1_16_1), - map(0x32, Version.V1_16_2, Version.V1_16_4), - map(0x36, Version.V1_17, Version.V1_18_2), - map(0x34, Version.V1_19, Version.V1_19), - map(0x37, Version.V1_19_1, Version.V1_19_1) + map(0x38, V1_7_2, V1_8), + map(0x2D, V1_9, V1_12), + map(0x2E, V1_12_1, V1_12_2), + map(0x30, V1_13, V1_13_2), + map(0x33, V1_14, V1_14_4), + map(0x34, V1_15, V1_15_2), + map(0x33, V1_16, V1_16_1), + map(0x32, V1_16_2, V1_16_4), + map(0x36, V1_17, V1_18_2), + map(0x34, V1_19, V1_19), + map(0x37, V1_19_1, V1_19_1), + map(0x36, V1_19_3, V1_19_3) ); clientBound.register(PacketTitleLegacy::new, - map(0x45, Version.V1_8, Version.V1_11_1), - map(0x47, Version.V1_12, Version.V1_12), - map(0x48, Version.V1_12_1, Version.V1_12_2), - map(0x4B, Version.V1_13, Version.V1_13_2), - map(0x4F, Version.V1_14, Version.V1_14_4), - map(0x50, Version.V1_15, Version.V1_15_2), - map(0x4F, Version.V1_16, Version.V1_16_4) + map(0x45, V1_8, V1_11_1), + map(0x47, V1_12, V1_12), + map(0x48, V1_12_1, V1_12_2), + map(0x4B, V1_13, V1_13_2), + map(0x4F, V1_14, V1_14_4), + map(0x50, V1_15, V1_15_2), + map(0x4F, V1_16, V1_16_4) ); clientBound.register(PacketTitleSetTitle::new, - map(0x59, Version.V1_17, Version.V1_17_1), - map(0x5A, Version.V1_18, Version.V1_19), - map(0x5D, Version.V1_19_1, Version.V1_19_1) + map(0x59, V1_17, V1_17_1), + map(0x5A, V1_18, V1_19), + map(0x5D, V1_19_1, V1_19_1), + map(0x5B, V1_19_3, V1_19_3) ); clientBound.register(PacketTitleSetSubTitle::new, - map(0x57, Version.V1_17, Version.V1_17_1), - map(0x58, Version.V1_18, Version.V1_19), - map(0x5B, Version.V1_19_1, Version.V1_19_1) + map(0x57, V1_17, V1_17_1), + map(0x58, V1_18, V1_19), + map(0x5B, V1_19_1, V1_19_1), + map(0x59, V1_19_3, V1_19_3) ); clientBound.register(PacketTitleTimes::new, - map(0x5A, Version.V1_17, Version.V1_17_1), - map(0x5B, Version.V1_18, Version.V1_19), - map(0x5E, Version.V1_19_1, Version.V1_19_1) + map(0x5A, V1_17, V1_17_1), + map(0x5B, V1_18, V1_19), + map(0x5E, V1_19_1, V1_19_1), + map(0x5C, V1_19_3, V1_19_3) ); clientBound.register(PacketPlayerListHeader::new, - map(0x47, Version.V1_8, Version.V1_8), - map(0x48, Version.V1_9, Version.V1_9_2), - map(0x47, Version.V1_9_4, Version.V1_11_1), - map(0x49, Version.V1_12, Version.V1_12), - map(0x4A, Version.V1_12_1, Version.V1_12_2), - map(0x4E, Version.V1_13, Version.V1_13_2), - map(0x53, Version.V1_14, Version.V1_14_4), - map(0x54, Version.V1_15, Version.V1_15_2), - map(0x53, Version.V1_16, Version.V1_16_4), - map(0x5E, Version.V1_17, Version.V1_17_1), - map(0x5F, Version.V1_18, Version.V1_18_2), - map(0x60, Version.V1_19, Version.V1_19), - map(0x63, Version.V1_19_1, Version.V1_19_1) + map(0x47, V1_8, V1_8), + map(0x48, V1_9, V1_9_2), + map(0x47, V1_9_4, V1_11_1), + map(0x49, V1_12, V1_12), + map(0x4A, V1_12_1, V1_12_2), + map(0x4E, V1_13, V1_13_2), + map(0x53, V1_14, V1_14_4), + map(0x54, V1_15, V1_15_2), + map(0x53, V1_16, V1_16_4), + map(0x5E, V1_17, V1_17_1), + map(0x5F, V1_18, V1_18_2), + map(0x60, V1_19, V1_19), + map(0x63, V1_19_1, V1_19_1), + map(0x61, V1_19_3, V1_19_3) + ); + clientBound.register(PacketSpawnPosition::new, + map(0x4C, V1_19_3, V1_19_3) ); } }; @@ -270,7 +269,7 @@ public static class ProtocolMappings { private final Map registry = new HashMap<>(); public PacketRegistry getRegistry(Version version) { - return registry.getOrDefault(version, registry.get(Version.getMin())); + return registry.getOrDefault(version, registry.get(getMin())); } public void register(Supplier packet, Mapping... mappings) { diff --git a/api/src/main/java/ua/nanit/limbo/protocol/registry/Version.java b/api/src/main/java/ua/nanit/limbo/protocol/registry/Version.java index 6d1de8d3..674b87f0 100644 --- a/api/src/main/java/ua/nanit/limbo/protocol/registry/Version.java +++ b/api/src/main/java/ua/nanit/limbo/protocol/registry/Version.java @@ -23,6 +23,10 @@ public enum Version { UNDEFINED(-1), + V1_7_2(4), + // 1.7.2-1.7.5 has same protocol numbers + V1_7_6(5), + // 1.7.6-1.7.10 has same protocol numbers V1_8(47), // 1.8-1.8.8 has same protocol numbers V1_9(107), @@ -60,7 +64,8 @@ public enum Version { // 1.18.1 has same protocol number V1_18_2(758), V1_19(759), - V1_19_1(760); + V1_19_1(760), + V1_19_3(761); private static final Map VERSION_MAP; private static final Version MAX; @@ -119,7 +124,7 @@ public boolean isSupported() { } public static Version getMin() { - return V1_8; + return V1_7_2; } public static Version getMax() { diff --git a/api/src/main/java/ua/nanit/limbo/server/LimboServer.java b/api/src/main/java/ua/nanit/limbo/server/LimboServer.java index db17cc5c..84d88848 100644 --- a/api/src/main/java/ua/nanit/limbo/server/LimboServer.java +++ b/api/src/main/java/ua/nanit/limbo/server/LimboServer.java @@ -35,7 +35,7 @@ import ua.nanit.limbo.connection.ClientConnection; import ua.nanit.limbo.connection.PacketHandler; import ua.nanit.limbo.connection.PacketSnapshots; -import ua.nanit.limbo.world.dimension.DimensionRegistry; +import ua.nanit.limbo.world.DimensionRegistry; public final class LimboServer { private boolean running = false; diff --git a/api/src/main/java/ua/nanit/limbo/world/dimension/Dimension.java b/api/src/main/java/ua/nanit/limbo/world/Dimension.java similarity index 96% rename from api/src/main/java/ua/nanit/limbo/world/dimension/Dimension.java rename to api/src/main/java/ua/nanit/limbo/world/Dimension.java index b55c09b5..eff6b91a 100644 --- a/api/src/main/java/ua/nanit/limbo/world/dimension/Dimension.java +++ b/api/src/main/java/ua/nanit/limbo/world/Dimension.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package ua.nanit.limbo.world.dimension; +package ua.nanit.limbo.world; import net.kyori.adventure.nbt.CompoundBinaryTag; @@ -42,4 +42,4 @@ public String getName() { public CompoundBinaryTag getData() { return data; } -} +} \ No newline at end of file diff --git a/api/src/main/java/ua/nanit/limbo/world/dimension/DimensionRegistry.java b/api/src/main/java/ua/nanit/limbo/world/DimensionRegistry.java similarity index 86% rename from api/src/main/java/ua/nanit/limbo/world/dimension/DimensionRegistry.java rename to api/src/main/java/ua/nanit/limbo/world/DimensionRegistry.java index 399ec60a..befc16d0 100644 --- a/api/src/main/java/ua/nanit/limbo/world/dimension/DimensionRegistry.java +++ b/api/src/main/java/ua/nanit/limbo/world/DimensionRegistry.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package ua.nanit.limbo.world.dimension; +package ua.nanit.limbo.world; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -43,8 +43,8 @@ public final class DimensionRegistry { private CompoundBinaryTag codec_1_19_1; private CompoundBinaryTag oldCodec; - public DimensionRegistry(ClassLoader server) { - this.classLoader = server; + public DimensionRegistry(ClassLoader classLoader) { + this.classLoader = classLoader; } public CompoundBinaryTag getCodec_1_16() { @@ -76,12 +76,12 @@ public Dimension getDefaultDimension_1_18_2() { } public void load(String def) throws IOException { - codec_1_16 = readCodecFile("dimension/codec_1_16.snbt"); - codec_1_18_2 = readCodecFile("dimension/codec_1_18_2.snbt"); - codec_1_19 = readCodecFile("dimension/codec_1_19.snbt"); - codec_1_19_1 = readCodecFile("dimension/codec_1_19_1.snbt"); + codec_1_16 = readCodecFile("/dimension/codec_1_16.snbt"); + codec_1_18_2 = readCodecFile("/dimension/codec_1_18_2.snbt"); + codec_1_19 = readCodecFile("/dimension/codec_1_19.snbt"); + codec_1_19_1 = readCodecFile("/dimension/codec_1_19_1.snbt"); // On 1.16-1.16.1 different codec format - oldCodec = readCodecFile("dimension/codec_old.snbt"); + oldCodec = readCodecFile("/dimension/codec_old.snbt"); defaultDimension_1_16 = getDefaultDimension(def, codec_1_16); defaultDimension_1_18_2 = getDefaultDimension(def, codec_1_18_2); @@ -108,10 +108,11 @@ private Dimension getDefaultDimension(String def, CompoundBinaryTag tag) { } private CompoundBinaryTag readCodecFile(String resPath) throws IOException { - InputStream in = classLoader.getResourceAsStream(resPath); + String originalPath = resPath.startsWith("/") ? resPath.substring(1) : resPath; + InputStream in = classLoader.getResourceAsStream(originalPath); if (in == null) - throw new FileNotFoundException("Cannot find dimension registry file in " + resPath); + throw new FileNotFoundException("Cannot find dimension registry file"); return TagStringIO.get().asCompound(streamToString(in)); } @@ -127,4 +128,4 @@ private String streamToString(InputStream in) throws IOException { return content; } -} +} \ No newline at end of file diff --git a/api/src/main/java/ua/nanit/limbo/world/Location.java b/api/src/main/java/ua/nanit/limbo/world/Location.java deleted file mode 100644 index 06b629aa..00000000 --- a/api/src/main/java/ua/nanit/limbo/world/Location.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2020 Nan1t - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package ua.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/api/src/main/resources/settings.yml b/api/src/main/resources/settings.yml index f58d926e..531b50d7 100644 --- a/api/src/main/resources/settings.yml +++ b/api/src/main/resources/settings.yml @@ -20,33 +20,28 @@ ping: dimension: THE_END # Whether to display the player in the player list -# For 1.16.5 clients player list will be sent even if disabled, to avoid crash +# For 1.16.5 clients, player list will be sent even if disabled, to avoid crash playerList: enable: false username: 'NanoLimbo' # Whether to display header and footer in player list +# For 1.8+ clients headerAndFooter: enable: false header: '{"text": "&eWelcome!"}' footer: '{"text": "&9NanoLimbo"}' -# Spawn position in the world -spawnPosition: - 'x': 0.0 - 'y': 400.0 - 'z': 0.0 - 'yaw': 0.0 - 'pitch': 0.0 - # Setup player's game mode # 0 - Survival # 1 - Creative (hide HP and food bar) # 2 - Adventure # 3 - Spectator (hide all UI bars) +# Spectator works on 1.8+ clients gameMode: 3 # Server name which is shown under F3 +# For 1.13+ clients brandName: enable: true content: 'NanoLimbo' @@ -57,7 +52,7 @@ joinMessage: text: '{"text": "&eWelcome to the Limbo!"}' # BossBar displays when player join to server -# Works on 1.9+ clients only +# For 1.9+ clients bossBar: enable: true text: '{"text": "Welcome to the Limbo!"}' @@ -68,6 +63,7 @@ bossBar: division: SOLID # Display title and subtitle +# For 1.8+ clients title: enable: true # Set title text value empty, if you need only subtitle