From 9d1d77f9d0be65e3297d2f80a66534f31881e89a Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 30 Aug 2023 23:43:26 +0200 Subject: [PATCH] Address review by Camotoy - no need to tell client about new difficulty/default game mode Remove duplicate settings in SettingsUtils - otherwise, they clash with the new translator Prevent client Gamemode switching when personal Gamemode is "default" --- .../BedrockSetDefaultGameTypeTranslator.java | 11 ++++--- .../BedrockSetDifficultyTranslator.java | 4 --- .../geysermc/geyser/util/SettingsUtils.java | 31 ------------------- 3 files changed, 7 insertions(+), 39 deletions(-) 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 45eed0a11c9..cb8edcc633e 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 @@ -27,6 +27,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import org.cloudburstmc.protocol.bedrock.packet.SetDefaultGameTypePacket; +import org.cloudburstmc.protocol.bedrock.packet.SetPlayerGameTypePacket; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; @@ -42,9 +43,11 @@ public void translate(GeyserSession session, SetDefaultGameTypePacket packet) { if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { session.getGeyser().getWorldManager().setDefaultGameMode(session, GameMode.byId(packet.getGamemode())); } - // update the client - SetDefaultGameTypePacket defaultGameTypePacket = new SetDefaultGameTypePacket(); - defaultGameTypePacket.setGamemode(packet.getGamemode()); - session.sendUpstreamPacket(defaultGameTypePacket); + // Stop the client from updating their own Gamemode without telling the server + // Can occur when client Gamemode is set to "default", and default game mode is changed. + SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); + int gamemode = session.getGameMode().ordinal() == 3 ? 6 : session.getGameMode().ordinal(); + playerGameTypePacket.setGamemode(gamemode); + session.sendUpstreamPacket(playerGameTypePacket); } } 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 181bb89facf..a36aa77df3f 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 @@ -44,9 +44,5 @@ public void translate(GeyserSession session, SetDifficultyPacket packet) { session.getGeyser().getWorldManager().setDifficulty(session, Difficulty.from(packet.getDifficulty())); } } - // inform the client - SetDifficultyPacket difficultyPacket = new SetDifficultyPacket(); - difficultyPacket.setDifficulty(session.getWorldCache().getDifficulty().ordinal()); - session.sendUpstreamPacket(difficultyPacket); } } diff --git a/core/src/main/java/org/geysermc/geyser/util/SettingsUtils.java b/core/src/main/java/org/geysermc/geyser/util/SettingsUtils.java index 5957fb9d98f..8a8d684f6ee 100644 --- a/core/src/main/java/org/geysermc/geyser/util/SettingsUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/SettingsUtils.java @@ -25,8 +25,6 @@ package org.geysermc.geyser.util; -import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; -import com.github.steveice10.mc.protocol.data.game.setting.Difficulty; import org.geysermc.cumulus.component.DropdownComponent; import org.geysermc.cumulus.form.CustomForm; import org.geysermc.geyser.GeyserImpl; @@ -77,23 +75,6 @@ public static CustomForm buildForm(GeyserSession session) { } } - boolean canModifyServer = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server"); - if (canModifyServer) { - builder.label("geyser.settings.title.server"); - - DropdownComponent.Builder gamemodeDropdown = DropdownComponent.builder("%createWorldScreen.gameMode.personal"); - for (GameMode gamemode : GameMode.values()) { - gamemodeDropdown.option("selectWorld.gameMode." + gamemode.name().toLowerCase(), session.getGameMode() == gamemode); - } - builder.dropdown(gamemodeDropdown); - - DropdownComponent.Builder difficultyDropdown = DropdownComponent.builder("%options.difficulty"); - for (Difficulty difficulty : Difficulty.values()) { - difficultyDropdown.option("%options.difficulty." + difficulty.name().toLowerCase(), session.getWorldCache().getDifficulty() == difficulty); - } - builder.dropdown(difficultyDropdown); - } - boolean showGamerules = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules"); if (showGamerules) { builder.label("geyser.settings.title.game_rules") @@ -128,18 +109,6 @@ public static CustomForm buildForm(GeyserSession session) { } } - if (canModifyServer) { - GameMode gameMode = GameMode.values()[(int) response.next()]; - if (gameMode != null && gameMode != session.getGameMode()) { - session.getGeyser().getWorldManager().setPlayerGameMode(session, gameMode); - } - - Difficulty difficulty = Difficulty.values()[(int) response.next()]; - if (difficulty != null && difficulty != session.getWorldCache().getDifficulty()) { - session.getGeyser().getWorldManager().setDifficulty(session, difficulty); - } - } - if (showGamerules) { for (GameRule gamerule : GameRule.VALUES) { if (Boolean.class.equals(gamerule.getType())) {