Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwanted behaviour with show-coordinates #2151

Merged
merged 7 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -1199,13 +1198,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