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
This commit is contained in:
Camotoy 2021-06-27 19:57:53 -04:00
parent 5b1d815926
commit 215ffc618f
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 28 additions and 17 deletions

View file

@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.cumulus.Form; import org.geysermc.cumulus.Form;
import org.geysermc.cumulus.SimpleForm; import org.geysermc.cumulus.SimpleForm;
@ -73,17 +74,19 @@ public class FormCache {
} }
public void handleResponse(ModalFormResponsePacket response) { public void handleResponse(ModalFormResponsePacket response) {
Form form = forms.get(response.getFormId()); Form form = forms.remove(response.getFormId());
if (form == null) { if (form == null) {
return; return;
} }
Consumer<String> responseConsumer = form.getResponseHandler(); Consumer<String> responseConsumer = form.getResponseHandler();
if (responseConsumer != null) { 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) { public boolean removeWindow(int id) {

View file

@ -51,6 +51,7 @@ public enum GameRule {
DROWNINGDAMAGE("drowningDamage", Boolean.class, true), DROWNINGDAMAGE("drowningDamage", Boolean.class, true),
FALLDAMAGE("fallDamage", Boolean.class, true), FALLDAMAGE("fallDamage", Boolean.class, true),
FIREDAMAGE("fireDamage", Boolean.class, true), FIREDAMAGE("fireDamage", Boolean.class, true),
FREEZEDAMAGE("freezeDamage", Boolean.class, true),
FORGIVEDEADPLAYERS("forgiveDeadPlayers", Boolean.class, true), // JE only FORGIVEDEADPLAYERS("forgiveDeadPlayers", Boolean.class, true), // JE only
KEEPINVENTORY("keepInventory", Boolean.class, false), KEEPINVENTORY("keepInventory", Boolean.class, false),
LOGADMINCOMMANDS("logAdminCommands", Boolean.class, true), // JE only LOGADMINCOMMANDS("logAdminCommands", Boolean.class, true), // JE only
@ -58,6 +59,7 @@ public enum GameRule {
MAXENTITYCRAMMING("maxEntityCramming", Integer.class, 24), // JE only MAXENTITYCRAMMING("maxEntityCramming", Integer.class, 24), // JE only
MOBGRIEFING("mobGriefing", Boolean.class, true), MOBGRIEFING("mobGriefing", Boolean.class, true),
NATURALREGENERATION("naturalRegeneration", Boolean.class, true), NATURALREGENERATION("naturalRegeneration", Boolean.class, true),
PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", Integer.class, 100), // JE only
RANDOMTICKSPEED("randomTickSpeed", Integer.class, 3), RANDOMTICKSPEED("randomTickSpeed", Integer.class, 3),
REDUCEDDEBUGINFO("reducedDebugInfo", Boolean.class, false), // JE only REDUCEDDEBUGINFO("reducedDebugInfo", Boolean.class, false), // JE only
SENDCOMMANDFEEDBACK("sendCommandFeedback", Boolean.class, true), SENDCOMMANDFEEDBACK("sendCommandFeedback", Boolean.class, true),
@ -68,7 +70,7 @@ public enum GameRule {
UNKNOWN("unknown", Object.class); UNKNOWN("unknown", Object.class);
private static final GameRule[] VALUES = values(); public static final GameRule[] VALUES = values();
@Getter @Getter
private final String javaID; private final String javaID;

View file

@ -45,12 +45,13 @@ public class SettingsUtils {
String language = session.getLocale(); String language = session.getLocale();
CustomForm.Builder builder = CustomForm.builder() CustomForm.Builder builder = CustomForm.builder()
.translator(LanguageUtils::getPlayerLocaleString, language) .translator(SettingsUtils::translateEntry, language)
.title("geyser.settings.title.main") .title("geyser.settings.title.main")
.iconPath("textures/ui/settings_glyph_color_2x.png"); .iconPath("textures/ui/settings_glyph_color_2x.png");
// Only show the client title if any of the client settings are available // 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"); builder.label("geyser.settings.title.client");
// Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. // 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"); builder.label("geyser.settings.title.server");
DropdownComponent.Builder gamemodeDropdown = DropdownComponent.builder("%createWorldScreen.gameMode.personal"); DropdownComponent.Builder gamemodeDropdown = DropdownComponent.builder("%createWorldScreen.gameMode.personal");
@ -83,7 +85,8 @@ public class SettingsUtils {
builder.dropdown(difficultyDropdown); 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") builder.label("geyser.settings.title.game_rules")
.translator(LocaleUtils::getLocaleString); // we need translate gamerules next .translator(LocaleUtils::getLocaleString); // we need translate gamerules next
@ -108,24 +111,20 @@ public class SettingsUtils {
return; return;
} }
if (session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { if (showClientSettings) {
response.skip(); // Client settings title
// Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config.
if (session.getPreferencesCache().isAllowShowCoordinates()) { if (session.getPreferencesCache().isAllowShowCoordinates()) {
session.getPreferencesCache().setPrefersShowCoordinates(response.next()); session.getPreferencesCache().setPrefersShowCoordinates(response.next());
session.getPreferencesCache().updateShowCoordinates(); session.getPreferencesCache().updateShowCoordinates();
response.skip();
} }
if (CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { if (CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) {
CooldownUtils.CooldownType cooldownType = CooldownUtils.CooldownType.VALUES[(int) response.next()]; CooldownUtils.CooldownType cooldownType = CooldownUtils.CooldownType.VALUES[(int) response.next()];
session.getPreferencesCache().setCooldownPreference(cooldownType); session.getPreferencesCache().setCooldownPreference(cooldownType);
response.skip();
} }
} }
if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { if (canModifyServer) {
GameMode gameMode = GameMode.values()[(int) response.next()]; GameMode gameMode = GameMode.values()[(int) response.next()];
if (gameMode != null && gameMode != session.getGameMode()) { if (gameMode != null && gameMode != session.getGameMode()) {
session.getConnector().getWorldManager().setPlayerGameMode(session, gameMode); session.getConnector().getWorldManager().setPlayerGameMode(session, gameMode);
@ -137,8 +136,8 @@ public class SettingsUtils {
} }
} }
if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules")) { if (showGamerules) {
for (GameRule gamerule : GameRule.values()) { for (GameRule gamerule : GameRule.VALUES) {
if (gamerule.equals(GameRule.UNKNOWN)) { if (gamerule.equals(GameRule.UNKNOWN)) {
continue; continue;
} }
@ -160,4 +159,11 @@ public class SettingsUtils {
return builder.build(); 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);
}
} }