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.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<String> 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) {

View File

@ -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;

View File

@ -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);
}
}