From 6f6c1455ee6f6004eb63685203f92bd968beb261 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 24 Jan 2021 12:26:48 +0000 Subject: [PATCH 1/6] Fix show-coordinates not disabling the coordinates display --- .../geysermc/connector/network/session/GeyserSession.java | 4 +++- .../geysermc/connector/network/session/cache/WorldCache.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 104e72cd365..d84022a3052 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -836,6 +836,8 @@ private void startGame() { startGamePacket.setVanillaVersion("*"); startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT); upstream.sendPacket(startGamePacket); + + getWorldCache().setShowCoordinates(connector.getConfig().isShowCoordinates()); } public void addTeleport(TeleportCache teleportCache) { @@ -956,8 +958,8 @@ public void sendDownstreamPacket(Packet packet) { * @param value The new value for reducedDebugInfo */ public void setReducedDebugInfo(boolean value) { - worldCache.setShowCoordinates(!value); reducedDebugInfo = value; + worldCache.setShowCoordinates(!value); } /** diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java index 0cbfffbaf3d..5decd9b6ccb 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java @@ -71,7 +71,8 @@ public int increaseAndGetScoreboardPacketsPerSecond() { * @param value True to show, false to hide */ public void setShowCoordinates(boolean value) { - showCoordinates = value; - session.sendGameRule("showcoordinates", value); + boolean check = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); + showCoordinates = check && value; + session.sendGameRule("showcoordinates", check && value); } } \ No newline at end of file From db88a504842f3e333c9541bd6f350d20a93bc789 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 25 Jan 2021 09:10:05 +0000 Subject: [PATCH 2/6] Add more descriptive variables and comments --- .../geysermc/connector/network/session/GeyserSession.java | 5 +++-- .../connector/network/session/cache/WorldCache.java | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index d84022a3052..633d8b0b8c2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -386,6 +386,9 @@ public void connect(RemoteServer remoteServer) { startGame(); this.remoteServer = remoteServer; + // Update the ShowCoordinates data based on the config setting + getWorldCache().setShowCoordinates(connector.getConfig().isShowCoordinates()); + // Set the hardcoded shield ID to the ID we just defined in StartGamePacket upstream.getSession().getHardcodedBlockingId().set(ItemRegistry.SHIELD.getBedrockId()); @@ -836,8 +839,6 @@ private void startGame() { startGamePacket.setVanillaVersion("*"); startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT); upstream.sendPacket(startGamePacket); - - getWorldCache().setShowCoordinates(connector.getConfig().isShowCoordinates()); } public void addTeleport(TeleportCache teleportCache) { diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java index 5decd9b6ccb..57dca4b45e3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java @@ -71,8 +71,8 @@ public int increaseAndGetScoreboardPacketsPerSecond() { * @param value True to show, false to hide */ public void setShowCoordinates(boolean value) { - boolean check = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); - showCoordinates = check && value; - session.sendGameRule("showcoordinates", check && value); + boolean allowUserSetting = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); + showCoordinates = allowUserSetting && value; + session.sendGameRule("showcoordinates", allowUserSetting && value); } } \ No newline at end of file From b1f1fe6b341008416fd65e7f32d2f25660cb3124 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Sun, 18 Apr 2021 22:39:42 -0400 Subject: [PATCH 3/6] fix show-coordinates --- .../network/session/GeyserSession.java | 8 ++---- .../network/session/cache/WorldCache.java | 28 +++++++++++++++---- .../connector/utils/SettingsUtils.java | 18 ++++++++---- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 5a471c8122b..2d367ca154c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -493,9 +493,6 @@ public void connect() { this.remotePort = connector.getConfig().getRemote().getPort(); this.remoteAuthType = connector.getDefaultAuthType(); - // Update the ShowCoordinates data based on the config setting - getWorldCache().setShowCoordinates(connector.getConfig().isShowCoordinates()); - // Set the hardcoded shield ID to the ID we just defined in StartGamePacket upstream.getSession().getHardcodedBlockingId().set(ItemRegistry.SHIELD.getBedrockId()); @@ -1202,13 +1199,14 @@ public void sendDownstreamPacket(Packet packet) { /** * Update the cached value for the reduced debug info gamerule. - * This also toggles the coordinates display + * If enabled, also hides the player's coordinates. * * @param value The new value for reducedDebugInfo */ public void setReducedDebugInfo(boolean value) { reducedDebugInfo = value; - worldCache.setShowCoordinates(!value); + // Set the showCoordinates data. This is done because setShowCoordinates() uses this gamerule as a variable. + getWorldCache().setShowCoordinates(); } /** diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java index 57dca4b45e3..3c21a929430 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java @@ -28,6 +28,7 @@ import com.github.steveice10.mc.protocol.data.game.setting.Difficulty; import lombok.Getter; import lombok.Setter; +import org.geysermc.connector.configuration.GeyserConfiguration; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.scoreboard.Objective; import org.geysermc.connector.scoreboard.Scoreboard; @@ -38,6 +39,17 @@ public class WorldCache { private final GeyserSession session; @Setter private Difficulty difficulty = Difficulty.EASY; + + /** + * True if the client prefers being shown their coordinates, regardless if they're being shown or not. + * This will be true everytime the client joins the server because neither the client nor server store the preference permanently. + */ + @Setter + private boolean prefersShowCoordinates = true; + + /** + * True if the client is being shown their coordinates. + */ private boolean showCoordinates = true; private Scoreboard scoreboard; @@ -66,13 +78,17 @@ public int increaseAndGetScoreboardPacketsPerSecond() { } /** - * Tell the client to hide or show the coordinates + * Tell the client to hide or show the coordinates. + * + * If {@link #isPrefersShowCoordinates()} is true, coordinates will be shown, unless either of the following conditions apply: + * + *
  • {@link GeyserSession#isReducedDebugInfo()} is enabled + *
  • {@link GeyserConfiguration#isShowCoordinates()} is disabled. * - * @param value True to show, false to hide */ - public void setShowCoordinates(boolean value) { - boolean allowUserSetting = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); - showCoordinates = allowUserSetting && value; - session.sendGameRule("showcoordinates", allowUserSetting && value); + public void setShowCoordinates() { + boolean allowShowCoordinates = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); + showCoordinates = allowShowCoordinates && prefersShowCoordinates; + session.sendGameRule("showcoordinates", showCoordinates); } } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java index c01378d0012..d0d89f177cb 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java @@ -57,8 +57,12 @@ public static void buildForm(GeyserSession session) { CustomFormBuilder builder = new CustomFormBuilder(LanguageUtils.getPlayerLocaleString("geyser.settings.title.main", language)); builder.setIcon(new FormImage(FormImage.FormImageType.PATH, "textures/ui/settings_glyph_color_2x.png")); - builder.addComponent(new LabelComponent(LanguageUtils.getPlayerLocaleString("geyser.settings.title.client", language))); - builder.addComponent(new ToggleComponent(LanguageUtils.getPlayerLocaleString("geyser.settings.option.coordinates", language), session.getWorldCache().isShowCoordinates())); + // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. + if (!session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates()) { + builder.addComponent(new LabelComponent(LanguageUtils.getPlayerLocaleString("geyser.settings.title.client", language))); + + builder.addComponent(new ToggleComponent(LanguageUtils.getPlayerLocaleString("geyser.settings.option.coordinates", language), session.getWorldCache().isPrefersShowCoordinates())); + } if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { @@ -117,10 +121,14 @@ public static boolean handleSettingsForm(GeyserSession session, String response) } int offset = 0; - offset++; // Client settings title + // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. + if (!session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates()) { + offset++; // Client settings title - session.getWorldCache().setShowCoordinates(settingsResponse.getToggleResponses().get(offset)); - offset++; + session.getWorldCache().setPrefersShowCoordinates(settingsResponse.getToggleResponses().get(offset)); + session.getWorldCache().setShowCoordinates(); + offset++; + } if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { offset++; // Server settings title From ad7f5f6ba4a8d430f76dd1636399c1b71246ee6d Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Mon, 19 Apr 2021 10:57:01 -0400 Subject: [PATCH 4/6] rename setShowCoordinates() to updateShowCoordinates() --- .../org/geysermc/connector/network/session/GeyserSession.java | 4 ++-- .../geysermc/connector/network/session/cache/WorldCache.java | 2 +- .../main/java/org/geysermc/connector/utils/SettingsUtils.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 2d367ca154c..ec1d74fd947 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -1205,8 +1205,8 @@ public void sendDownstreamPacket(Packet packet) { */ public void setReducedDebugInfo(boolean value) { reducedDebugInfo = value; - // Set the showCoordinates data. This is done because setShowCoordinates() uses this gamerule as a variable. - getWorldCache().setShowCoordinates(); + // Set the showCoordinates data. This is done because updateShowCoordinates() uses this gamerule as a variable. + getWorldCache().updateShowCoordinates(); } /** diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java index 3c21a929430..8f4e81c9bde 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java @@ -86,7 +86,7 @@ public int increaseAndGetScoreboardPacketsPerSecond() { *
  • {@link GeyserConfiguration#isShowCoordinates()} is disabled. * */ - public void setShowCoordinates() { + public void updateShowCoordinates() { boolean allowShowCoordinates = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); showCoordinates = allowShowCoordinates && prefersShowCoordinates; session.sendGameRule("showcoordinates", showCoordinates); diff --git a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java index d0d89f177cb..1d06c8a0f1a 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java @@ -126,7 +126,7 @@ public static boolean handleSettingsForm(GeyserSession session, String response) offset++; // Client settings title session.getWorldCache().setPrefersShowCoordinates(settingsResponse.getToggleResponses().get(offset)); - session.getWorldCache().setShowCoordinates(); + session.getWorldCache().updateShowCoordinates(); offset++; } From e2eb052e7b27572a416c9d8dde4ad056d09b7080 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Tue, 20 Apr 2021 18:33:27 -0400 Subject: [PATCH 5/6] remove unused showCoordinates variable --- .../connector/network/session/cache/WorldCache.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java index 8f4e81c9bde..270d3f4a593 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WorldCache.java @@ -47,11 +47,6 @@ public class WorldCache { @Setter private boolean prefersShowCoordinates = true; - /** - * True if the client is being shown their coordinates. - */ - private boolean showCoordinates = true; - private Scoreboard scoreboard; private final ScoreboardUpdater scoreboardUpdater; @@ -83,12 +78,11 @@ public int increaseAndGetScoreboardPacketsPerSecond() { * If {@link #isPrefersShowCoordinates()} is true, coordinates will be shown, unless either of the following conditions apply: * *
  • {@link GeyserSession#isReducedDebugInfo()} is enabled - *
  • {@link GeyserConfiguration#isShowCoordinates()} is disabled. + *
  • {@link GeyserConfiguration#isShowCoordinates()} is disabled * */ public void updateShowCoordinates() { boolean allowShowCoordinates = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates(); - showCoordinates = allowShowCoordinates && prefersShowCoordinates; - session.sendGameRule("showcoordinates", showCoordinates); + session.sendGameRule("showcoordinates", allowShowCoordinates && prefersShowCoordinates); } } \ No newline at end of file From 93d93e86e015b5cfde4cca0a0579d1d7b15fa7a9 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Wed, 21 Apr 2021 16:12:48 -0400 Subject: [PATCH 6/6] set reducedDebugInfo in JavaJoinGameTranslator --- .../org/geysermc/connector/network/session/GeyserSession.java | 1 - .../network/translators/java/JavaJoinGameTranslator.java | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index ec1d74fd947..2594cff0038 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -1007,7 +1007,6 @@ private void startGame() { startGamePacket.setLightningLevel(0); startGamePacket.setMultiplayerGame(true); startGamePacket.setBroadcastingToLan(true); - startGamePacket.getGamerules().add(new GameRuleData<>("showcoordinates", connector.getConfig().isShowCoordinates())); startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC); startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC); startGamePacket.setCommandsEnabled(!connector.getConfig().isXboxAchievementsEnabled()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index e9a1901dce2..33e46c95681 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -86,6 +86,8 @@ public void translate(ServerJoinGamePacket packet, GeyserSession session) { gamerulePacket.getGameRules().add(new GameRuleData<>("doimmediaterespawn", !packet.isEnableRespawnScreen())); session.sendUpstreamPacket(gamerulePacket); + session.setReducedDebugInfo(packet.isReducedDebugInfo()); + session.setRenderDistance(packet.getViewDistance()); // We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc