Skip to content

Commit

Permalink
Fix unwanted behaviour with show-coordinates (#2151)
Browse files Browse the repository at this point in the history
Co-authored-by: rtm516 <[email protected]>
  • Loading branch information
Konicai and rtm516 authored Apr 21, 2021
1 parent f0a002f commit 0a79eb9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,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());
Expand Down Expand Up @@ -1214,13 +1213,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) {
worldCache.setShowCoordinates(!value);
reducedDebugInfo = value;
// Set the showCoordinates data. This is done because updateShowCoordinates() uses this gamerule as a variable.
getWorldCache().updateShowCoordinates();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +39,13 @@ public class WorldCache {
private final GeyserSession session;
@Setter
private Difficulty difficulty = Difficulty.EASY;
private boolean showCoordinates = true;

/**
* 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;

private Scoreboard scoreboard;
private final ScoreboardUpdater scoreboardUpdater;
Expand Down Expand Up @@ -66,12 +73,16 @@ 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:
*
* <li> {@link GeyserSession#isReducedDebugInfo()} is enabled
* <li> {@link GeyserConfiguration#isShowCoordinates()} is disabled
*
* @param value True to show, false to hide
*/
public void setShowCoordinates(boolean value) {
showCoordinates = value;
session.sendGameRule("showcoordinates", value);
public void updateShowCoordinates() {
boolean allowShowCoordinates = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates();
session.sendGameRule("showcoordinates", allowShowCoordinates && prefersShowCoordinates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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().updateShowCoordinates();
offset++;
}

if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) {
offset++; // Server settings title
Expand Down

0 comments on commit 0a79eb9

Please sign in to comment.