Fix unwanted behaviour with show-coordinates (#2151)

Co-authored-by: rtm516 <ryantmilner@hotmail.co.uk>
This commit is contained in:
Konicai 2021-04-21 16:57:01 -04:00 committed by GitHub
parent f0a002f0e3
commit 0a79eb92ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 14 deletions

View File

@ -1022,7 +1022,6 @@ public class GeyserSession implements CommandSender {
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());
@ -1214,13 +1213,14 @@ public class GeyserSession implements CommandSender {
/**
* 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();
}
/**

View File

@ -28,6 +28,7 @@ package org.geysermc.connector.network.session.cache;
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,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;
@ -66,12 +73,16 @@ public class WorldCache {
}
/**
* 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);
}
}

View File

@ -86,6 +86,8 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
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

View File

@ -57,8 +57,12 @@ public class SettingsUtils {
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 class SettingsUtils {
}
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