From ae983779baf072832edcec93b39de9de4276fa02 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 25 Sep 2023 22:54:23 +0200 Subject: [PATCH 01/23] Fix: Don't allow client side gamemode changes even if rogue plugins send a level 4 op permission... (#4148) --- .../registry/PacketTranslatorRegistry.java | 2 - .../BedrockRequestPermissionsPacket.java | 43 +++++++++++++++++++ .../BedrockSetDefaultGameTypeTranslator.java | 2 +- .../BedrockSetDifficultyTranslator.java | 2 +- .../BedrockSetPlayerGameTypeTranslator.java | 2 +- 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockRequestPermissionsPacket.java diff --git a/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java index dbc8e2e26..61999d4f6 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java @@ -29,7 +29,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDe import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundTabListPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLightUpdatePacket; import io.netty.channel.EventLoop; -import org.cloudburstmc.protocol.bedrock.packet.RequestPermissionsPacket; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.registry.loader.RegistryLoaders; import org.geysermc.geyser.session.GeyserSession; @@ -47,7 +46,6 @@ public class PacketTranslatorRegistry extends AbstractMappedRegistry { + + @Override + public void translate(GeyserSession session, RequestPermissionsPacket packet) { + session.sendAdventureSettings(); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDefaultGameTypeTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDefaultGameTypeTranslator.java index c818cc910..df28f7ca7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDefaultGameTypeTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDefaultGameTypeTranslator.java @@ -41,7 +41,7 @@ public class BedrockSetDefaultGameTypeTranslator extends PacketTranslator= 2 || session.hasPermission("geyser.settings.server")) { + if (session.getOpPermissionLevel() >= 2 && session.hasPermission("geyser.settings.server")) { session.getGeyser().getWorldManager().setDefaultGameMode(session, GameMode.byId(packet.getGamemode())); } // Stop the client from updating their own Gamemode without telling the server diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDifficultyTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDifficultyTranslator.java index a36aa77df..b996a96b1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDifficultyTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetDifficultyTranslator.java @@ -39,7 +39,7 @@ public class BedrockSetDifficultyTranslator extends PacketTranslator= 2 || session.hasPermission("geyser.settings.server")) { + if (session.getOpPermissionLevel() >= 2 && session.hasPermission("geyser.settings.server")) { if (packet.getDifficulty() != session.getWorldCache().getDifficulty().ordinal()) { session.getGeyser().getWorldManager().setDifficulty(session, Difficulty.from(packet.getDifficulty())); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetPlayerGameTypeTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetPlayerGameTypeTranslator.java index a1c2c2987..2d8d420f8 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetPlayerGameTypeTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockSetPlayerGameTypeTranslator.java @@ -45,7 +45,7 @@ public class BedrockSetPlayerGameTypeTranslator extends PacketTranslator= 2 || session.hasPermission("geyser.settings.server")) { + if (session.getOpPermissionLevel() >= 2 && session.hasPermission("geyser.settings.server")) { if (packet.getGamemode() != session.getGameMode().ordinal()) { // Bedrock has more Gamemodes than Java, leading to cases 5 (for "default") and 6 (for "spectator") being sent // https://github.com/CloudburstMC/Protocol/blob/3.0/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/GameType.java From 5276a1e2ba7a32ed47b8fcea64f13f12323b3ecd Mon Sep 17 00:00:00 2001 From: Spongecade Date: Wed, 27 Sep 2023 09:55:54 -0500 Subject: [PATCH 02/23] Update Minecraft Wiki links to new domain (#4151) --- .../org/geysermc/geyser/inventory/item/TippedArrowPotion.java | 2 +- .../main/java/org/geysermc/geyser/text/MinecraftLocale.java | 2 +- .../protocol/java/entity/JavaEntityEventTranslator.java | 2 +- .../translator/protocol/java/level/JavaSetTimeTranslator.java | 2 +- .../main/java/org/geysermc/geyser/util/AttributeUtils.java | 2 +- core/src/main/java/org/geysermc/geyser/util/BlockUtils.java | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java b/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java index ddc44fbc4..e45667fe2 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java @@ -31,7 +31,7 @@ import java.util.Locale; /** * Potion identifiers and their respective Bedrock IDs used with arrows. - * https://minecraft.gamepedia.com/Arrow#Item_Data + * https://minecraft.wiki/w/Arrow#Data_values */ @Getter public enum TippedArrowPotion { diff --git a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java index 260b45136..00866eda3 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java @@ -76,7 +76,7 @@ public class MinecraftLocale { public static void downloadAndLoadLocale(String locale) { locale = locale.toLowerCase(Locale.ROOT); if (locale.equals("nb_no")) { - // Different locale code - https://minecraft.fandom.com/wiki/Language + // Different locale code - https://minecraft.wiki/w/Language locale = "no_no"; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index 50582974d..4b1483bbf 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -120,7 +120,7 @@ public class JavaEntityEventTranslator extends PacketTranslator 2.0; case "stone" -> 4.0; case "iron" -> 6.0; @@ -100,7 +100,7 @@ public final class BlockUtils { return true; } - // https://minecraft.gamepedia.com/Breaking + // https://minecraft.wiki/w/Breaking private static double calculateBreakTime(double blockHardness, String toolTier, boolean canHarvestWithHand, boolean correctTool, boolean canTierMineBlock, String toolType, boolean isShearsEffective, int toolEfficiencyLevel, int hasteLevel, int miningFatigueLevel, boolean insideOfWaterWithoutAquaAffinity, boolean onGround) { From c2cd99c82939f19ffaf6310e4b84458b70c550fc Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:14:49 -0400 Subject: [PATCH 03/23] Support Java 1.20.2 (#4112) * Initial pass for 1.20.2, compiling * Remove unused level events * handle null GameProfile in ClientboundPlayerInfoUpdatePacket * Handle level events BRUSH_BLOCK_COMPLETE and EGG_CRACK * Account for null tag in DecoratedPotBlockEntityTranslator * Explicitly show that 1.20.31 is supported --- README.md | 2 +- .../java/org/geysermc/geyser/GeyserImpl.java | 1 - .../geyser/level/GeyserAdvancement.java | 5 -- .../geysermc/geyser/network/GameProtocol.java | 8 ++- .../registry/PacketTranslatorRegistry.java | 4 +- .../geyser/session/GeyserSession.java | 14 ++-- .../geyser/session/cache/TagCache.java | 5 +- .../DecoratedPotBlockEntityTranslator.java | 4 ++ .../BedrockNetworkStackLatencyTranslator.java | 2 +- .../java/JavaCustomPayloadTranslator.java | 4 +- .../java/JavaCustomQueryTranslator.java | 4 +- .../java/JavaDisconnectTranslator.java | 2 +- .../java/JavaGameProfileTranslator.java | 9 +++ .../java/JavaKeepAliveTranslator.java | 2 +- .../protocol/java/JavaLoginTranslator.java | 57 +++------------ .../protocol/java/JavaPingTranslator.java | 4 +- .../java/JavaRegistryDataTranslator.java | 67 +++++++++++++++++ .../protocol/java/JavaRespawnTranslator.java | 14 ++-- .../java/JavaUpdateTagsTranslator.java | 2 +- .../entity/JavaUpdateMobEffectTranslator.java | 3 +- .../JavaPlayerInfoUpdateTranslator.java | 31 +++++--- .../entity/spawn/JavaAddEntityTranslator.java | 38 +++++++++- .../entity/spawn/JavaAddPlayerTranslator.java | 72 ------------------- .../JavaChunkBatchFinishedTranslator.java | 44 ++++++++++++ .../java/level/JavaLevelEventTranslator.java | 6 ++ .../geyser/util/PluginMessageUtils.java | 2 +- core/src/main/resources/mappings | 2 +- gradle/libs.versions.toml | 2 +- 28 files changed, 243 insertions(+), 167 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRegistryDataTranslator.java delete mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/spawn/JavaAddPlayerTranslator.java create mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaChunkBatchFinishedTranslator.java diff --git a/README.md b/README.md index 7f9f6fe9e..d78386687 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here! -### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.30 and Minecraft Java 1.20/1.20.1. +### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.31 and Minecraft Java 1.20/1.20.1. ## Setting Up Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser. diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index d13836e9a..4a5f16bfa 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -71,7 +71,6 @@ import org.geysermc.geyser.level.WorldManager; import org.geysermc.geyser.network.netty.GeyserServer; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.Registries; -import org.geysermc.geyser.registry.loader.RegistryLoaders; import org.geysermc.geyser.scoreboard.ScoreboardUpdater; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.PendingMicrosoftAuthentication; diff --git a/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java b/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java index fc3c86dd4..936248afe 100644 --- a/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java +++ b/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java @@ -52,11 +52,6 @@ public class GeyserAdvancement { return this.advancement.getId(); } - @NonNull - public List getCriteria() { - return this.advancement.getCriteria(); - } - @NonNull public List> getRequirements() { return this.advancement.getRequirements(); diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 63cce329c..fb9684f77 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -46,7 +46,9 @@ public final class GameProtocol { * Default Bedrock codec that should act as a fallback. Should represent the latest available * release of the game that Geyser supports. */ - public static final BedrockCodec DEFAULT_BEDROCK_CODEC = Bedrock_v618.CODEC; + public static final BedrockCodec DEFAULT_BEDROCK_CODEC = Bedrock_v618.CODEC.toBuilder() + .minecraftVersion("1.20.31") + .build(); /** * A list of all supported Bedrock versions that can join Geyser @@ -66,7 +68,9 @@ public final class GameProtocol { SUPPORTED_BEDROCK_CODECS.add(Bedrock_v594.CODEC.toBuilder() .minecraftVersion("1.20.10/1.20.15") .build()); - SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC); + SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder() + .minecraftVersion("1.20.30/1.20.31") + .build()); } /** diff --git a/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java index 61999d4f6..e37f8aa64 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/PacketTranslatorRegistry.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.registry; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDelimiterPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundTabListPacket; +import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundChunkBatchStartPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLightUpdatePacket; import io.netty.channel.EventLoop; import org.geysermc.geyser.GeyserImpl; @@ -43,9 +44,10 @@ public class PacketTranslatorRegistry extends AbstractMappedRegistry> IGNORED_PACKETS = Collections.newSetFromMap(new IdentityHashMap<>()); static { + IGNORED_PACKETS.add(ClientboundChunkBatchStartPacket.class); // we don't track chunk batch sizes/periods + IGNORED_PACKETS.add(ClientboundDelimiterPacket.class); // Not implemented, spams logs IGNORED_PACKETS.add(ClientboundLightUpdatePacket.class); // Light is handled on Bedrock for us IGNORED_PACKETS.add(ClientboundTabListPacket.class); // Cant be implemented in Bedrock - IGNORED_PACKETS.add(ClientboundDelimiterPacket.class); // Not implemented, spams logs } protected PacketTranslatorRegistry() { diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index f7d362e0d..5c9725fae 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -45,15 +45,15 @@ import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility; import com.github.steveice10.mc.protocol.data.game.setting.SkinPart; import com.github.steveice10.mc.protocol.data.game.statistic.CustomStatistic; import com.github.steveice10.mc.protocol.data.game.statistic.Statistic; +import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundClientInformationPacket; import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientInformationPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemPacket; -import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundCustomQueryPacket; +import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundCustomQueryAnswerPacket; import com.github.steveice10.packetlib.BuiltinFlags; import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.event.session.ConnectedEvent; @@ -292,7 +292,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { private Vector2i lastChunkPosition = null; @Setter private int clientRenderDistance = -1; - private int serverRenderDistance; + private int serverRenderDistance = -1; // Exposed for GeyserConnect usage protected boolean sentSpawnPacket; @@ -1665,7 +1665,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } private void sendDownstreamPacket0(Packet packet) { - if (protocol.getState().equals(ProtocolState.GAME) || packet.getClass() == ServerboundCustomQueryPacket.class) { + ProtocolState state = protocol.getState(); + if (state == ProtocolState.GAME || state == ProtocolState.CONFIGURATION || packet.getClass() == ServerboundCustomQueryAnswerPacket.class) { downstream.sendPacket(packet); } else { geyser.getLogger().debug("Tried to send downstream packet " + packet.getClass().getSimpleName() + " before connected to the server"); @@ -1824,8 +1825,11 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { if (clientRenderDistance != -1) { // The client has sent a render distance return clientRenderDistance; + } else if (serverRenderDistance != -1) { + // only known once ClientboundLoginPacket is received + return serverRenderDistance; } - return serverRenderDistance; + return 2; // unfortunate default until we got more info } // We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/TagCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/TagCache.java index ab1dfbe2b..5acfc1f09 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/TagCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/TagCache.java @@ -25,9 +25,10 @@ package org.geysermc.geyser.session.cache; -import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundUpdateTagsPacket; +import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundUpdateTagsPacket; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntLists; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserLogger; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -112,7 +113,7 @@ public class TagCache { } } - private IntList load(int[] tags) { + private IntList load(int @Nullable[] tags) { if (tags == null) { return IntLists.EMPTY_LIST; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java index e60342b27..1774d9c76 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java @@ -41,6 +41,10 @@ public class DecoratedPotBlockEntityTranslator extends BlockEntityTranslator { @Override public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) { + if (tag == null) { + return; + } + // exact same format if (tag.get("sherds") instanceof ListTag sherds) { List translated = new ArrayList<>(4); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java index 1ccd5ced9..412a97e3a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java @@ -25,7 +25,7 @@ package org.geysermc.geyser.translator.protocol.bedrock; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket; +import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundKeepAlivePacket; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.packet.NetworkStackLatencyPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomPayloadTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomPayloadTranslator.java index cf5cfa198..2a7202b0c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomPayloadTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomPayloadTranslator.java @@ -25,8 +25,8 @@ package org.geysermc.geyser.translator.protocol.java; -import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCustomPayloadPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket; +import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket; +import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket; import com.google.common.base.Charsets; import org.cloudburstmc.protocol.bedrock.packet.TransferPacket; import org.cloudburstmc.protocol.bedrock.packet.UnknownPacket; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomQueryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomQueryTranslator.java index 89df63898..0eaef91f1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomQueryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCustomQueryTranslator.java @@ -26,7 +26,7 @@ package org.geysermc.geyser.translator.protocol.java; import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundCustomQueryPacket; -import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundCustomQueryPacket; +import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundCustomQueryAnswerPacket; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; @@ -41,7 +41,7 @@ public class JavaCustomQueryTranslator extends PacketTranslator CONFIGURATION + */ @Translator(packet = ClientboundGameProfilePacket.class) public class JavaGameProfileTranslator extends PacketTranslator { @@ -65,5 +70,9 @@ public class JavaGameProfileTranslator extends PacketTranslator { @@ -64,42 +55,22 @@ public class JavaLoginTranslator extends PacketTranslator dimensions = session.getDimensions(); - dimensions.clear(); - - JavaDimension.load(packet.getRegistry(), dimensions); - - Int2ObjectMap chatTypes = session.getChatTypes(); - chatTypes.clear(); - for (CompoundTag tag : JavaCodecUtil.iterateAsTag(packet.getRegistry().get("minecraft:chat_type"))) { - // The ID is NOT ALWAYS THE SAME! ViaVersion as of 1.19 adds two registry entries that do NOT match vanilla. - int id = ((IntTag) tag.get("id")).getValue(); - CompoundTag element = tag.get("element"); - CompoundTag chat = element.get("chat"); - TextDecoration textDecoration = null; - if (chat != null) { - textDecoration = new TextDecoration(chat); - } - chatTypes.put(id, textDecoration); - } + PlayerSpawnInfo spawnInfo = packet.getCommonPlayerSpawnInfo(); // If the player is already initialized and a join game packet is sent, they // are swapping servers if (session.isSpawned()) { - String fakeDim = DimensionUtils.getTemporaryDimension(session.getDimension(), packet.getDimension()); + String fakeDim = DimensionUtils.getTemporaryDimension(session.getDimension(), spawnInfo.getDimension()); DimensionUtils.switchDimension(session, fakeDim); session.getWorldCache().removeScoreboard(); } - session.setWorldName(packet.getWorldName()); + session.setWorldName(spawnInfo.getWorldName()); session.setLevels(packet.getWorldNames()); - BiomeTranslator.loadServerBiomes(session, packet.getRegistry()); - session.getTagCache().clear(); + session.setGameMode(spawnInfo.getGameMode()); - session.setGameMode(packet.getGameMode()); - - String newDimension = packet.getDimension(); + String newDimension = spawnInfo.getDimension(); boolean needsSpawnPacket = !session.isSentSpawnPacket(); if (needsSpawnPacket) { @@ -114,11 +85,11 @@ public class JavaLoginTranslator extends PacketTranslator { + + @Override + public void translate(GeyserSession session, ClientboundRegistryDataPacket packet) { + Map dimensions = session.getDimensions(); + dimensions.clear(); + JavaDimension.load(packet.getRegistry(), dimensions); + + Int2ObjectMap chatTypes = session.getChatTypes(); + chatTypes.clear(); + for (CompoundTag tag : JavaCodecUtil.iterateAsTag(packet.getRegistry().get("minecraft:chat_type"))) { + // The ID is NOT ALWAYS THE SAME! ViaVersion as of 1.19 adds two registry entries that do NOT match vanilla. + int id = ((IntTag) tag.get("id")).getValue(); + CompoundTag element = tag.get("element"); + CompoundTag chat = element.get("chat"); + TextDecoration textDecoration = null; + if (chat != null) { + textDecoration = new TextDecoration(chat); + } + chatTypes.put(id, textDecoration); + } + + BiomeTranslator.loadServerBiomes(session, packet.getRegistry()); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRespawnTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRespawnTranslator.java index 71f5dc8fc..fb7536b19 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRespawnTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRespawnTranslator.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.translator.protocol.java; +import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; @@ -46,6 +47,7 @@ public class JavaRespawnTranslator extends PacketTranslator { @@ -50,13 +52,24 @@ public class JavaPlayerInfoUpdateTranslator extends PacketTranslator definition = Registries.ENTITY_DEFINITIONS.get(packet.getType()); + if (definition == null) { + session.getGeyser().getLogger().warning("Could not find an entity definition with type " + packet.getType()); + return; + } + Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ()); float yaw = packet.getYaw(); float pitch = packet.getPitch(); float headYaw = packet.getHeadYaw(); - EntityDefinition definition = Registries.ENTITY_DEFINITIONS.get(packet.getType()); - if (definition == null) { - session.getGeyser().getLogger().warning("Could not find an entity definition with type " + packet.getType()); + if (packet.getType() == EntityType.PLAYER) { + + PlayerEntity entity; + if (packet.getUuid().equals(session.getPlayerEntity().getUuid())) { + // Server is sending a fake version of the current player + entity = new PlayerEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + session.getPlayerEntity().getUuid(), position, motion, yaw, pitch, headYaw, session.getPlayerEntity().getUsername(), + session.getPlayerEntity().getTexturesProperty()); + } else { + entity = session.getEntityCache().getPlayerEntity(packet.getUuid()); + if (entity == null) { + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.entity.player.failed_list", packet.getUuid())); + return; + } + + entity.setEntityId(packet.getEntityId()); + entity.setPosition(position); + entity.setYaw(yaw); + entity.setPitch(pitch); + entity.setHeadYaw(headYaw); + entity.setMotion(motion); + } + session.getEntityCache().cacheEntity(entity); + + entity.sendPlayer(); + SkinManager.requestAndHandleSkinAndCape(entity, session, null); return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/spawn/JavaAddPlayerTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/spawn/JavaAddPlayerTranslator.java deleted file mode 100644 index 20a5f8213..000000000 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/spawn/JavaAddPlayerTranslator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.translator.protocol.java.entity.spawn; - -import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.entity.type.player.PlayerEntity; -import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.skin.SkinManager; -import org.geysermc.geyser.text.GeyserLocale; -import org.geysermc.geyser.translator.protocol.PacketTranslator; -import org.geysermc.geyser.translator.protocol.Translator; - -@Translator(packet = ClientboundAddPlayerPacket.class) -public class JavaAddPlayerTranslator extends PacketTranslator { - - @Override - public void translate(GeyserSession session, ClientboundAddPlayerPacket packet) { - Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); - float yaw = packet.getYaw(); - float pitch = packet.getPitch(); - float headYaw = packet.getYaw(); - - PlayerEntity entity; - if (packet.getUuid().equals(session.getPlayerEntity().getUuid())) { - // Server is sending a fake version of the current player - entity = new PlayerEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), - session.getPlayerEntity().getUuid(), position, Vector3f.ZERO, yaw, pitch, headYaw, session.getPlayerEntity().getUsername(), - session.getPlayerEntity().getTexturesProperty()); - } else { - entity = session.getEntityCache().getPlayerEntity(packet.getUuid()); - if (entity == null) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.entity.player.failed_list", packet.getUuid())); - return; - } - - entity.setEntityId(packet.getEntityId()); - entity.setPosition(position); - entity.setYaw(yaw); - entity.setPitch(pitch); - entity.setHeadYaw(headYaw); - } - session.getEntityCache().cacheEntity(entity); - - entity.sendPlayer(); - SkinManager.requestAndHandleSkinAndCape(entity, session, null); - } -} diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaChunkBatchFinishedTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaChunkBatchFinishedTranslator.java new file mode 100644 index 000000000..67f56111a --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaChunkBatchFinishedTranslator.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.translator.protocol.java.level; + +import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundChunkBatchFinishedPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundChunkBatchReceivedPacket; +import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.translator.protocol.PacketTranslator; +import org.geysermc.geyser.translator.protocol.Translator; + +@Translator(packet = ClientboundChunkBatchFinishedPacket.class) +public class JavaChunkBatchFinishedTranslator extends PacketTranslator { + + @Override + public void translate(GeyserSession session, ClientboundChunkBatchFinishedPacket packet) { + // server just sent a batch of LevelChunkWithLightPackets + // the vanilla client uses a ChunkBatchSizeCalculator to calculate the desiredChunksPerTick, + // but currently we just send an arbitrary value. server clamps the value between 0.01 and 64. + session.sendDownstreamPacket(new ServerboundChunkBatchReceivedPacket(20)); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelEventTranslator.java index d59b40b8f..aecb304db 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelEventTranslator.java @@ -31,6 +31,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.Clientb import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; +import org.cloudburstmc.protocol.bedrock.data.ParticleType; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; @@ -103,6 +104,10 @@ public class JavaLevelEventTranslator extends PacketTranslator { + effectPacket.setType(ParticleType.BRUSH_DUST); + session.playSoundEvent(SoundEvent.BRUSH_COMPLETED, pos); // todo 1.20.2 verify this + } case COMPOSTER -> { effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_CROP_GROWTH); @@ -224,6 +229,7 @@ public class JavaLevelEventTranslator extends PacketTranslator effectPacket.setType(ParticleType.VILLAGER_HAPPY); // both the lil green sparkle case ENDERDRAGON_FIREBALL_EXPLODE -> { effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_EYE_OF_ENDER_DEATH); // TODO diff --git a/core/src/main/java/org/geysermc/geyser/util/PluginMessageUtils.java b/core/src/main/java/org/geysermc/geyser/util/PluginMessageUtils.java index 032dd2af7..f6b91388f 100644 --- a/core/src/main/java/org/geysermc/geyser/util/PluginMessageUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/PluginMessageUtils.java @@ -25,7 +25,7 @@ package org.geysermc.geyser.util; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket; +import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket; import com.google.common.base.Charsets; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.session.GeyserSession; diff --git a/core/src/main/resources/mappings b/core/src/main/resources/mappings index 587220aaf..31ce17e12 160000 --- a/core/src/main/resources/mappings +++ b/core/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 587220aafb55e80f2a70d6eac2d4b89dc0a005bd +Subproject commit 31ce17e12e991bd841270b99f461641093f42564 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3e19eea95..f654255fa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ protocol-connection = "3.0.0.Beta1-20230908.171156-105" raknet = "1.0.0.CR1-20230703.195238-9" blockstateupdater="1.20.30-20230918.203831-4" mcauthlib = "d9d773e" -mcprotocollib = "1.20-2-20230827.192136-1" +mcprotocollib = "1.20.2-1-20230926.224810-3" adventure = "4.14.0" adventure-platform = "4.3.0" junit = "5.9.2" From 5d30019bc78a860df8e9bc1cd31d3650a411c1eb Mon Sep 17 00:00:00 2001 From: Hasan <52300558+hasankayra04@users.noreply.github.com> Date: Sat, 30 Sep 2023 22:46:21 +0300 Subject: [PATCH 04/23] Change supported java version - Update README.md (#4163) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d78386687..6c26f3744 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here! -### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.31 and Minecraft Java 1.20/1.20.1. +### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.31 and Minecraft Java 1.20.2 ## Setting Up Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser. From 1d75d084a787e7c3577ab144447f1e3c9d38084c Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 30 Sep 2023 22:18:57 +0100 Subject: [PATCH 05/23] Force loading help-text using utf-8 to fix encoding errors (#4165) --- core/src/main/java/org/geysermc/geyser/GeyserMain.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/GeyserMain.java b/core/src/main/java/org/geysermc/geyser/GeyserMain.java index 8726c1b24..4e60a79b8 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserMain.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserMain.java @@ -28,6 +28,7 @@ package org.geysermc.geyser; import javax.swing.*; import java.io.InputStream; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.Scanner; @@ -60,7 +61,7 @@ public class GeyserMain { helpStream = GeyserMain.class.getClassLoader().getResourceAsStream("languages/run-help/en_US.txt"); } - Scanner help = new Scanner(helpStream).useDelimiter("\\Z"); + Scanner help = new Scanner(helpStream, StandardCharsets.UTF_8).useDelimiter("\\Z"); String line = ""; while (help.hasNext()) { line = help.next(); From 34ff8c121740a57665765bbcee6e643ebfd89a1d Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 1 Oct 2023 07:17:53 +0200 Subject: [PATCH 06/23] Allow extensions to load other extension's classes, and store extensions by IDs instead of name (#3946) - the extensionmanagers `extension` method now takes in a extension id instead of name - extension folders are now created using extension id's - Extensions can load classes from other extensions now - Added warning about external class loading - Wherever applicable: store extensions internally by id instead of name --- .../api/extension/ExtensionManager.java | 8 ++--- .../platform/spigot/GeyserSpigotPlugin.java | 2 +- .../extension/GeyserExtensionClassLoader.java | 36 +++++++++++++------ .../extension/GeyserExtensionLoader.java | 29 ++++++++++----- .../extension/GeyserExtensionManager.java | 10 +++--- 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java b/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java index a9d0d7376..5226221df 100644 --- a/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java +++ b/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionManager.java @@ -36,13 +36,13 @@ import java.util.Collection; public abstract class ExtensionManager { /** - * Gets an extension with the given name. + * Gets an extension by the given ID. * - * @param name the name of the extension - * @return an extension with the given name + * @param id the ID of the extension + * @return an extension with the given ID */ @Nullable - public abstract Extension extension(@NonNull String name); + public abstract Extension extension(@NonNull String id); /** * Enables the given {@link Extension}. diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java index b932962a0..cfb6ff5ae 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java @@ -194,7 +194,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { commandMap.register(extension.description().id(), "geyserext", pluginCommand); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { - this.geyserLogger.error("Failed to construct PluginCommand for extension " + extension.description().name(), ex); + this.geyserLogger.error("Failed to construct PluginCommand for extension " + extension.name(), ex); } } } diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionClassLoader.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionClassLoader.java index 30d6ac856..dca11dfcd 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionClassLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionClassLoader.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.extension; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.extension.ExtensionDescription; import org.geysermc.geyser.api.extension.exception.InvalidExtensionException; @@ -39,14 +40,17 @@ import java.nio.file.Path; public class GeyserExtensionClassLoader extends URLClassLoader { private final GeyserExtensionLoader loader; + private final ExtensionDescription description; private final Object2ObjectMap> classes = new Object2ObjectOpenHashMap<>(); + private boolean warnedForExternalClassAccess; - public GeyserExtensionClassLoader(GeyserExtensionLoader loader, ClassLoader parent, Path path) throws MalformedURLException { + public GeyserExtensionClassLoader(GeyserExtensionLoader loader, ClassLoader parent, Path path, ExtensionDescription description) throws MalformedURLException { super(new URL[] { path.toUri().toURL() }, parent); this.loader = loader; + this.description = description; } - public Extension load(ExtensionDescription description) throws InvalidExtensionException { + public Extension load() throws InvalidExtensionException { try { Class jarClass; try { @@ -76,22 +80,32 @@ public class GeyserExtensionClassLoader extends URLClassLoader { } protected Class findClass(String name, boolean checkGlobal) throws ClassNotFoundException { - if (name.startsWith("org.geysermc.geyser.") || name.startsWith("net.minecraft.")) { - throw new ClassNotFoundException(name); - } - Class result = this.classes.get(name); if (result == null) { - result = super.findClass(name); - if (result == null && checkGlobal) { - result = this.loader.classByName(name); + // Try to find class in current extension + try { + result = super.findClass(name); + } catch (ClassNotFoundException ignored) { + // If class is not found in current extension, check in the global class loader + // This is used for classes that are not in the extension, but are in other extensions + if (checkGlobal) { + if (!warnedForExternalClassAccess) { + GeyserImpl.getInstance().getLogger().warning("Extension " + this.description.name() + " loads class " + name + " from an external source. " + + "This can change at any time and break the extension, additionally to potentially causing unexpected behaviour!"); + warnedForExternalClassAccess = true; + } + result = this.loader.classByName(name); + } } if (result != null) { + // If class is found, cache it this.loader.setClass(name, result); + this.classes.put(name, result); + } else { + // If class is not found, throw exception + throw new ClassNotFoundException(name); } - - this.classes.put(name, result); } return result; } diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java index 7e998e413..dac5ee802 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java @@ -66,26 +66,38 @@ public class GeyserExtensionLoader extends ExtensionLoader { } Path parentFile = path.getParent(); - Path dataFolder = parentFile.resolve(description.name()); + + // Extension folders used to be created by name; this changes them to the ID + Path oldDataFolder = parentFile.resolve(description.name()); + Path dataFolder = parentFile.resolve(description.id()); + + if (Files.exists(oldDataFolder) && Files.isDirectory(oldDataFolder) && !oldDataFolder.equals(dataFolder)) { + try { + Files.move(oldDataFolder, dataFolder, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + throw new InvalidExtensionException("Failed to move data folder for extension " + description.name(), e); + } + } + if (Files.exists(dataFolder) && !Files.isDirectory(dataFolder)) { throw new InvalidExtensionException("The folder " + dataFolder + " is not a directory and is the data folder for the extension " + description.name() + "!"); } final GeyserExtensionClassLoader loader; try { - loader = new GeyserExtensionClassLoader(this, getClass().getClassLoader(), path); + loader = new GeyserExtensionClassLoader(this, getClass().getClassLoader(), path, description); } catch (Throwable e) { throw new InvalidExtensionException(e); } - this.classLoaders.put(description.name(), loader); + this.classLoaders.put(description.id(), loader); - final Extension extension = loader.load(description); + final Extension extension = loader.load(); return this.setup(extension, description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), extension)); } private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder, ExtensionEventBus eventBus) { - GeyserExtensionLogger logger = new GeyserExtensionLogger(GeyserImpl.getInstance().getLogger(), description.name()); + GeyserExtensionLogger logger = new GeyserExtensionLogger(GeyserImpl.getInstance().getLogger(), description.id()); return new GeyserExtensionContainer(extension, dataFolder, description, this, logger, eventBus); } @@ -152,7 +164,8 @@ public class GeyserExtensionLoader extends ExtensionLoader { GeyserExtensionDescription description = this.extensionDescription(path); String name = description.name(); - if (extensions.containsKey(name) || extensionManager.extension(name) != null) { + String id = description.id(); + if (extensions.containsKey(id) || extensionManager.extension(id) != null) { GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.extensions.load.duplicate", name, path.toString())); return; } @@ -169,8 +182,8 @@ public class GeyserExtensionLoader extends ExtensionLoader { return; } - extensions.put(name, path); - loadedExtensions.put(name, this.loadExtension(path, description)); + extensions.put(id, path); + loadedExtensions.put(id, this.loadExtension(path, description)); } catch (Exception e) { GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e); } diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java index 5dd924301..3c41c4329 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java @@ -52,8 +52,8 @@ public class GeyserExtensionManager extends ExtensionManager { } @Override - public Extension extension(@NonNull String name) { - return this.extensions.get(name); + public Extension extension(@NonNull String id) { + return this.extensions.get(id); } @Override @@ -83,7 +83,7 @@ public class GeyserExtensionManager extends ExtensionManager { if (!extension.isEnabled()) { extension.setEnabled(true); GeyserImpl.getInstance().eventBus().register(extension, extension); - GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.enable.success", extension.description().name())); + GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.enable.success", extension.name())); } } @@ -98,7 +98,7 @@ public class GeyserExtensionManager extends ExtensionManager { GeyserImpl.getInstance().eventBus().unregisterAll(extension); extension.setEnabled(false); - GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.disable.success", extension.description().name())); + GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.disable.success", extension.name())); } } @@ -121,6 +121,6 @@ public class GeyserExtensionManager extends ExtensionManager { @Override public void register(@NonNull Extension extension) { - this.extensions.put(extension.name(), extension); + this.extensions.put(extension.description().id(), extension); } } From 71bef08ef6e6edfcc6242076ebdcf1091fc8f6d9 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:41:04 -0400 Subject: [PATCH 07/23] Fix CustomQueryTranslator (#4169) --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f654255fa..d21bf5e33 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ protocol-connection = "3.0.0.Beta1-20230908.171156-105" raknet = "1.0.0.CR1-20230703.195238-9" blockstateupdater="1.20.30-20230918.203831-4" mcauthlib = "d9d773e" -mcprotocollib = "1.20.2-1-20230926.224810-3" +mcprotocollib = "1.20.2-1-20231001.173210-4" adventure = "4.14.0" adventure-platform = "4.3.0" junit = "5.9.2" From be5b437e5f9bfdefe5e0a5440ac5a178871ce31a Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:06:57 -0400 Subject: [PATCH 08/23] Add spigot world adapter for 1.20.2 (#4170) --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d21bf5e33..85f42ea0d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,7 +24,7 @@ jline = "3.21.0" terminalconsoleappender = "1.2.0" folia = "1.19.4-R0.1-SNAPSHOT" viaversion = "4.0.0" -adapters = "1.9-SNAPSHOT" +adapters = "1.10-SNAPSHOT" commodore = "2.2" bungeecord = "a7c6ede" velocity = "3.1.1" From 7d489c7354b4888b02b5a49c651a9f45249ba170 Mon Sep 17 00:00:00 2001 From: petersv5 <88165842+petersv5@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:15:44 +0200 Subject: [PATCH 09/23] Close threads at server shutdown (#4029) Co-authored-by: Peter Svensson Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com> --- .../network/GeyserServerInitializer.java | 6 ++- .../geyser/network/netty/GeyserServer.java | 38 +++++++++++++++---- .../geysermc/geyser/skin/SkinProvider.java | 28 ++++++++++---- gradle/libs.versions.toml | 2 +- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java b/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java index 35d2d7f33..f19a46e6a 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java +++ b/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java @@ -47,6 +47,10 @@ public class GeyserServerInitializer extends BedrockServerInitializer { this.geyser = geyser; } + public DefaultEventLoopGroup getEventLoopGroup() { + return eventLoopGroup; + } + @Override public void initSession(@Nonnull BedrockServerSession bedrockServerSession) { try { @@ -72,4 +76,4 @@ public class GeyserServerInitializer extends BedrockServerInitializer { protected BedrockPeer createPeer(Channel channel) { return new GeyserBedrockPeer(channel, this::createSession); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java b/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java index df9e1e9d9..6fbb29157 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java @@ -39,6 +39,7 @@ import io.netty.channel.kqueue.KQueueEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel; +import io.netty.util.concurrent.Future; import lombok.Getter; import net.jodah.expiringmap.ExpirationPolicy; import net.jodah.expiringmap.ExpiringMap; @@ -58,6 +59,7 @@ import org.geysermc.geyser.network.netty.handler.RakPingHandler; import org.geysermc.geyser.network.netty.proxy.ProxyServerHandler; import org.geysermc.geyser.ping.GeyserPingInfo; import org.geysermc.geyser.ping.IGeyserPingPassthrough; +import org.geysermc.geyser.skin.SkinProvider; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.translator.text.MessageTranslator; @@ -83,14 +85,21 @@ public final class GeyserServer { private static final Transport TRANSPORT = compatibleTransport(); + /** + * See {@link EventLoopGroup#shutdownGracefully(long, long, TimeUnit)} + */ + private static final int SHUTDOWN_QUIET_PERIOD_MS = 100; + private static final int SHUTDOWN_TIMEOUT_MS = 500; + private final GeyserImpl geyser; - private final EventLoopGroup group; + private EventLoopGroup group; private final ServerBootstrap bootstrap; + private EventLoopGroup playerGroup; @Getter private final ExpiringMap proxiedAddresses; - private ChannelFuture future; + private ChannelFuture bootstrapFuture; public GeyserServer(GeyserImpl geyser, int threadCount) { this.geyser = geyser; @@ -109,7 +118,7 @@ public final class GeyserServer { public CompletableFuture bind(InetSocketAddress address) { CompletableFuture future = new CompletableFuture<>(); - this.future = this.bootstrap.bind(address).addListener(bindResult -> { + this.bootstrapFuture = this.bootstrap.bind(address).addListener(bindResult -> { if (bindResult.cause() != null) { future.completeExceptionally(bindResult.cause()); return; @@ -117,7 +126,7 @@ public final class GeyserServer { future.complete(null); }); - Channel channel = this.future.channel(); + Channel channel = this.bootstrapFuture.channel(); // Add our ping handler channel.pipeline() @@ -132,8 +141,19 @@ public final class GeyserServer { } public void shutdown() { - this.group.shutdownGracefully(); - this.future.channel().closeFuture().syncUninterruptibly(); + try { + Future future1 = this.group.shutdownGracefully(SHUTDOWN_QUIET_PERIOD_MS, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS); + this.group = null; + Future future2 = this.playerGroup.shutdownGracefully(SHUTDOWN_QUIET_PERIOD_MS, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS); + this.playerGroup = null; + future1.sync(); + future2.sync(); + + SkinProvider.shutdown(); + } catch (InterruptedException e) { + GeyserImpl.getInstance().getLogger().severe("Exception in shutdown process", e); + } + this.bootstrapFuture.channel().closeFuture().syncUninterruptibly(); } private ServerBootstrap createBootstrap(EventLoopGroup group) { @@ -149,11 +169,13 @@ public final class GeyserServer { } } + GeyserServerInitializer serverInitializer = new GeyserServerInitializer(this.geyser); + playerGroup = serverInitializer.getEventLoopGroup(); return new ServerBootstrap() .channelFactory(RakChannelFactory.server(TRANSPORT.datagramChannel())) .group(group) .option(RakChannelOption.RAK_HANDLE_PING, true) - .childHandler(new GeyserServerInitializer(this.geyser)); + .childHandler(serverInitializer); } public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) { @@ -217,7 +239,7 @@ public final class GeyserServer { .version(GameProtocol.DEFAULT_BEDROCK_CODEC.getMinecraftVersion()) // Required to not be empty as of 1.16.210.59. Can only contain . and numbers. .ipv4Port(this.geyser.getConfig().getBedrock().port()) .ipv6Port(this.geyser.getConfig().getBedrock().port()) - .serverId(future.channel().config().getOption(RakChannelOption.RAK_GUID)); + .serverId(bootstrapFuture.channel().config().getOption(RakChannelOption.RAK_GUID)); if (config.isPassthroughMotd() && pingInfo != null && pingInfo.getDescription() != null) { String[] motd = MessageTranslator.convertMessageLenient(pingInfo.getDescription()).split("\n"); diff --git a/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java b/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java index 41f750990..f491473be 100644 --- a/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java +++ b/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java @@ -58,7 +58,7 @@ import java.util.function.Predicate; public class SkinProvider { private static final boolean ALLOW_THIRD_PARTY_CAPES = GeyserImpl.getInstance().getConfig().isAllowThirdPartyCapes(); - static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(ALLOW_THIRD_PARTY_CAPES ? 21 : 14); + static ExecutorService EXECUTOR_SERVICE; static final Skin EMPTY_SKIN; static final Cape EMPTY_CAPE = new Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, -1, true); @@ -133,6 +133,20 @@ public class SkinProvider { WEARING_CUSTOM_SKULL_SLIM = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.wearingCustomSkullSlim\"}}", wearingCustomSkullSlim, false); } + private static ExecutorService getExecutorService() { + if (EXECUTOR_SERVICE == null) { + EXECUTOR_SERVICE = Executors.newFixedThreadPool(ALLOW_THIRD_PARTY_CAPES ? 21 : 14); + } + return EXECUTOR_SERVICE; + } + + public static void shutdown() { + if (EXECUTOR_SERVICE != null) { + EXECUTOR_SERVICE.shutdown(); + EXECUTOR_SERVICE = null; + } + } + public static void registerCacheImageTask(GeyserImpl geyser) { // Schedule Daily Image Expiry if we are caching them if (geyser.getConfig().getCacheImages() > 0) { @@ -302,7 +316,7 @@ public class SkinProvider { GeyserImpl.getInstance().getLogger().debug("Took " + (System.currentTimeMillis() - time) + "ms for " + playerId); return skinAndCape; - }, EXECUTOR_SERVICE); + }, getExecutorService()); } static CompletableFuture requestSkin(UUID playerId, String textureUrl, boolean newThread) { @@ -320,7 +334,7 @@ public class SkinProvider { CompletableFuture future; if (newThread) { - future = CompletableFuture.supplyAsync(() -> supplySkin(playerId, textureUrl), EXECUTOR_SERVICE) + future = CompletableFuture.supplyAsync(() -> supplySkin(playerId, textureUrl), getExecutorService()) .whenCompleteAsync((skin, throwable) -> { skin.updated = true; CACHED_JAVA_SKINS.put(textureUrl, skin); @@ -349,7 +363,7 @@ public class SkinProvider { CompletableFuture future; if (newThread) { - future = CompletableFuture.supplyAsync(() -> supplyCape(capeUrl, provider), EXECUTOR_SERVICE) + future = CompletableFuture.supplyAsync(() -> supplyCape(capeUrl, provider), getExecutorService()) .whenCompleteAsync((cape, throwable) -> { CACHED_JAVA_CAPES.put(capeUrl, cape); requestedCapes.remove(capeUrl); @@ -388,7 +402,7 @@ public class SkinProvider { CompletableFuture future; if (newThread) { - future = CompletableFuture.supplyAsync(() -> supplyEars(skin, earsUrl), EXECUTOR_SERVICE) + future = CompletableFuture.supplyAsync(() -> supplyEars(skin, earsUrl), getExecutorService()) .whenCompleteAsync((outSkin, throwable) -> { }); } else { Skin ears = supplyEars(skin, earsUrl); // blocking @@ -620,7 +634,7 @@ public class SkinProvider { } return null; } - }, EXECUTOR_SERVICE); + }, getExecutorService()); } /** @@ -646,7 +660,7 @@ public class SkinProvider { } return null; } - }, EXECUTOR_SERVICE).thenCompose(uuid -> { + }, getExecutorService()).thenCompose(uuid -> { if (uuid == null) { return CompletableFuture.completedFuture(null); } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 85f42ea0d..46106f490 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ protocol-connection = "3.0.0.Beta1-20230908.171156-105" raknet = "1.0.0.CR1-20230703.195238-9" blockstateupdater="1.20.30-20230918.203831-4" mcauthlib = "d9d773e" -mcprotocollib = "1.20.2-1-20231001.173210-4" +mcprotocollib = "1.20.2-1-20231001.201013-5" adventure = "4.14.0" adventure-platform = "4.3.0" junit = "5.9.2" From 7983448ce637656db1fca95eb65344a8c6d90de3 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 3 Oct 2023 01:12:54 +0200 Subject: [PATCH 10/23] Remove Mojang account sign-in option (#4147) * Remove Mojang auth * Yeet Connector wrapper, ensure that empty config arrays (e.g. saved user logins) are empty lists instead of null to avoid NPE exceptions --- .../geysermc/connector/GeyserConnector.java | 91 ---------- .../network/session/GeyserSession.java | 161 ------------------ .../network/session/auth/AuthData.java | 55 ------ .../java/org/geysermc/geyser/GeyserImpl.java | 8 +- .../configuration/GeyserConfiguration.java | 18 -- .../GeyserJacksonConfiguration.java | 20 --- .../geyser/network/UpstreamPacketHandler.java | 15 +- .../geyser/session/GeyserSession.java | 77 +-------- .../org/geysermc/geyser/util/FileUtils.java | 5 +- .../geyser/util/LoginEncryptionUtils.java | 25 --- 10 files changed, 13 insertions(+), 462 deletions(-) delete mode 100644 core/src/main/java/org/geysermc/connector/GeyserConnector.java delete mode 100644 core/src/main/java/org/geysermc/connector/network/session/GeyserSession.java delete mode 100644 core/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java diff --git a/core/src/main/java/org/geysermc/connector/GeyserConnector.java b/core/src/main/java/org/geysermc/connector/GeyserConnector.java deleted file mode 100644 index 381282a2a..000000000 --- a/core/src/main/java/org/geysermc/connector/GeyserConnector.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector; - -import org.geysermc.api.Geyser; -import org.geysermc.geyser.api.util.PlatformType; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.geyser.GeyserImpl; - -import java.util.UUID; - -/** - * Deprecated, please use {@link Geyser} or {@link GeyserImpl}. - * - * @deprecated legacy code - */ -@Deprecated -public class GeyserConnector { - public static final String NAME = GeyserImpl.NAME; - public static final String GIT_VERSION = GeyserImpl.GIT_VERSION; // A fallback for running in IDEs - public static final String VERSION = GeyserImpl.VERSION; // A fallback for running in IDEs - - public static final String OAUTH_CLIENT_ID = GeyserImpl.OAUTH_CLIENT_ID; - - private static final GeyserConnector INSTANCE = new GeyserConnector(); - - public static GeyserConnector getInstance() { - return INSTANCE; - } - - public boolean isShuttingDown() { - return GeyserImpl.getInstance().isShuttingDown(); - } - - public PlatformType getPlatformType() { - return GeyserImpl.getInstance().getPlatformType(); - } - - public void shutdown() { - GeyserImpl.getInstance().shutdown(); - } - - public void reload() { - GeyserImpl.getInstance().reload(); - } - - public GeyserSession getPlayerByXuid(String xuid) { - org.geysermc.geyser.session.GeyserSession session = GeyserImpl.getInstance().connectionByXuid(xuid); - if (session != null) { - return new GeyserSession(session); - } else { - return null; - } - } - - public GeyserSession getPlayerByUuid(UUID uuid) { - org.geysermc.geyser.session.GeyserSession session = GeyserImpl.getInstance().connectionByUuid(uuid); - if (session != null) { - return new GeyserSession(session); - } else { - return null; - } - } - - public boolean isProductionEnvironment() { - return GeyserImpl.getInstance().isProductionEnvironment(); - } -} diff --git a/core/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/core/src/main/java/org/geysermc/connector/network/session/GeyserSession.java deleted file mode 100644 index 6298a41f6..000000000 --- a/core/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.network.session; - -import com.github.steveice10.packetlib.packet.Packet; -import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; -import org.geysermc.connector.network.session.auth.AuthData; - -/** - * Deprecated, legacy code. Serves as a wrapper around - * the class used now. - * - * @deprecated legacy code - */ -@Deprecated -public class GeyserSession { - private final org.geysermc.geyser.session.GeyserSession handle; - - public GeyserSession(org.geysermc.geyser.session.GeyserSession handle) { - this.handle = handle; - } - - public AuthData getAuthData() { - return new AuthData(this.handle.getAuthData()); - } - - public boolean isMicrosoftAccount() { - return this.handle.isMicrosoftAccount(); - } - - public boolean isClosed() { - return this.handle.isClosed(); - } - - public String getRemoteAddress() { - return this.handle.remoteServer().address(); - } - - public int getRemotePort() { - return this.handle.remoteServer().port(); - } - - public int getRenderDistance() { - return this.handle.getServerRenderDistance(); - } - - public boolean isSentSpawnPacket() { - return this.handle.isSentSpawnPacket(); - } - - public boolean isLoggedIn() { - return this.handle.isLoggedIn(); - } - - public boolean isLoggingIn() { - return this.handle.isLoggingIn(); - } - - public boolean isSpawned() { - return this.handle.isSpawned(); - } - - public boolean isInteracting() { - return this.handle.isInteracting(); - } - - public boolean isCanFly() { - return this.handle.isCanFly(); - } - - public boolean isFlying() { - return this.handle.isFlying(); - } - - public void connect() { - this.handle.connect(); - } - - public void login() { - throw new UnsupportedOperationException(); - } - - public void authenticate(String username) { - this.handle.authenticate(username); - } - - public void authenticate(String username, String password) { - this.handle.authenticate(username, password); - } - - public void authenticateWithMicrosoftCode() { - this.handle.authenticateWithMicrosoftCode(); - } - - public void disconnect(String reason) { - this.handle.disconnect(reason); - } - - public void close() { - throw new UnsupportedOperationException(); - } - - public void executeInEventLoop(Runnable runnable) { - this.handle.executeInEventLoop(runnable); - } - - public String getName() { - return this.handle.bedrockUsername(); - } - - public boolean isConsole() { - return this.handle.isConsole(); - } - - public String getLocale() { - return this.handle.locale(); - } - - public void sendUpstreamPacket(BedrockPacket packet) { - this.handle.sendUpstreamPacket(packet); - } - - public void sendUpstreamPacketImmediately(BedrockPacket packet) { - this.handle.sendUpstreamPacketImmediately(packet); - } - - public void sendDownstreamPacket(Packet packet) { - this.handle.sendDownstreamPacket(packet); - } - - public boolean hasPermission(String permission) { - return this.handle.hasPermission(permission); - } - - public void sendAdventureSettings() { - this.handle.sendAdventureSettings(); - } -} diff --git a/core/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java b/core/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java deleted file mode 100644 index cca7aa48c..000000000 --- a/core/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.network.session.auth; - -import java.util.UUID; - -/** - * Deprecated, legacy code. Serves as a wrapper around - * the class used now. - * - * @deprecated legacy code - */ -@Deprecated -public class AuthData { - private final org.geysermc.geyser.session.auth.AuthData handle; - - public AuthData(org.geysermc.geyser.session.auth.AuthData handle) { - this.handle = handle; - } - - public String getName() { - return this.handle.name(); - } - - public UUID getUUID() { - return this.handle.uuid(); - } - - public String getXboxUUID() { - return this.handle.xuid(); - } -} diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 4a5f16bfa..185ab7c2a 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -43,7 +43,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.api.Geyser; -import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.cumulus.form.Form; import org.geysermc.cumulus.form.util.FormBuilder; import org.geysermc.erosion.packet.Packets; @@ -61,6 +60,7 @@ import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent; import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.api.network.BedrockListener; import org.geysermc.geyser.api.network.RemoteServer; +import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.entity.EntityDefinitions; @@ -478,12 +478,6 @@ public class GeyserImpl implements GeyserApi { } if (config.getRemote().authType() == AuthType.ONLINE) { - if (config.getUserAuths() != null && !config.getUserAuths().isEmpty()) { - getLogger().warning("The 'userAuths' config section is now deprecated, and will be removed in the near future! " + - "Please migrate to the new 'saved-user-logins' config option: " + - "https://wiki.geysermc.org/geyser/understanding-the-config/"); - } - // May be written/read to on multiple threads from each GeyserSession as well as writing the config savedRefreshTokens = new ConcurrentHashMap<>(); diff --git a/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java b/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java index 222af341b..e36ec819b 100644 --- a/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java +++ b/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java @@ -36,7 +36,6 @@ import org.geysermc.geyser.text.GeyserLocale; import java.nio.file.Path; import java.util.List; -import java.util.Map; public interface GeyserConfiguration { /** @@ -53,9 +52,6 @@ public interface GeyserConfiguration { List getSavedUserLogins(); - @Deprecated - Map getUserAuths(); - boolean isCommandSuggestions(); @JsonIgnore @@ -147,8 +143,6 @@ public interface GeyserConfiguration { void setPort(int port); - boolean isPasswordAuthentication(); - boolean isUseProxyProtocol(); boolean isForwardHost(); @@ -164,18 +158,6 @@ public interface GeyserConfiguration { void setAuthType(AuthType authType); } - interface IUserAuthenticationInfo { - String getEmail(); - - String getPassword(); - - /** - * Will be removed after Microsoft accounts are fully migrated - */ - @Deprecated - boolean isMicrosoftAccount(); - } - interface IMetricsInfo { boolean isEnabled(); diff --git a/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java b/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java index 64ab09954..268304844 100644 --- a/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java +++ b/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java @@ -44,7 +44,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; @@ -67,8 +66,6 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration public abstract Path getFloodgateKeyPath(); - private Map userAuths; - @JsonProperty("command-suggestions") private boolean commandSuggestions = true; @@ -275,10 +272,6 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration return false; } - @Getter - @JsonProperty("allow-password-authentication") - private boolean passwordAuthentication = true; - @Getter @JsonProperty("use-proxy-protocol") private boolean useProxyProtocol = false; @@ -288,19 +281,6 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration private boolean forwardHost = false; } - @Getter - @JsonIgnoreProperties(ignoreUnknown = true) // DO NOT REMOVE THIS! Otherwise, after we remove microsoft-account configs will not load - public static class UserAuthenticationInfo implements IUserAuthenticationInfo { - @AsteriskSerializer.Asterisk() - private String email; - - @AsteriskSerializer.Asterisk() - private String password; - - @JsonProperty("microsoft-account") - private boolean microsoftAccount = false; - } - @Getter @JsonIgnoreProperties(ignoreUnknown = true) public static class MetricsInfo implements IMetricsInfo { diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 6b43422e5..361aaffb9 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -52,7 +52,6 @@ import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.api.pack.PackCodec; import org.geysermc.geyser.api.pack.ResourcePack; import org.geysermc.geyser.api.pack.ResourcePackManifest; -import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.event.type.SessionLoadResourcePacksEventImpl; import org.geysermc.geyser.pack.GeyserResourcePack; import org.geysermc.geyser.registry.BlockRegistries; @@ -257,21 +256,9 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { return true; } } - if (geyser.getConfig().getUserAuths() != null) { - GeyserConfiguration.IUserAuthenticationInfo info = geyser.getConfig().getUserAuths().get(bedrockUsername); - - if (info != null) { - geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.auth.stored_credentials", session.getAuthData().name())); - session.setMicrosoftAccount(info.isMicrosoftAccount()); - session.authenticate(info.getEmail(), info.getPassword()); - return true; - } - } PendingMicrosoftAuthentication.AuthenticationTask task = geyser.getPendingMicrosoftAuthentication().getTask(session.getAuthData().xuid()); if (task != null) { - if (task.getAuthentication().isDone() && session.onMicrosoftLoginComplete(task)) { - return true; - } + return task.getAuthentication().isDone() && session.onMicrosoftLoginComplete(task); } return false; diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 5c9725fae..673ff5f37 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -26,10 +26,7 @@ package org.geysermc.geyser.session; import com.github.steveice10.mc.auth.data.GameProfile; -import com.github.steveice10.mc.auth.exception.request.InvalidCredentialsException; import com.github.steveice10.mc.auth.exception.request.RequestException; -import com.github.steveice10.mc.auth.service.AuthenticationService; -import com.github.steveice10.mc.auth.service.MojangAuthenticationService; import com.github.steveice10.mc.auth.service.MsaAuthenticationService; import com.github.steveice10.mc.protocol.MinecraftConstants; import com.github.steveice10.mc.protocol.MinecraftProtocol; @@ -190,10 +187,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { @Setter private RemoteServer remoteServer; - @Deprecated - @Setter - private boolean microsoftAccount; - private final SessionPlayerEntity playerEntity; private final AdvancementsCache advancementsCache; @@ -701,76 +694,20 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } public void authenticate(String username) { - authenticate(username, ""); - } - - public void authenticate(String username, String password) { if (loggedIn) { geyser.getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.auth.already_loggedin", username)); return; } loggingIn = true; + // Always replace spaces with underscores to avoid illegal nicknames, e.g. with GeyserConnect + protocol = new MinecraftProtocol(username.replace(' ', '_')); - // Use a future to prevent timeouts as all the authentication is handled sync - CompletableFuture.supplyAsync(() -> { - try { - if (password != null && !password.isEmpty()) { - AuthenticationService authenticationService; - if (microsoftAccount) { - authenticationService = new MsaAuthenticationService(GeyserImpl.OAUTH_CLIENT_ID); - } else { - authenticationService = new MojangAuthenticationService(); - } - authenticationService.setUsername(username); - authenticationService.setPassword(password); - authenticationService.login(); - - GameProfile profile = authenticationService.getSelectedProfile(); - if (profile == null) { - // Java account is offline - disconnect(GeyserLocale.getPlayerLocaleString("geyser.network.remote.invalid_account", clientData.getLanguageCode())); - return null; - } - - protocol = new MinecraftProtocol(profile, authenticationService.getAccessToken()); - } else { - // always replace spaces when using Floodgate, - // as usernames with spaces cause issues with Bungeecord's login cycle. - // However, this doesn't affect the final username as Floodgate is still in charge of that. - // So if you have (for example) replace spaces enabled on Floodgate the spaces will re-appear. - String validUsername = username; - if (this.remoteServer.authType() == AuthType.FLOODGATE) { - validUsername = username.replace(' ', '_'); - } - - protocol = new MinecraftProtocol(validUsername); - } - } catch (InvalidCredentialsException | IllegalArgumentException e) { - geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.auth.login.invalid", username)); - disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.invalid.kick", getClientData().getLanguageCode())); - } catch (RequestException ex) { - disconnect(ex.getMessage()); - } - return null; - }).whenComplete((aVoid, ex) -> { - if (ex != null) { - disconnect(ex.toString()); - } - if (this.closed) { - if (ex != null) { - geyser.getLogger().error("", ex); - } - // Client disconnected during the authentication attempt - return; - } - - try { - connectDownstream(); - } catch (Throwable t) { - t.printStackTrace(); - } - }); + try { + connectDownstream(); + } catch (Throwable t) { + t.printStackTrace(); + } } public void authenticateWithRefreshToken(String refreshToken) { diff --git a/core/src/main/java/org/geysermc/geyser/util/FileUtils.java b/core/src/main/java/org/geysermc/geyser/util/FileUtils.java index acd2278fc..99e8f8d7d 100644 --- a/core/src/main/java/org/geysermc/geyser/util/FileUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/FileUtils.java @@ -25,6 +25,8 @@ package org.geysermc.geyser.util; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.geysermc.geyser.GeyserBootstrap; @@ -53,7 +55,8 @@ public class FileUtils { * @throws IOException if the config could not be loaded */ public static T loadConfig(File src, Class valueType) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); + ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()) + .setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY)); return objectMapper.readValue(src, valueType); } diff --git a/core/src/main/java/org/geysermc/geyser/util/LoginEncryptionUtils.java b/core/src/main/java/org/geysermc/geyser/util/LoginEncryptionUtils.java index eabfe3a88..478a6ef96 100644 --- a/core/src/main/java/org/geysermc/geyser/util/LoginEncryptionUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/LoginEncryptionUtils.java @@ -34,14 +34,12 @@ import org.cloudburstmc.protocol.bedrock.packet.ServerToClientHandshakePacket; import org.cloudburstmc.protocol.bedrock.util.ChainValidationResult; import org.cloudburstmc.protocol.bedrock.util.ChainValidationResult.IdentityData; import org.cloudburstmc.protocol.bedrock.util.EncryptionUtils; -import org.geysermc.cumulus.form.CustomForm; import org.geysermc.cumulus.form.ModalForm; import org.geysermc.cumulus.form.SimpleForm; import org.geysermc.cumulus.response.SimpleFormResponse; import org.geysermc.cumulus.response.result.FormResponseResult; import org.geysermc.cumulus.response.result.ValidFormResponseResult; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.auth.AuthData; import org.geysermc.geyser.session.auth.BedrockClientData; @@ -137,26 +135,16 @@ public class LoginEncryptionUtils { // Set DoDaylightCycle to false so the time doesn't accelerate while we're here session.setDaylightCycle(false); - GeyserConfiguration config = session.getGeyser().getConfig(); - boolean isPasswordAuthEnabled = config.getRemote().isPasswordAuthentication(); - session.sendForm( SimpleForm.builder() .translator(GeyserLocale::getPlayerLocaleString, session.locale()) .title("geyser.auth.login.form.notice.title") .content("geyser.auth.login.form.notice.desc") - .optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled) .button("geyser.auth.login.form.notice.btn_login.microsoft") .button("geyser.auth.login.form.notice.btn_disconnect") .closedOrInvalidResultHandler(() -> buildAndShowLoginWindow(session)) .validResultHandler((response) -> { if (response.clickedButtonId() == 0) { - session.setMicrosoftAccount(false); - buildAndShowLoginDetailsWindow(session); - return; - } - - if (response.clickedButtonId() == 1) { session.authenticateWithMicrosoftCode(); return; } @@ -212,19 +200,6 @@ public class LoginEncryptionUtils { }; } - public static void buildAndShowLoginDetailsWindow(GeyserSession session) { - session.sendForm( - CustomForm.builder() - .translator(GeyserLocale::getPlayerLocaleString, session.locale()) - .title("geyser.auth.login.form.details.title") - .label("geyser.auth.login.form.details.desc") - .input("geyser.auth.login.form.details.email", "account@geysermc.org", "") - .input("geyser.auth.login.form.details.pass", "123456", "") - .invalidResultHandler(() -> buildAndShowLoginDetailsWindow(session)) - .closedResultHandler(() -> buildAndShowLoginWindow(session)) - .validResultHandler((response) -> session.authenticate(response.next(), response.next()))); - } - /** * Shows the code that a user must input into their browser */ From 3547fab228aefe556be948d8a4e650870a526cb5 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 3 Oct 2023 17:15:30 +0200 Subject: [PATCH 11/23] Fix: Bedrock clients timing out due to present Java resource packs (#4176) * fix: auto deny Java edition resource packs * 1.20.2 bump on Fabric * bump mcpl * Bump required min version in the fabric.mod.json file --- .../fabric/src/main/resources/fabric.mod.json | 2 +- .../JavaClientboundResourcePacksPacket.java | 43 +++++++++++++++++++ gradle/libs.versions.toml | 6 +-- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java diff --git a/bootstrap/fabric/src/main/resources/fabric.mod.json b/bootstrap/fabric/src/main/resources/fabric.mod.json index 4c442017a..f401e8f23 100644 --- a/bootstrap/fabric/src/main/resources/fabric.mod.json +++ b/bootstrap/fabric/src/main/resources/fabric.mod.json @@ -25,7 +25,7 @@ "depends": { "fabricloader": ">=0.14.21", "fabric": "*", - "minecraft": ">=1.20", + "minecraft": ">=1.20.2", "fabric-permissions-api-v0": "*" } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java new file mode 100644 index 000000000..017502280 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.translator.protocol.java; + +import com.github.steveice10.mc.protocol.data.game.ResourcePackStatus; +import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundResourcePackPacket; +import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundResourcePackPacket; +import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.translator.protocol.PacketTranslator; +import org.geysermc.geyser.translator.protocol.Translator; + +@Translator(packet = ClientboundResourcePackPacket.class) +public class JavaClientboundResourcePacksPacket extends PacketTranslator { + + @Override + public void translate(GeyserSession session, ClientboundResourcePackPacket packet) { + // We need to "answer" this to avoid timeout issues related to resource packs + session.sendDownstreamPacket(new ServerboundResourcePackPacket(ResourcePackStatus.DECLINED)); + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 46106f490..579f9de31 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ protocol-connection = "3.0.0.Beta1-20230908.171156-105" raknet = "1.0.0.CR1-20230703.195238-9" blockstateupdater="1.20.30-20230918.203831-4" mcauthlib = "d9d773e" -mcprotocollib = "1.20.2-1-20231001.201013-5" +mcprotocollib = "1.20.2-1-20231003.141424-6" adventure = "4.14.0" adventure-platform = "4.3.0" junit = "5.9.2" @@ -28,9 +28,9 @@ adapters = "1.10-SNAPSHOT" commodore = "2.2" bungeecord = "a7c6ede" velocity = "3.1.1" -fabric-minecraft = "1.20" +fabric-minecraft = "1.20.2" fabric-loader = "0.14.21" -fabric-api = "0.83.0+1.20" +fabric-api = "0.89.0+1.20.2" [libraries] base-api = { group = "org.geysermc.api", name = "base-api", version.ref = "base-api" } From 89d7225c544b7b512ce5aa8dd6b19cd5a4edd86c Mon Sep 17 00:00:00 2001 From: Kas-tle <26531652+Kas-tle@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:56:47 -0700 Subject: [PATCH 12/23] Fix API Registration of Custom Block Overrides (#4178) * Api reg vanilla blockstate overrides; Closes #4177 Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * proper case non static Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Clear queue when done --------- Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> --- .../CustomBlockRegistryPopulator.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java index c9ed51166..e4bf43b93 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java @@ -72,9 +72,9 @@ public class CustomBlockRegistryPopulator { private static Set CUSTOM_BLOCKS; private static Set CUSTOM_BLOCK_NAMES; - private static Int2ObjectMap BLOCK_STATE_OVERRIDES; private static Map CUSTOM_BLOCK_ITEM_OVERRIDES; private static Map NON_VANILLA_BLOCK_STATE_OVERRIDES; + private static Map BLOCK_STATE_OVERRIDES_QUEUE; /** * Initializes custom blocks defined by API @@ -82,9 +82,9 @@ public class CustomBlockRegistryPopulator { private static void populateBedrock() { CUSTOM_BLOCKS = new ObjectOpenHashSet<>(); CUSTOM_BLOCK_NAMES = new ObjectOpenHashSet<>(); - BLOCK_STATE_OVERRIDES = new Int2ObjectOpenHashMap<>(); CUSTOM_BLOCK_ITEM_OVERRIDES = new HashMap<>(); NON_VANILLA_BLOCK_STATE_OVERRIDES = new HashMap<>(); + BLOCK_STATE_OVERRIDES_QUEUE = new HashMap<>(); GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomBlocksEvent() { @Override @@ -103,18 +103,11 @@ public class CustomBlockRegistryPopulator { @Override public void registerOverride(@NonNull String javaIdentifier, @NonNull CustomBlockState customBlockState) { - int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(javaIdentifier, -1); - if (id == -1) { - throw new IllegalArgumentException("Unknown Java block state. Identifier: " + javaIdentifier); - } if (!CUSTOM_BLOCKS.contains(customBlockState.block())) { throw new IllegalArgumentException("Custom block is unregistered. Name: " + customBlockState.name()); } - CustomBlockState oldBlockState = BLOCK_STATE_OVERRIDES.put(id, customBlockState); - if (oldBlockState != null) { - GeyserImpl.getInstance().getLogger().debug("Duplicate block state override for Java Identifier: " + - javaIdentifier + " Old override: " + oldBlockState.name() + " New override: " + customBlockState.name()); - } + // We can't register these yet as we don't have the java block id registry populated + BLOCK_STATE_OVERRIDES_QUEUE.put(javaIdentifier, customBlockState); } @Override @@ -139,10 +132,28 @@ public class CustomBlockRegistryPopulator { * Registers all vanilla custom blocks and skulls defined by API and mappings */ private static void populateVanilla() { + Int2ObjectMap blockStateOverrides = new Int2ObjectOpenHashMap<>(); + for (CustomSkull customSkull : BlockRegistries.CUSTOM_SKULLS.get().values()) { CUSTOM_BLOCKS.add(customSkull.getCustomBlockData()); } + for(Map.Entry entry : BLOCK_STATE_OVERRIDES_QUEUE.entrySet()) { + int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(entry.getKey(), -1); + if (id == -1) { + GeyserImpl.getInstance().getLogger().warning("Custom block state override for Java Identifier: " + + entry.getKey() + " could not be registered as it is not a valid block state."); + continue; + } + + CustomBlockState oldBlockState = blockStateOverrides.put(id, entry.getValue()); + if (oldBlockState != null) { + GeyserImpl.getInstance().getLogger().warning("Duplicate block state override for Java Identifier: " + + entry.getKey() + " Old override: " + oldBlockState.name() + " New override: " + entry.getValue().name()); + } + } + BLOCK_STATE_OVERRIDES_QUEUE = null; + Map> extendedCollisionBoxes = new HashMap<>(); Map extendedCollisionBoxSet = new HashMap<>(); MappingsConfigReader mappingsConfigReader = new MappingsConfigReader(); @@ -153,7 +164,7 @@ public class CustomBlockRegistryPopulator { } block.states().forEach((javaIdentifier, customBlockState) -> { int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(javaIdentifier, -1); - BLOCK_STATE_OVERRIDES.put(id, customBlockState.state()); + blockStateOverrides.put(id, customBlockState.state()); BoxComponent extendedCollisionBox = customBlockState.extendedCollisionBox(); if (extendedCollisionBox != null) { CustomBlockData extendedCollisionBlock = extendedCollisionBoxSet.computeIfAbsent(extendedCollisionBox, box -> { @@ -167,9 +178,9 @@ public class CustomBlockRegistryPopulator { }); }); - BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.set(BLOCK_STATE_OVERRIDES); - if (BLOCK_STATE_OVERRIDES.size() != 0) { - GeyserImpl.getInstance().getLogger().info("Registered " + BLOCK_STATE_OVERRIDES.size() + " custom block overrides."); + BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.set(blockStateOverrides); + if (blockStateOverrides.size() != 0) { + GeyserImpl.getInstance().getLogger().info("Registered " + blockStateOverrides.size() + " custom block overrides."); } BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.set(CUSTOM_BLOCK_ITEM_OVERRIDES); From b340d4d1c432631c82a9e9c8571b1cf368bd97d9 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 5 Oct 2023 19:23:14 +0200 Subject: [PATCH 13/23] Add wiki/setup guides to the Geyser config (#4186) * Added links to Wiki and Setup guide to the config * implement suggestions --- core/src/main/resources/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 37e74c662..8e4db5e38 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -5,6 +5,10 @@ # # GitHub: https://github.com/GeyserMC/Geyser # Discord: https://discord.gg/geysermc +# Wiki: https://wiki.geysermc.org/ +# +# NOTICE: See https://wiki.geysermc.org/geyser/setup/ for the setup guide. Many video tutorials are outdated. +# In most cases, especially with server hosting providers, further hosting-specific configuration is required. # -------------------------------- bedrock: From 82541a5b379836cfad63807f6c511f0948c616a5 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 6 Oct 2023 15:50:01 +0200 Subject: [PATCH 14/23] Show only 1.20.2 as supported on Fabric (#4190) --- bootstrap/fabric/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/fabric/build.gradle.kts b/bootstrap/fabric/build.gradle.kts index c260703a5..e392a4ef9 100644 --- a/bootstrap/fabric/build.gradle.kts +++ b/bootstrap/fabric/build.gradle.kts @@ -118,7 +118,7 @@ modrinth { syncBodyFrom.set(rootProject.file("README.md").readText()) uploadFile.set(tasks.getByPath("remapModrinthJar")) - gameVersions.addAll("1.20", "1.20.1") + gameVersions.addAll("1.20.2") loaders.add("fabric") failSilently.set(true) From e8eccc64be3c1464048545a08797ecef85de1f0c Mon Sep 17 00:00:00 2001 From: Hasan <52300558+hasankayra04@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:18:48 +0300 Subject: [PATCH 15/23] Change Bedrock version - Update README.md (#4188) * Change Bedrock version - Update README.md * Update pullrequest.yml Don't ever ignore workflows from PRs based on files changed as this breaks pending approval --------- Co-authored-by: Kas-tle <26531652+Kas-tle@users.noreply.github.com> --- .github/workflows/pullrequest.yml | 9 --------- README.md | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 72f50ff97..797d68767 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -2,15 +2,6 @@ name: Build Pull Request on: pull_request: - paths-ignore: - - '.github/ISSUE_TEMPLATE/*.yml' - - '.idea/copyright/*.xml' - - '.gitignore' - - 'CONTRIBUTING.md' - - 'LICENSE' - - 'Jenkinsfile ' - - 'README.md' - - 'licenseheader.txt' jobs: build: diff --git a/README.md b/README.md index 6c26f3744..8a1f456c7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here! -### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.31 and Minecraft Java 1.20.2 +### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.32 and Minecraft Java 1.20.2 ## Setting Up Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser. From 30cca70e56c93833b1cd6c5bbe4acb84369be63e Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 7 Oct 2023 21:38:44 +0100 Subject: [PATCH 16/23] Tell the server we loaded the resource pack (#4183) * Tell the server we loaded the resource pack * Decline resource packs if they are not required --------- Co-authored-by: onebeastchris --- .../protocol/java/JavaClientboundResourcePacksPacket.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java index 017502280..cc2733076 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaClientboundResourcePacksPacket.java @@ -38,6 +38,11 @@ public class JavaClientboundResourcePacksPacket extends PacketTranslator Date: Sun, 8 Oct 2023 00:31:23 +0200 Subject: [PATCH 17/23] Fix: Implement 1.20.30 START_FLYING and STOP_FLYING cases (#4198) --- .../BedrockRequestAbilityTranslator.java | 1 + .../player/BedrockActionTranslator.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java index 00cd5e5fd..f31fdba80 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java @@ -42,6 +42,7 @@ public class BedrockRequestAbilityTranslator extends PacketTranslator Date: Sun, 8 Oct 2023 12:33:17 +0200 Subject: [PATCH 18/23] Fix: Beacon effects broken since 1.20.2 (#4199) Since 1.20.2, effect IDs start at 0, not 1. Bedrock of course doesn't respect that, so we need to subtract 1! --- .../geyser/translator/inventory/BeaconInventoryTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java index db0702e13..a0b6ebe9c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java @@ -119,7 +119,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator } private OptionalInt toJava(int effectChoice) { - return effectChoice == 0 ? OptionalInt.empty() : OptionalInt.of(effectChoice); + return effectChoice == 0 ? OptionalInt.empty() : OptionalInt.of(effectChoice - 1); } @Override From 3f0e366bacad887bf971f8c77ee7d5867b5ba4c3 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 8 Oct 2023 18:04:22 +0200 Subject: [PATCH 19/23] Fix: Don't rename extensions while the extension directory is being walked (#4197) --- .../extension/GeyserExtensionLoader.java | 71 +++++++++---------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java index dac5ee802..da0fbffda 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java @@ -43,9 +43,9 @@ import java.io.Reader; import java.nio.file.*; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.regex.Pattern; -import java.util.stream.Stream; @RequiredArgsConstructor public class GeyserExtensionLoader extends ExtensionLoader { @@ -148,47 +148,46 @@ public class GeyserExtensionLoader extends ExtensionLoader { Map loadedExtensions = new LinkedHashMap<>(); Pattern[] extensionFilters = this.extensionFilters(); - try (Stream entries = Files.walk(extensionsDirectory)) { - entries.forEach(path -> { - if (Files.isDirectory(path)) { + List extensionPaths = Files.walk(extensionsDirectory).toList(); + extensionPaths.forEach(path -> { + if (Files.isDirectory(path)) { + return; + } + + for (Pattern filter : extensionFilters) { + if (!filter.matcher(path.getFileName().toString()).matches()) { + return; + } + } + + try { + GeyserExtensionDescription description = this.extensionDescription(path); + + String name = description.name(); + String id = description.id(); + if (extensions.containsKey(id) || extensionManager.extension(id) != null) { + GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.extensions.load.duplicate", name, path.toString())); return; } - for (Pattern filter : extensionFilters) { - if (!filter.matcher(path.getFileName().toString()).matches()) { - return; - } + // Completely different API version + if (description.majorApiVersion() != Geyser.api().majorApiVersion()) { + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion())); + return; } - try { - GeyserExtensionDescription description = this.extensionDescription(path); - - String name = description.name(); - String id = description.id(); - if (extensions.containsKey(id) || extensionManager.extension(id) != null) { - GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.extensions.load.duplicate", name, path.toString())); - return; - } - - // Completely different API version - if (description.majorApiVersion() != Geyser.api().majorApiVersion()) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion())); - return; - } - - // If the extension requires new API features, being backwards compatible - if (description.minorApiVersion() > Geyser.api().minorApiVersion()) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion())); - return; - } - - extensions.put(id, path); - loadedExtensions.put(id, this.loadExtension(path, description)); - } catch (Exception e) { - GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e); + // If the extension requires new API features, being backwards compatible + if (description.minorApiVersion() > Geyser.api().minorApiVersion()) { + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion())); + return; } - }); - } + + extensions.put(id, path); + loadedExtensions.put(id, this.loadExtension(path, description)); + } catch (Exception e) { + GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e); + } + }); for (GeyserExtensionContainer container : loadedExtensions.values()) { this.extensionContainers.put(container.extension(), container); From e8048ede0856ea2f985b0a4122fd1683bf0d8968 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 8 Oct 2023 20:33:35 +0200 Subject: [PATCH 20/23] Fix: Skull rotation issues since 1.20.2 (#4200) --- .../org/geysermc/geyser/level/block/BlockStateValues.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/level/block/BlockStateValues.java b/core/src/main/java/org/geysermc/geyser/level/block/BlockStateValues.java index a686ba552..97ab18c6b 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/BlockStateValues.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/BlockStateValues.java @@ -173,8 +173,8 @@ public final class BlockStateValues { } if (javaId.contains("wall_skull") || javaId.contains("wall_head")) { - String direction = javaId.substring(javaId.lastIndexOf("facing=") + 7); - int rotation = switch (direction.substring(0, direction.length() - 1)) { + String direction = javaId.substring(javaId.lastIndexOf("facing=") + 7, javaId.lastIndexOf("powered=") - 1); + int rotation = switch (direction) { case "north" -> 180; case "west" -> 90; case "east" -> 270; From b17f4a46f484666407297c1bba300297acb7c6c4 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 9 Oct 2023 18:20:18 +0200 Subject: [PATCH 21/23] Update outdated proxy message to check for 1.20.2, remove floodgate 1.0 checks (#4204) --- .../geyser/platform/bungeecord/GeyserBungeePlugin.java | 7 +------ .../geyser/platform/velocity/GeyserVelocityPlugin.java | 10 ---------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java index 538e00a05..86f283329 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java @@ -77,7 +77,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { // Copied from ViaVersion. // https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43 try { - ProtocolConstants.class.getField("MINECRAFT_1_19_3"); + ProtocolConstants.class.getField("MINECRAFT_1_20_2"); } catch (NoSuchFieldException e) { getLogger().warning(" / \\"); getLogger().warning(" / \\"); @@ -111,11 +111,6 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { @Override public void onEnable() { - // Remove this in like a year - if (getProxy().getPluginManager().getPlugin("floodgate-bungee") != null) { - geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.outdated", "https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/")); - return; - } // Force-disable query if enabled, or else Geyser won't enable for (ListenerInfo info : getProxy().getConfig().getListeners()) { diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java index aac27fb65..dbbd30c41 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java @@ -114,16 +114,6 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); this.geyser = GeyserImpl.load(PlatformType.VELOCITY, this); - - // Remove this in like a year - try { - // Should only exist on 1.0 - Class.forName("org.geysermc.floodgate.FloodgateAPI"); - geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.outdated", - "https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/")); - return; - } catch (ClassNotFoundException ignored) { - } } private void postStartup() { From 00800acd6acf0339f78c48c36c95c5038139139f Mon Sep 17 00:00:00 2001 From: EpsilonZunsat <121496151+EpsilonZunsat@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:15:33 +0800 Subject: [PATCH 22/23] Fixed incorrect bedrock version of skin mirroring geometry (#4207) * fix geometry.humanoid.wearingCustomSkull.json's LeftLeg * fix geometry.humanoid.wearingCustomSkullSlim.json'LeftLeg --- .../bedrock/skin/geometry.humanoid.wearingCustomSkull.json | 7 +++---- .../skin/geometry.humanoid.wearingCustomSkullSlim.json | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkull.json b/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkull.json index b18d1205b..b3c5533da 100644 --- a/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkull.json +++ b/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkull.json @@ -145,10 +145,9 @@ { "origin": [ -0.1, 0.0, -2.0 ], "size": [ 4, 12, 4 ], - "uv": [ 0, 16 ] + "uv": [ 16, 48 ] } - ], - "mirror": true + ] }, { @@ -219,4 +218,4 @@ } } ] -} \ No newline at end of file +} diff --git a/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkullSlim.json b/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkullSlim.json index 3855c92ec..94559e3f7 100644 --- a/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkullSlim.json +++ b/core/src/main/resources/bedrock/skin/geometry.humanoid.wearingCustomSkullSlim.json @@ -145,10 +145,9 @@ { "origin": [ -0.1, 0.0, -2.0 ], "size": [ 4, 12, 4 ], - "uv": [ 0, 16 ] + "uv": [ 16, 48 ] } - ], - "mirror": true + ] }, { @@ -219,4 +218,4 @@ } } ] -} \ No newline at end of file +} From 3fa35b2cb94b628aaaa229742002eacfb0a42bad Mon Sep 17 00:00:00 2001 From: Kas-tle <26531652+Kas-tle@users.noreply.github.com> Date: Thu, 12 Oct 2023 06:02:57 -0700 Subject: [PATCH 23/23] Restrict game packets to state; Closes #4191 (#4210) Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> --- .../command/defaults/StatisticsCommand.java | 2 +- .../geyser/entity/type/InteractionEntity.java | 2 +- .../geyser/inventory/AnvilContainer.java | 4 +- .../geyser/inventory/click/ClickPlan.java | 2 +- .../updater/AnvilInventoryUpdater.java | 2 +- .../geyser/session/GeyserSession.java | 47 ++++++++++++++++--- .../session/cache/AdvancementsCache.java | 6 +-- .../geyser/session/cache/BookEditCache.java | 2 +- .../inventory/BeaconInventoryTranslator.java | 2 +- .../EnchantingInventoryTranslator.java | 2 +- .../inventory/LecternInventoryTranslator.java | 4 +- .../inventory/LoomInventoryTranslator.java | 2 +- .../MerchantInventoryTranslator.java | 2 +- .../inventory/PlayerInventoryTranslator.java | 6 +-- .../StonecutterInventoryTranslator.java | 2 +- .../bedrock/BedrockAnimateTranslator.java | 6 +-- .../BedrockBlockEntityDataTranslator.java | 4 +- .../BedrockCommandBlockUpdateTranslator.java | 4 +- .../BedrockContainerCloseTranslator.java | 2 +- ...BedrockInventoryTransactionTranslator.java | 28 +++++------ .../BedrockItemFrameDropItemTranslator.java | 2 +- .../BedrockLecternUpdateTranslator.java | 8 ++-- .../BedrockMobEquipmentTranslator.java | 4 +- .../BedrockMoveEntityAbsoluteTranslator.java | 2 +- .../bedrock/BedrockPlayerInputTranslator.java | 4 +- .../BedrockRequestAbilityTranslator.java | 2 +- .../bedrock/BedrockRespawnTranslator.java | 2 +- .../bedrock/BedrockShowCreditsTranslator.java | 2 +- .../entity/BedrockEntityEventTranslator.java | 2 +- .../player/BedrockActionTranslator.java | 40 +++++++--------- .../player/BedrockInteractTranslator.java | 8 ++-- .../player/BedrockMovePlayerTranslator.java | 4 +- .../player/BedrockRiderJumpTranslator.java | 2 +- .../BedrockLevelSoundEventTranslator.java | 2 +- .../java/JavaCustomQueryTranslator.java | 2 +- .../player/JavaPlayerPositionTranslator.java | 4 +- .../inventory/JavaOpenScreenTranslator.java | 2 +- .../JavaChunkBatchFinishedTranslator.java | 2 +- .../java/level/JavaGameEventTranslator.java | 2 +- .../geysermc/geyser/util/InventoryUtils.java | 8 ++-- 40 files changed, 132 insertions(+), 103 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java index ea2da51df..1ff12dea3 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java @@ -44,7 +44,7 @@ public class StatisticsCommand extends GeyserCommand { session.setWaitingForStatistics(true); ServerboundClientCommandPacket ServerboundClientCommandPacket = new ServerboundClientCommandPacket(ClientCommand.STATS); - session.sendDownstreamPacket(ServerboundClientCommandPacket); + session.sendDownstreamGamePacket(ServerboundClientCommandPacket); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index c88f90f19..0917465d4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -68,7 +68,7 @@ public class InteractionEntity extends Entity { animatePacket.setAction(AnimatePacket.Action.SWING_ARM); session.sendUpstreamPacket(animatePacket); - session.sendDownstreamPacket(new ServerboundSwingPacket(hand)); + session.sendDownstreamGamePacket(new ServerboundSwingPacket(hand)); return InteractionResult.SUCCESS; } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java b/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java index 5b0800e44..e99b901a4 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java @@ -82,14 +82,14 @@ public class AnvilContainer extends Container { correctRename = plainNewName; // Java Edition sends a packet every time an item is renamed even slightly in GUI. Fortunately, this works out for us now ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainNewName); - session.sendDownstreamPacket(renameItemPacket); + session.sendDownstreamGamePacket(renameItemPacket); } else { // Restore formatting for item since we're not renaming correctRename = MessageTranslator.convertMessageLenient(originalName); // Java Edition sends the original custom name when not renaming, // if there isn't a custom name an empty string is sent ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName); - session.sendDownstreamPacket(renameItemPacket); + session.sendDownstreamGamePacket(renameItemPacket); } useJavaLevelCost = false; diff --git a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java index bfe5a7d9d..f31f6d82f 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java @@ -152,7 +152,7 @@ public final class ClickPlan { changedItems ); - session.sendDownstreamPacket(clickPacket); + session.sendDownstreamGamePacket(clickPacket); } session.getPlayerInventory().setCursor(simulatedCursor, session); diff --git a/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java b/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java index ea4ef674b..aa7897038 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java @@ -120,7 +120,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater { // does not result in a FilterTextPacket String originalName = MessageTranslator.convertToPlainTextLenient(ItemUtils.getCustomName(input.getNbt()), session.locale()); ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName); - session.sendDownstreamPacket(renameItemPacket); + session.sendDownstreamGamePacket(renameItemPacket); anvilContainer.setNewName(null); } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 673ff5f37..35b532905 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -1135,7 +1135,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { if (position != null) { ServerboundMovePlayerPosPacket packet = new ServerboundMovePlayerPosPacket(playerEntity.isOnGround(), position.getX(), position.getY(), position.getZ()); - sendDownstreamPacket(packet); + sendDownstreamGamePacket(packet); } lastMovementTimestamp = System.currentTimeMillis(); } @@ -1317,7 +1317,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { return false; } - sendDownstreamPacket(useItemPacket); + sendDownstreamGamePacket(useItemPacket); playerEntity.setFlag(EntityFlag.BLOCKING, true); // Metadata should be updated later return true; @@ -1351,7 +1351,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { if (playerEntity.getFlag(EntityFlag.BLOCKING)) { ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, Vector3i.ZERO, Direction.DOWN, 0); - sendDownstreamPacket(releaseItemPacket); + sendDownstreamGamePacket(releaseItemPacket); playerEntity.setFlag(EntityFlag.BLOCKING, false); return true; } @@ -1361,7 +1361,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { public void requestOffhandSwap() { ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO, Direction.DOWN, 0); - sendDownstreamPacket(swapHandsPacket); + sendDownstreamGamePacket(swapHandsPacket); } @Override @@ -1396,14 +1396,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { * Sends a chat message to the Java server. */ public void sendChat(String message) { - sendDownstreamPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet())); + sendDownstreamGamePacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet())); } /** * Sends a command to the Java server. */ public void sendCommand(String command) { - sendDownstreamPacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet())); + sendDownstreamGamePacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet())); } public void setServerRenderDistance(int renderDistance) { @@ -1575,6 +1575,39 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { upstream.sendPacketImmediately(packet); } + /** + * Send a packet to the remote server if in the game state. + * + * @param packet the java edition packet from MCProtocolLib + */ + public void sendDownstreamGamePacket(Packet packet) { + sendDownstreamPacket(packet, ProtocolState.GAME); + } + + /** + * Send a packet to the remote server if in the login state. + * + * @param packet the java edition packet from MCProtocolLib + */ + public void sendDownstreamLoginPacket(Packet packet) { + sendDownstreamPacket(packet, ProtocolState.LOGIN); + } + + /** + * Send a packet to the remote server if in the specified state. + * + * @param packet the java edition packet from MCProtocolLib + * @param intendedState the state the client should be in + */ + public void sendDownstreamPacket(Packet packet, ProtocolState intendedState) { + if (protocol.getState() != intendedState) { + geyser.getLogger().debug("Tried to send " + packet.getClass().getSimpleName() + " packet while not in " + intendedState.name() + " state"); + return; + } + + sendDownstreamPacket(packet); + } + /** * Send a packet to the remote server. * @@ -1718,7 +1751,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { // We're "flying locked" in this gamemode flying = true; ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true); - sendDownstreamPacket(abilitiesPacket); + sendDownstreamGamePacket(abilitiesPacket); } abilities.add(Ability.FLYING); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java index 00b186292..db0321147 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java @@ -97,7 +97,7 @@ public class AdvancementsCache { } else { // Send a packet indicating that we intend to open this particular advancement window ServerboundSeenAdvancementsPacket packet = new ServerboundSeenAdvancementsPacket(id); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); // Wait for a response there } } @@ -137,7 +137,7 @@ public class AdvancementsCache { builder.closedResultHandler(() -> { // Indicate that we have closed the current advancement tab - session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket()); + session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket()); }).validResultHandler((response) -> { if (response.getClickedButtonId() < visibleAdvancements.size()) { @@ -146,7 +146,7 @@ public class AdvancementsCache { } else { buildAndShowMenuForm(); // Indicate that we have closed the current advancement tab - session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket()); + session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket()); } }); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java index 35bea7295..d1ebd0c78 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java @@ -68,7 +68,7 @@ public class BookEditCache { packet = null; return; } - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); packet = null; lastBookUpdate = System.currentTimeMillis(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java index a0b6ebe9c..00323ce83 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java @@ -114,7 +114,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator // Input a beacon payment BeaconPaymentAction beaconPayment = (BeaconPaymentAction) request.getActions()[0]; ServerboundSetBeaconPacket packet = new ServerboundSetBeaconPacket(toJava(beaconPayment.getPrimaryEffect()), toJava(beaconPayment.getSecondaryEffect())); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java index a1c928c6b..0085a7550 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java @@ -129,7 +129,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla return rejectRequest(request); } ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), javaSlot); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java index ec0d4534d..92cd8a0d4 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java @@ -102,7 +102,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { if (session.isDroppingLecternBook()) { // We have to enter the inventory GUI to eject the book ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), 3); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); session.setDroppingLecternBook(false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false); } else if (lecternContainer.getBlockEntityTag() == null) { @@ -153,7 +153,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { session.getLecternCache().add(position); // Close the window - we will reopen it once the client has this data synced ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId()); - session.sendDownstreamPacket(closeWindowPacket); + session.sendDownstreamGamePacket(closeWindowPacket); InventoryUtils.closeInventory(session, inventory.getJavaId(), false); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java index 8fb98a284..0e43ba660 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java @@ -149,7 +149,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator { // And the Java loom window has a fixed row/width of four // So... Number / 4 = row (so we don't have to bother there), and number % 4 is our column, which leads us back to our index. :) ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), index); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); GeyserItemStack inputCopy = inventory.getItem(0).copy(1); inputCopy.setNetId(session.getNextItemNetId()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index e159827e8..c4f958ba1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -155,7 +155,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator { private ItemStackResponse handleTrade(GeyserSession session, Inventory inventory, ItemStackRequest request, int tradeChoice) { ServerboundSelectTradePacket packet = new ServerboundSelectTradePacket(tradeChoice); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); if (session.isEmulatePost1_13Logic()) { // 1.18 Java cooperates nicer than older versions diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java index b9468ac4f..613121dfd 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java @@ -359,7 +359,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator { } ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, sourceItem.getItemStack(dropAction.getCount())); - session.sendDownstreamPacket(creativeDropPacket); + session.sendDownstreamGamePacket(creativeDropPacket); sourceItem.sub(dropAction.getCount()); } @@ -494,7 +494,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator { dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getNbt()); } ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, dropStack); - session.sendDownstreamPacket(creativeDropPacket); + session.sendDownstreamGamePacket(creativeDropPacket); break; } default: @@ -515,7 +515,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator { ItemStack itemStack = item.isEmpty() ? new ItemStack(-1, 0, null) : item.getItemStack(); ServerboundSetCreativeModeSlotPacket creativePacket = new ServerboundSetCreativeModeSlotPacket(slot, itemStack); - session.sendDownstreamPacket(creativePacket); + session.sendDownstreamGamePacket(creativePacket); } private static boolean isCraftingGrid(ItemStackRequestSlotData slotInfoData) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java index 0663866ed..50c040a0b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java @@ -69,7 +69,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl if (container.getStonecutterButton() != button) { // Getting the index of the item in the Java stonecutter list ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), button); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); container.setStonecutterButton(button); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java index 60ff187f5..33fbaed30 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java @@ -64,7 +64,7 @@ public class BedrockAnimateTranslator extends PacketTranslator { // and Bedrock 1.19.51. // Note for the future: we should probably largely ignore this packet and instead replicate // all actions on our end, and send swings where needed. - session.sendDownstreamPacket(new ServerboundSwingPacket(Hand.MAIN_HAND)); + session.sendDownstreamGamePacket(new ServerboundSwingPacket(Hand.MAIN_HAND)); session.activateArmAnimationTicking(); } }, @@ -77,12 +77,12 @@ public class BedrockAnimateTranslator extends PacketTranslator { // Packet value is a float of how long one has been rowing, so we convert that into a boolean session.setSteeringLeft(packet.getRowingTime() > 0.0); ServerboundPaddleBoatPacket steerLeftPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight()); - session.sendDownstreamPacket(steerLeftPacket); + session.sendDownstreamGamePacket(steerLeftPacket); } case ROW_RIGHT -> { session.setSteeringRight(packet.getRowingTime() > 0.0); ServerboundPaddleBoatPacket steerRightPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight()); - session.sendDownstreamPacket(steerRightPacket); + session.sendDownstreamGamePacket(steerRightPacket); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java index f280f144f..bab5e59a5 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java @@ -108,7 +108,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator legacySlots = packet.getLegacySlots(); if (packet.getActions().size() == 1 && legacySlots.size() > 0) { @@ -453,13 +453,13 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator currentJavaPage) { for (int i = currentJavaPage; i < newJavaPage; i++) { ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2); - session.sendDownstreamPacket(clickButtonPacket); + session.sendDownstreamGamePacket(clickButtonPacket); } } else { for (int i = currentJavaPage; i > newJavaPage; i--) { ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1); - session.sendDownstreamPacket(clickButtonPacket); + session.sendDownstreamGamePacket(clickButtonPacket); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java index d045a6c24..f5086e29a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java @@ -58,7 +58,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator session.sendDownstreamPacket(new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence())), + session.scheduleInEventLoop(() -> session.sendDownstreamGamePacket(new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence())), 50, TimeUnit.MILLISECONDS); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java index 4b5107bda..8a8749e34 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java @@ -72,6 +72,6 @@ public class BedrockMoveEntityAbsoluteTranslator extends PacketTranslator { public void translate(GeyserSession session, RespawnPacket packet) { if (packet.getState() == RespawnPacket.State.CLIENT_READY) { ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); - session.sendDownstreamPacket(javaRespawnPacket); + session.sendDownstreamGamePacket(javaRespawnPacket); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java index 0aec2a5d9..3314975ef 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java @@ -39,7 +39,7 @@ public class BedrockShowCreditsTranslator extends PacketTranslator { // Not sent as of 1.18.10 ServerboundSelectTradePacket selectTradePacket = new ServerboundSelectTradePacket(packet.getData()); - session.sendDownstreamPacket(selectTradePacket); + session.sendDownstreamGamePacket(selectTradePacket); session.scheduleInEventLoop(() -> { Inventory openInventory = session.getOpenInventory(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java index 826a76575..bff097248 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java @@ -26,10 +26,6 @@ package org.geysermc.geyser.translator.protocol.bedrock.entity.player; import com.github.steveice10.mc.protocol.data.game.entity.object.Direction; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; @@ -97,7 +93,7 @@ public class BedrockActionTranslator extends PacketTranslator } ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking()); - session.sendDownstreamPacket(interactPacket); + session.sendDownstreamGamePacket(interactPacket); break; case DAMAGE: ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking()); - session.sendDownstreamPacket(attackPacket); + session.sendDownstreamGamePacket(attackPacket); break; case LEAVE_VEHICLE: ServerboundPlayerCommandPacket sneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING); - session.sendDownstreamPacket(sneakPacket); + session.sendDownstreamGamePacket(sneakPacket); Entity currentVehicle = session.getPlayerEntity().getVehicle(); if (currentVehicle != null) { @@ -123,7 +123,7 @@ public class BedrockInteractTranslator extends PacketTranslator if (ridingEntity instanceof AbstractHorseEntity || (ridingEntity != null && ridingEntity.getDefinition().entityType() == EntityType.CHEST_BOAT)) { // This mob has an inventory of its own that we should open instead. ServerboundPlayerCommandPacket openVehicleWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_VEHICLE_INVENTORY); - session.sendDownstreamPacket(openVehicleWindowPacket); + session.sendDownstreamGamePacket(openVehicleWindowPacket); } else { session.setOpenInventory(session.getPlayerInventory()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java index cae25e2a3..d81c0abab 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java @@ -83,7 +83,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator { ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); - session.sendDownstreamPacket(javaRespawnPacket); + session.sendDownstreamGamePacket(javaRespawnPacket); } case FIRST_TIME -> { ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket(); diff --git a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java index 9141ee7ab..0348eca11 100644 --- a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java @@ -260,7 +260,7 @@ public class InventoryUtils { // If this is the item we're looking for if (geyserItem.getJavaId() == itemStack.getId() && Objects.equals(geyserItem.getNbt(), itemStack.getNbt())) { ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item - session.sendDownstreamPacket(packetToSend); + session.sendDownstreamGamePacket(packetToSend); return; } } @@ -274,7 +274,7 @@ public class InventoryUtils { if ((slot - 36) != inventory.getHeldItemSlot()) { setHotbarItem(session, slot); } - session.sendDownstreamPacket(actionPacket); + session.sendDownstreamGamePacket(actionPacket); } } @@ -325,7 +325,7 @@ public class InventoryUtils { } ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item - session.sendDownstreamPacket(packetToSend); + session.sendDownstreamGamePacket(packetToSend); return; } @@ -340,7 +340,7 @@ public class InventoryUtils { if ((slot - 36) != inventory.getHeldItemSlot()) { setHotbarItem(session, slot); } - session.sendDownstreamPacket(actionPacket); + session.sendDownstreamGamePacket(actionPacket); } else { session.getGeyser().getLogger().debug("Cannot find item for block " + itemName); }