From 215ffc618fc04845fff47dd5b2bfd613028f8a34 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 19:57:53 -0400 Subject: [PATCH] Fix some SettingsUtils regressions - Add the new 1.17 gamerules - Don't hide exceptions in form responses - Fix the settings form silently failing - Fix some translation strings in the settings form --- .../network/session/cache/FormCache.java | 11 ++++--- .../geysermc/connector/utils/GameRule.java | 4 ++- .../connector/utils/SettingsUtils.java | 30 +++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java index 1cdcf228b..954a2b033 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java @@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.RequiredArgsConstructor; +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.cumulus.Form; import org.geysermc.cumulus.SimpleForm; @@ -73,17 +74,19 @@ public class FormCache { } public void handleResponse(ModalFormResponsePacket response) { - Form form = forms.get(response.getFormId()); + Form form = forms.remove(response.getFormId()); if (form == null) { return; } Consumer responseConsumer = form.getResponseHandler(); if (responseConsumer != null) { - responseConsumer.accept(response.getFormData()); + try { + responseConsumer.accept(response.getFormData()); + } catch (Exception e) { + GeyserConnector.getInstance().getLogger().error("Error while processing form response!", e); + } } - - removeWindow(response.getFormId()); } public boolean removeWindow(int id) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/GameRule.java b/connector/src/main/java/org/geysermc/connector/utils/GameRule.java index ca8ce3d3b..0b3908694 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/GameRule.java +++ b/connector/src/main/java/org/geysermc/connector/utils/GameRule.java @@ -51,6 +51,7 @@ public enum GameRule { DROWNINGDAMAGE("drowningDamage", Boolean.class, true), FALLDAMAGE("fallDamage", Boolean.class, true), FIREDAMAGE("fireDamage", Boolean.class, true), + FREEZEDAMAGE("freezeDamage", Boolean.class, true), FORGIVEDEADPLAYERS("forgiveDeadPlayers", Boolean.class, true), // JE only KEEPINVENTORY("keepInventory", Boolean.class, false), LOGADMINCOMMANDS("logAdminCommands", Boolean.class, true), // JE only @@ -58,6 +59,7 @@ public enum GameRule { MAXENTITYCRAMMING("maxEntityCramming", Integer.class, 24), // JE only MOBGRIEFING("mobGriefing", Boolean.class, true), NATURALREGENERATION("naturalRegeneration", Boolean.class, true), + PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", Integer.class, 100), // JE only RANDOMTICKSPEED("randomTickSpeed", Integer.class, 3), REDUCEDDEBUGINFO("reducedDebugInfo", Boolean.class, false), // JE only SENDCOMMANDFEEDBACK("sendCommandFeedback", Boolean.class, true), @@ -68,7 +70,7 @@ public enum GameRule { UNKNOWN("unknown", Object.class); - private static final GameRule[] VALUES = values(); + public static final GameRule[] VALUES = values(); @Getter private final String javaID; 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 1bd89de60..3937fa9a6 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java @@ -45,12 +45,13 @@ public class SettingsUtils { String language = session.getLocale(); CustomForm.Builder builder = CustomForm.builder() - .translator(LanguageUtils::getPlayerLocaleString, language) + .translator(SettingsUtils::translateEntry, language) .title("geyser.settings.title.main") .iconPath("textures/ui/settings_glyph_color_2x.png"); // Only show the client title if any of the client settings are available - if (session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { + boolean showClientSettings = session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED; + if (showClientSettings) { builder.label("geyser.settings.title.client"); // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. @@ -67,7 +68,8 @@ public class SettingsUtils { } } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { + 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"); @@ -83,7 +85,8 @@ public class SettingsUtils { builder.dropdown(difficultyDropdown); } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules")) { + boolean showGamerules = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules"); + if (showGamerules) { builder.label("geyser.settings.title.game_rules") .translator(LocaleUtils::getLocaleString); // we need translate gamerules next @@ -108,24 +111,20 @@ public class SettingsUtils { return; } - if (session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { - response.skip(); // Client settings title - + if (showClientSettings) { // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. if (session.getPreferencesCache().isAllowShowCoordinates()) { session.getPreferencesCache().setPrefersShowCoordinates(response.next()); session.getPreferencesCache().updateShowCoordinates(); - response.skip(); } if (CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { CooldownUtils.CooldownType cooldownType = CooldownUtils.CooldownType.VALUES[(int) response.next()]; session.getPreferencesCache().setCooldownPreference(cooldownType); - response.skip(); } } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { + if (canModifyServer) { GameMode gameMode = GameMode.values()[(int) response.next()]; if (gameMode != null && gameMode != session.getGameMode()) { session.getConnector().getWorldManager().setPlayerGameMode(session, gameMode); @@ -137,8 +136,8 @@ public class SettingsUtils { } } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules")) { - for (GameRule gamerule : GameRule.values()) { + if (showGamerules) { + for (GameRule gamerule : GameRule.VALUES) { if (gamerule.equals(GameRule.UNKNOWN)) { continue; } @@ -160,4 +159,11 @@ public class SettingsUtils { return builder.build(); } + + private static String translateEntry(String key, String locale) { + if (key.startsWith("geyser.")) { + return LanguageUtils.getPlayerLocaleString(key, locale); + } + return LocaleUtils.getLocaleString(key, locale); + } }