From 54ae3bd747490c5f7763a8f52bd5d9588d227fda Mon Sep 17 00:00:00 2001 From: lokspel <208148594+lokspel@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:45:14 +0400 Subject: [PATCH] Add configurable verification dimension (Overworld/Nether/End) --- .../sonar/api/config/SonarConfiguration.java | 12 +++++++ .../common/protocol/SonarPacketPreparer.java | 10 ++++-- .../protocol/packets/play/JoinGamePacket.java | 36 ++++++++++++++++++- .../src/main/resources/assets/config/cs.yml | 3 ++ .../src/main/resources/assets/config/de.yml | 3 ++ .../src/main/resources/assets/config/en.yml | 3 ++ .../src/main/resources/assets/config/fr.yml | 3 ++ .../src/main/resources/assets/config/ka.yml | 3 ++ .../src/main/resources/assets/config/nl.yml | 3 ++ .../src/main/resources/assets/config/pl.yml | 3 ++ .../main/resources/assets/config/pt-br.yml | 3 ++ .../src/main/resources/assets/config/ru.yml | 3 ++ .../src/main/resources/assets/config/zh.yml | 3 ++ 13 files changed, 84 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/xyz/jonesdev/sonar/api/config/SonarConfiguration.java b/api/src/main/java/xyz/jonesdev/sonar/api/config/SonarConfiguration.java index f1196471..2bdca15b 100644 --- a/api/src/main/java/xyz/jonesdev/sonar/api/config/SonarConfiguration.java +++ b/api/src/main/java/xyz/jonesdev/sonar/api/config/SonarConfiguration.java @@ -199,6 +199,7 @@ public void loadValues() { verification.timeOfDay = clamp(generalConfig.getInt("verification.time-of-day"), 0, 24000); verification.gamemode = Verification.Gamemode.valueOf(generalConfig.getString("verification.gamemode")); + verification.dimension = Verification.Dimension.valueOf(generalConfig.getString("verification.dimension")); verification.validNameRegex = Pattern.compile(generalConfig.getString("verification.checks.valid-name-regex")); verification.checkGeyser = generalConfig.getBoolean("verification.check-geyser-players"); @@ -405,6 +406,7 @@ public static final class Brand { } private Gamemode gamemode; + private Dimension dimension; @Getter @RequiredArgsConstructor @@ -421,6 +423,16 @@ public boolean isSurvivalOrAdventure() { } } + @Getter + @RequiredArgsConstructor + public enum Dimension { + OVERWORLD("minecraft:overworld"), + THE_NETHER("minecraft:the_nether"), + THE_END("minecraft:the_end"); + + private final String key; + } + private int timeOfDay; private boolean checkGeyser; private boolean checkEagler; diff --git a/common/src/main/java/xyz/jonesdev/sonar/common/protocol/SonarPacketPreparer.java b/common/src/main/java/xyz/jonesdev/sonar/common/protocol/SonarPacketPreparer.java index 661def29..fe15d2c9 100644 --- a/common/src/main/java/xyz/jonesdev/sonar/common/protocol/SonarPacketPreparer.java +++ b/common/src/main/java/xyz/jonesdev/sonar/common/protocol/SonarPacketPreparer.java @@ -155,12 +155,16 @@ public void prepare() { loginSuccess = new SonarPacketSnapshot(new LoginSuccessPacket(uuid, username, true)); // Prepare JoinGame packet + final SonarConfiguration.Verification.Dimension configDimension = + Sonar.get0().getConfig().getVerification().getDimension(); + final DimensionType verificationDimension = DimensionType.valueOf(configDimension.name()); + final String dimensionKey = configDimension.getKey(); joinGame = new SonarPacketSnapshot(new JoinGamePacket(PLAYER_ENTITY_ID, Sonar.get0().getConfig().getVerification().getGamemode().getId(), -1, 0, 0, RANDOM.nextInt(3), 1, 0, 0, - new String[]{"minecraft:overworld"}, "minecraft:overworld", "flat", - DimensionType.OVERWORLD, RANDOM.nextLong() & 1337, + new String[]{dimensionKey}, dimensionKey, "flat", + verificationDimension, RANDOM.nextLong() & 1337, false, true, false, false, false, false, true)); @@ -177,7 +181,7 @@ public void prepare() { // Set the dynamic block and collide Y position based on the maximum fall distance dynamicSpawnYPosition = PLATFORM_Y_POSITION + (int) Math.ceil(fallDistance); defaultSpawnPosition = new SonarPacketSnapshot(new SetDefaultSpawnPositionPacket( - "minecraft:overworld", + dimensionKey, SPAWN_X_POSITION, IN_AIR_Y_POSITION, SPAWN_Z_POSITION)); spawnPosition = new SonarPacketSnapshot(new SetPlayerPositionRotationPacket( SPAWN_X_POSITION, IN_AIR_Y_POSITION, SPAWN_Z_POSITION, diff --git a/common/src/main/java/xyz/jonesdev/sonar/common/protocol/packets/play/JoinGamePacket.java b/common/src/main/java/xyz/jonesdev/sonar/common/protocol/packets/play/JoinGamePacket.java index d86a1533..8cd0c1ac 100644 --- a/common/src/main/java/xyz/jonesdev/sonar/common/protocol/packets/play/JoinGamePacket.java +++ b/common/src/main/java/xyz/jonesdev/sonar/common/protocol/packets/play/JoinGamePacket.java @@ -140,7 +140,7 @@ public void encode(final @NotNull ByteBuf byteBuf, final @NotNull ProtocolVersio byteBuf.writeBoolean(limitedCrafting); if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_20_5)) { - ProtocolUtil.writeVarInt(byteBuf, dimension.getId()); + ProtocolUtil.writeVarInt(byteBuf, findDimensionId(getRegistryCodec(protocolVersion))); } else { ProtocolUtil.writeString(byteBuf, dimension.getKey()); } @@ -173,6 +173,40 @@ public void encode(final @NotNull ByteBuf byteBuf, final @NotNull ProtocolVersio } } + private int findDimensionId(final @NotNull CompoundBinaryTag codec) { + final CompoundBinaryTag dimensionType = codec.getCompound("minecraft:dimension_type"); + if (dimensionType == null) return dimension.getId(); + final ListBinaryTag values = dimensionType.getList("value"); + if (values == null) return dimension.getId(); + for (int i = 0; i < values.size(); i++) { + final CompoundBinaryTag entry = (CompoundBinaryTag) values.get(i); + if (entry == null) continue; + if (levelName.equals(entry.getString("name"))) { + return entry.getInt("id"); + } + } + return dimension.getId(); + } + + private static @NotNull CompoundBinaryTag getRegistryCodec(final @NotNull ProtocolVersion protocolVersion) { + if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_26_1)) { + return DimensionRegistry.CODEC_26_1; + } else if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_21_11)) { + return DimensionRegistry.CODEC_1_21_11; + } else if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_21_5)) { + return DimensionRegistry.CODEC_1_21_5; + } else if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_21_4)) { + return DimensionRegistry.CODEC_1_21_4; + } else if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_21_2)) { + return DimensionRegistry.CODEC_1_21_2; + } else if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_21)) { + return DimensionRegistry.CODEC_1_21; + } else if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_20_5)) { + return DimensionRegistry.CODEC_1_20_5; + } + return DimensionRegistry.CODEC_1_20; + } + private static CompoundBinaryTag getCodec(final @NotNull ProtocolVersion protocolVersion) { if (protocolVersion.greaterThanOrEquals(ProtocolVersion.MINECRAFT_1_20)) { return DimensionRegistry.CODEC_1_20; diff --git a/common/src/main/resources/assets/config/cs.yml b/common/src/main/resources/assets/config/cs.yml index ac96409d..f2e1c65d 100644 --- a/common/src/main/resources/assets/config/cs.yml +++ b/common/src/main/resources/assets/config/cs.yml @@ -170,6 +170,9 @@ verification: # na kterém proxy naslouchá (port "bind" v konfiguraci vašeho proxy). destination-port: 25565 + # Dimenze ověřovacího světa + # Typy: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # Gamemode hráče při verifikaci # Typy: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: všechny komponenty UI jsou zobrazeny diff --git a/common/src/main/resources/assets/config/de.yml b/common/src/main/resources/assets/config/de.yml index f4a648c6..4f297a0a 100644 --- a/common/src/main/resources/assets/config/de.yml +++ b/common/src/main/resources/assets/config/de.yml @@ -168,6 +168,9 @@ verification: # den Port, auf dem der Proxy horcht (den "Bind"-Port in Ihrer Proxy-Konfiguration). destination-port: 25565 + # Die Dimension der Verifizierungswelt + # Mögliche Typen: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # Der Spielmodus des Spielers während der Überprüfung # Mögliche Typen: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: alle UI-Komponenten sind sichtbar diff --git a/common/src/main/resources/assets/config/en.yml b/common/src/main/resources/assets/config/en.yml index 45fff390..b558c42b 100644 --- a/common/src/main/resources/assets/config/en.yml +++ b/common/src/main/resources/assets/config/en.yml @@ -170,6 +170,9 @@ verification: # the port the proxy is listening on (the "bind" port in your proxy config). destination-port: 25565 + # The dimension of the verification world + # Possible types: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # The gamemode of the player during verification # Possible types: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: all UI components are visible diff --git a/common/src/main/resources/assets/config/fr.yml b/common/src/main/resources/assets/config/fr.yml index f444dc0b..0cc9c5de 100644 --- a/common/src/main/resources/assets/config/fr.yml +++ b/common/src/main/resources/assets/config/fr.yml @@ -170,6 +170,9 @@ verification: # le port d'écoute du proxy (le port "bind" dans la configuration de votre proxy). destination-port: 25565 + # La dimension du monde de vérification + # Types possibles : OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # Le mode de jeu du joueur pendant la vérification # Types possibles : SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL : tous les composants de l'interface utilisateur sont visibles diff --git a/common/src/main/resources/assets/config/ka.yml b/common/src/main/resources/assets/config/ka.yml index bb8402b1..8a972bf4 100644 --- a/common/src/main/resources/assets/config/ka.yml +++ b/common/src/main/resources/assets/config/ka.yml @@ -169,6 +169,9 @@ verification: # რომელზეც პროქსი უსმენს ("bind" პორტი თქვენი პროქსის კონფიგურაციაში). destination-port: 25565 + # გადამოწმების სამყაროს განზომილება + # შესაძლო ტიპები: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # მოთამაშის თამაშის რეჟიმი გადამოწმების დროს # შესაძლო ტიპები: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: ყველა UI კომპონენტი ჩანს diff --git a/common/src/main/resources/assets/config/nl.yml b/common/src/main/resources/assets/config/nl.yml index 8fae7202..049e77fb 100644 --- a/common/src/main/resources/assets/config/nl.yml +++ b/common/src/main/resources/assets/config/nl.yml @@ -170,6 +170,9 @@ verification: # de poort waarop de proxy luistert (de "bind"-poort in uw proxyconfiguratie). destination-port: 25565 + # De dimensie van de verificatiewereld + # Mogelijke typen: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # De spelmodus van de speler tijdens verificatie # Mogelijke typen: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: alle UI-componenten zijn zichtbaar diff --git a/common/src/main/resources/assets/config/pl.yml b/common/src/main/resources/assets/config/pl.yml index 489ecd17..a8555eab 100644 --- a/common/src/main/resources/assets/config/pl.yml +++ b/common/src/main/resources/assets/config/pl.yml @@ -169,6 +169,9 @@ verification: # na którym nasłuchuje proxy (port "bind" w konfiguracji twojego proxy). destination-port: 25565 + # Wymiar świata weryfikacji + # Dostępne rodzaje: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # Tryb gry gracza (gamemode) podczas weryfikacji # Dostępne rodzaje: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: Wszystkie komponenty interfejsu są widoczne diff --git a/common/src/main/resources/assets/config/pt-br.yml b/common/src/main/resources/assets/config/pt-br.yml index 085a6be6..c52947d3 100644 --- a/common/src/main/resources/assets/config/pt-br.yml +++ b/common/src/main/resources/assets/config/pt-br.yml @@ -169,6 +169,9 @@ verification: # a porta em que o proxy está ouvindo (a porta "bind" na configuração do seu proxy). destination-port: 25565 + # A dimensão do mundo de verificação + # Tipos possíveis: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # O modo de jogo do jogador durante a verificação # Tipos possíveis: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: todos os componentes da UI são visíveis diff --git a/common/src/main/resources/assets/config/ru.yml b/common/src/main/resources/assets/config/ru.yml index 36c0ef0e..76b52ada 100644 --- a/common/src/main/resources/assets/config/ru.yml +++ b/common/src/main/resources/assets/config/ru.yml @@ -170,6 +170,9 @@ verification: # на котором слушает прокси (порт "bind" в конфигурации вашего прокси). destination-port: 25565 + # Измерение мира проверки + # Возможные типы: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # Режим игрока во время проверки # Возможные типы: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: все компоненты пользовательского интерфейса видны diff --git a/common/src/main/resources/assets/config/zh.yml b/common/src/main/resources/assets/config/zh.yml index 1f4edb21..e96e4534 100644 --- a/common/src/main/resources/assets/config/zh.yml +++ b/common/src/main/resources/assets/config/zh.yml @@ -165,6 +165,9 @@ verification: # 代理服务器监听的端口 (代理配置中的 "bind" 端口)。 destination-port: 25565 + # 验证世界的维度 + # 可用类型: OVERWORLD, THE_NETHER, THE_END + dimension: OVERWORLD # 玩家正在验证时所使用的游戏模式 # 可用类型: SURVIVAL, CREATIVE, ADVENTURE # - SURVIVAL: 生存模式, 所有UI可见