Merge pull request #22 from BoomEaro/feature/1.18.2

Support 1.19
This commit is contained in:
Max 2022-06-30 20:41:11 +02:00 committed by GitHub
commit 2548479cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 4517 additions and 66 deletions

View File

@ -6,6 +6,15 @@ plugins {
group 'ru.nanit'
version '1.3.4'
compileJava {
options.encoding = "UTF-8"
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
@ -15,8 +24,8 @@ dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation 'org.spongepowered:configurate-yaml:4.1.2'
implementation 'io.netty:netty-all:4.1.73.Final'
implementation 'net.kyori:adventure-nbt:4.9.2'
implementation 'io.netty:netty-all:4.1.77.Final'
implementation 'net.kyori:adventure-nbt:4.10.1'
implementation 'com.grack:nanojson:1.7'
}

View File

@ -87,6 +87,12 @@ public final class LimboConfig {
maxPlayers = conf.node("maxPlayers").getInt();
pingData = conf.node("ping").get(PingData.class);
dimensionType = conf.node("dimension").getString();
if (dimensionType.equalsIgnoreCase("nether")) {
dimensionType = "the_nether";
}
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();

View File

@ -25,6 +25,7 @@ import ru.nanit.limbo.protocol.packets.login.PacketLoginPluginResponse;
import ru.nanit.limbo.protocol.packets.login.PacketLoginStart;
import ru.nanit.limbo.protocol.packets.status.PacketStatusPing;
import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest;
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
import ru.nanit.limbo.server.LimboServer;
import ru.nanit.limbo.server.Logger;
import ru.nanit.limbo.util.UuidUtil;
@ -63,7 +64,7 @@ public class PacketHandler {
}
public void handle(ClientConnection conn, PacketStatusRequest packet) {
conn.sendPacket(PacketSnapshots.PACKET_STATUS_RESPONSE);
conn.sendPacket(new PacketStatusResponse(server));
}
public void handle(ClientConnection conn, PacketStatusPing packet) {

View File

@ -21,7 +21,6 @@ import ru.nanit.limbo.LimboConstants;
import ru.nanit.limbo.protocol.PacketSnapshot;
import ru.nanit.limbo.protocol.packets.login.PacketLoginSuccess;
import ru.nanit.limbo.protocol.packets.play.*;
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
import ru.nanit.limbo.server.LimboServer;
import ru.nanit.limbo.server.data.Title;
import ru.nanit.limbo.util.UuidUtil;
@ -32,7 +31,6 @@ import java.util.concurrent.ThreadLocalRandom;
public final class PacketSnapshots {
public static PacketSnapshot PACKET_STATUS_RESPONSE;
public static PacketSnapshot PACKET_LOGIN_SUCCESS;
public static PacketSnapshot PACKET_JOIN_GAME;
public static PacketSnapshot PACKET_PLUGIN_MESSAGE;
@ -52,6 +50,7 @@ public final class PacketSnapshots {
public static PacketSnapshot PACKET_TITLE_LEGACY_SUBTITLE;
public static PacketSnapshot PACKET_TITLE_LEGACY_TIMES;
private PacketSnapshots() { }
public static void initPackets(LimboServer server) {
@ -73,8 +72,9 @@ public final class PacketSnapshots {
joinGame.setReducedDebugInfo(true);
joinGame.setDebug(false);
joinGame.setViewDistance(0);
joinGame.setWorldName("minecraft:world");
joinGame.setWorldNames("minecraft:world");
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
joinGame.setWorldName(worldName);
joinGame.setWorldNames(worldName);
joinGame.setHashedSeed(0);
joinGame.setDimensionRegistry(server.getDimensionRegistry());
@ -99,7 +99,6 @@ public final class PacketSnapshots {
info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid);
PACKET_STATUS_RESPONSE = PacketSnapshot.of(new PacketStatusResponse(server));
PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess);
PACKET_JOIN_GAME = PacketSnapshot.of(joinGame);
PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities);
@ -125,7 +124,7 @@ public final class PacketSnapshots {
if (server.getConfig().isUseJoinMessage()) {
PacketChatMessage joinMessage = new PacketChatMessage();
joinMessage.setJsonData(server.getConfig().getJoinMessage());
joinMessage.setPosition(PacketChatMessage.Position.CHAT);
joinMessage.setPosition(PacketChatMessage.PositionLegacy.SYSTEM_MESSAGE);
joinMessage.setSender(UUID.randomUUID());
PACKET_JOIN_MESSAGE = PacketSnapshot.of(joinMessage);
}

View File

@ -47,7 +47,7 @@ public class PacketDecoder extends MessageToMessageDecoder<ByteBuf> {
Packet packet = mappings.getPacket(packetId);
if (packet != null) {
Logger.debug("Received packet %s", packet.toString());
Logger.debug("Received packet %s[0x%s]", packet.toString(), Integer.toHexString(packetId));
try {
packet.decode(msg, version);
} catch (Exception e) {

View File

@ -51,7 +51,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
}
if (packetId == -1) {
Logger.warning("Undefined packet class: %s", packet.getClass().getName());
Logger.warning("Undefined packet class: %s[0x%s]", packet.getClass().getName(), Integer.toHexString(packetId));
return;
}
@ -61,7 +61,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
packet.encode(msg, version);
if (Logger.getLevel() >= 3) {
Logger.debug("Sending %s packet (%d bytes)", packet.toString(), msg.readableBytes());
Logger.debug("Sending %s[0x%s] packet (%d bytes)", packet.toString(), Integer.toHexString(packetId), msg.readableBytes());
}
} catch (Exception e) {
Logger.error("Cannot encode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());

View File

@ -166,7 +166,8 @@ public class ByteMessage extends ByteBuf {
for (CompoundBinaryTag tag : compoundTags) {
BinaryTagIO.writer().write(tag, (OutputStream) stream);
}
} catch (IOException e) {
}
catch (IOException e) {
throw new EncoderException("Cannot write NBT CompoundTag");
}
}
@ -174,7 +175,8 @@ public class ByteMessage extends ByteBuf {
public CompoundBinaryTag readCompoundTag() {
try (ByteBufInputStream stream = new ByteBufInputStream(buf)) {
return BinaryTagIO.reader().read((InputStream) stream);
} catch (IOException thrown) {
}
catch (IOException thrown) {
throw new DecoderException("Cannot read NBT CompoundTag");
}
}
@ -182,7 +184,8 @@ public class ByteMessage extends ByteBuf {
public void writeCompoundTag(CompoundBinaryTag compoundTag) {
try (ByteBufOutputStream stream = new ByteBufOutputStream(buf)) {
BinaryTagIO.writer().write(compoundTag, (OutputStream) stream);
} catch (IOException e) {
}
catch (IOException e) {
throw new EncoderException("Cannot write NBT CompoundTag");
}
}

View File

@ -44,6 +44,9 @@ public class PacketLoginSuccess implements PacketOut {
msg.writeString(uuid.toString());
}
msg.writeString(username);
if (version.moreOrEqual(Version.V1_19)) {
msg.writeVarInt(0);
}
}
@Override

View File

@ -26,14 +26,14 @@ import java.util.UUID;
public class PacketChatMessage implements PacketOut {
private String jsonData;
private Position position;
private PositionLegacy position;
private UUID sender;
public void setJsonData(String jsonData) {
this.jsonData = jsonData;
}
public void setPosition(Position position) {
public void setPosition(PositionLegacy position) {
this.position = position;
}
@ -44,13 +44,18 @@ public class PacketChatMessage implements PacketOut {
@Override
public void encode(ByteMessage msg, Version version) {
msg.writeString(jsonData);
if (version.moreOrEqual(Version.V1_19)) {
msg.writeVarInt(position.index);
}
else {
msg.writeByte(position.index);
}
if (version.moreOrEqual(Version.V1_16))
if (version.moreOrEqual(Version.V1_16) && version.less(Version.V1_19))
msg.writeUuid(sender);
}
public enum Position {
public enum PositionLegacy {
CHAT(0),
SYSTEM_MESSAGE(1),
@ -58,7 +63,7 @@ public class PacketChatMessage implements PacketOut {
private final int index;
Position(int index) {
PositionLegacy(int index) {
this.index = index;
}

View File

@ -101,7 +101,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_8, Version.V1_9_1)) {
msg.writeByte(gameMode);
msg.writeByte(dimensionRegistry.getDefaultDimension().getId());
msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(0); // Difficulty
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
@ -110,7 +110,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_9_2, Version.V1_13_2)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(0); // Difficulty
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
@ -119,7 +119,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_14, Version.V1_14_4)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
msg.writeVarInt(viewDistance);
@ -128,7 +128,7 @@ public class PacketJoinGame implements PacketOut {
if (version.fromTo(Version.V1_15, Version.V1_15_2)) {
msg.writeByte(gameMode);
msg.writeInt(dimensionRegistry.getDefaultDimension().getId());
msg.writeInt(dimensionRegistry.getDefaultDimension_1_16().getId());
msg.writeLong(hashedSeed);
msg.writeByte(maxPlayers);
msg.writeString("flat"); // Level type
@ -142,7 +142,7 @@ public class PacketJoinGame implements PacketOut {
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getOldCodec());
msg.writeString(dimensionRegistry.getDefaultDimension().getName());
msg.writeString(dimensionRegistry.getDefaultDimension_1_16().getName());
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeByte(maxPlayers);
@ -158,8 +158,8 @@ public class PacketJoinGame implements PacketOut {
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
msg.writeCompoundTag(dimensionRegistry.getCodec_1_16());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_16().getData());
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
@ -170,13 +170,19 @@ public class PacketJoinGame implements PacketOut {
msg.writeBoolean(isFlat);
}
if (version.moreOrEqual(Version.V1_18)) {
if (version.fromTo(Version.V1_18, Version.V1_18_2)) {
msg.writeBoolean(isHardcore);
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension().getData());
if (version.moreOrEqual(Version.V1_18_2)) {
msg.writeCompoundTag(dimensionRegistry.getCodec_1_18_2());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_18_2().getData());
}
else {
msg.writeCompoundTag(dimensionRegistry.getCodec_1_16());
msg.writeCompoundTag(dimensionRegistry.getDefaultDimension_1_16().getData());
}
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
@ -187,6 +193,25 @@ public class PacketJoinGame implements PacketOut {
msg.writeBoolean(isDebug);
msg.writeBoolean(isFlat);
}
if (version.moreOrEqual(Version.V1_19)) {
msg.writeBoolean(isHardcore);
msg.writeByte(gameMode);
msg.writeByte(previousGameMode);
msg.writeStringsArray(worldNames);
msg.writeCompoundTag(dimensionRegistry.getCodec_1_19());
msg.writeString(worldName); // World type
msg.writeString(worldName);
msg.writeLong(hashedSeed);
msg.writeVarInt(maxPlayers);
msg.writeVarInt(viewDistance);
msg.writeVarInt(viewDistance); // Simulation Distance
msg.writeBoolean(reducedDebugInfo);
msg.writeBoolean(enableRespawnScreen);
msg.writeBoolean(isDebug);
msg.writeBoolean(isFlat);
msg.writeBoolean(false);
}
}
}

View File

@ -54,6 +54,9 @@ public class PacketPlayerInfo implements PacketOut {
msg.writeVarInt(gameMode);
msg.writeVarInt(60);
msg.writeBoolean(false);
if (version.moreOrEqual(Version.V1_19)) {
msg.writeBoolean(false);
}
}
}

View File

@ -84,7 +84,8 @@ public enum State {
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)
map(0x0F, V1_17, V1_18_2),
map(0x11, V1_19, V1_19)
);
clientBound.register(PacketDeclareCommands::new,
@ -92,7 +93,8 @@ public enum State {
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)
map(0x12, V1_17, V1_18_2),
map(0x0F, V1_19, V1_19)
);
clientBound.register(PacketJoinGame::new,
map(0x01, V1_8, V1_8),
@ -101,7 +103,8 @@ public enum State {
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)
map(0x26, V1_17, V1_18_2),
map(0x23, V1_19, V1_19)
);
clientBound.register(PacketPluginMessage::new,
map(0x19, V1_13, V1_13_2),
@ -109,7 +112,8 @@ public enum State {
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)
map(0x18, V1_17, V1_18_2),
map(0x15, V1_19, V1_19)
);
clientBound.register(PacketPlayerAbilities::new,
map(0x39, V1_8, V1_8),
@ -120,7 +124,8 @@ public enum State {
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)
map(0x32, V1_17, V1_18_2),
map(0x2F, V1_19, V1_19)
);
clientBound.register(PacketPlayerPositionAndLook::new,
map(0x08, V1_8, V1_8),
@ -131,7 +136,8 @@ public enum State {
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)
map(0x38, V1_17, V1_18_2),
map(0x36, V1_19, V1_19)
);
clientBound.register(PacketKeepAlive::new,
map(0x00, V1_8, V1_8),
@ -141,7 +147,8 @@ public enum State {
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)
map(0x21, V1_17, V1_18_2),
map(0x1E, V1_19, V1_19)
);
clientBound.register(PacketChatMessage::new,
map(0x02, V1_8, V1_8),
@ -149,13 +156,15 @@ public enum State {
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)
map(0x0F, V1_17, V1_18_2),
map(0x5F, V1_19, V1_19)
);
clientBound.register(PacketBossBar::new,
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)
map(0x0D, V1_17, V1_18_2),
map(0x0A, V1_19, V1_19)
);
clientBound.register(PacketPlayerInfo::new,
map(0x38, V1_8, V1_8),
@ -166,7 +175,8 @@ public enum State {
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)
map(0x36, V1_17, V1_18_2),
map(0x34, V1_19, V1_19)
);
clientBound.register(PacketTitleLegacy::new,
map(0x45, V1_8, V1_11_1),
@ -179,15 +189,15 @@ public enum State {
);
clientBound.register(PacketTitleSetTitle::new,
map(0x59, V1_17, V1_17_1),
map(0x5A, V1_18, V1_18)
map(0x5A, V1_18, V1_19)
);
clientBound.register(PacketTitleSetSubTitle::new,
map(0x57, V1_17, V1_17_1),
map(0x58, V1_18, V1_18)
map(0x58, V1_18, V1_19)
);
clientBound.register(PacketTitleTimes::new,
map(0x5A, V1_17, V1_17_1),
map(0x5B, V1_18, V1_18)
map(0x5B, V1_18, V1_19)
);
clientBound.register(PacketPlayerListHeader::new,
map(0x47, V1_8, V1_8),
@ -200,7 +210,8 @@ public enum State {
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)
map(0x5F, V1_18, V1_18_2),
map(0x60, V1_19, V1_19)
);
}
};

View File

@ -56,8 +56,10 @@ public enum Version {
// 1.16.5 has same protocol number
V1_17(755),
V1_17_1(756),
V1_18(757);
V1_18(757),
// 1.18.1 has same protocol number
V1_18_2(758),
V1_19(759);
private static final Map<Integer, Version> VERSION_MAP;
private static final Version MAX;

View File

@ -20,9 +20,10 @@ package ru.nanit.limbo.util;
public final class Colors {
private static final char CHAR_FROM = '&';
private static final char CHAR_TO = '§';
private static final char CHAR_TO = '\u00a7';
private Colors() {}
private Colors() {
}
public static String of(String text) {
if (text == null) return null;

View File

@ -31,33 +31,55 @@ public final class DimensionRegistry {
private final LimboServer server;
private Dimension defaultDimension;
private Dimension defaultDimension_1_16;
private Dimension defaultDimension_1_18_2;
private CompoundBinaryTag codec;
private CompoundBinaryTag codec_1_16;
private CompoundBinaryTag codec_1_18_2;
private CompoundBinaryTag codec_1_19;
private CompoundBinaryTag oldCodec;
public DimensionRegistry(LimboServer server) {
this.server = server;
}
public CompoundBinaryTag getCodec() {
return codec;
public CompoundBinaryTag getCodec_1_16() {
return codec_1_16;
}
public CompoundBinaryTag getCodec_1_18_2() {
return codec_1_18_2;
}
public CompoundBinaryTag getCodec_1_19() {
return codec_1_19;
}
public CompoundBinaryTag getOldCodec() {
return oldCodec;
}
public Dimension getDefaultDimension() {
return defaultDimension;
public Dimension getDefaultDimension_1_16() {
return defaultDimension_1_16;
}
public Dimension getDefaultDimension_1_18_2() {
return defaultDimension_1_18_2;
}
public void load(String def) throws IOException {
codec = readCodecFile("/dimension/codec_new.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");
// On 1.16-1.16.1 different codec format
oldCodec = readCodecFile("/dimension/codec_old.snbt");
ListBinaryTag dimensions = codec.getCompound("minecraft:dimension_type").getList("value");
defaultDimension_1_16 = getDefaultDimension(def, codec_1_16);
defaultDimension_1_18_2 = getDefaultDimension(def, codec_1_18_2);
}
private Dimension getDefaultDimension(String def, CompoundBinaryTag tag) {
ListBinaryTag dimensions = tag.getCompound("minecraft:dimension_type").getList("value");
CompoundBinaryTag overWorld = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(0)).get("element");
CompoundBinaryTag nether = (CompoundBinaryTag) ((CompoundBinaryTag) dimensions.get(2)).get("element");
@ -65,18 +87,14 @@ public final class DimensionRegistry {
switch (def.toLowerCase()) {
case "overworld":
defaultDimension = new Dimension(0, "minecraft:overworld", overWorld);
break;
case "nether":
defaultDimension = new Dimension(-1, "minecraft:nether", nether);
break;
return new Dimension(0, "minecraft:overworld", overWorld);
case "the_nether":
return new Dimension(-1, "minecraft:nether", nether);
case "the_end":
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
break;
return new Dimension(1, "minecraft:the_end", theEnd);
default:
defaultDimension = new Dimension(1, "minecraft:the_end", theEnd);
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
break;
return new Dimension(1, "minecraft:the_end", theEnd);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@ headerAndFooter:
# Spawn position in the world
spawnPosition:
x: 0.0
y: 64.0
y: 400.0
z: 0.0
yaw: 0.0
pitch: 0.0