From 7991ea2c1fa6164452f28486237a7174b67ad20c Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:26:05 +0200 Subject: [PATCH] fix: Fix default keys not loading correctly, add some helpful logging --- .../defaultoptions/keys/KeyMappingDefaultsHandler.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/net/blay09/mods/defaultoptions/keys/KeyMappingDefaultsHandler.java b/common/src/main/java/net/blay09/mods/defaultoptions/keys/KeyMappingDefaultsHandler.java index 457cf6b..2c3a79c 100644 --- a/common/src/main/java/net/blay09/mods/defaultoptions/keys/KeyMappingDefaultsHandler.java +++ b/common/src/main/java/net/blay09/mods/defaultoptions/keys/KeyMappingDefaultsHandler.java @@ -19,7 +19,7 @@ public class KeyMappingDefaultsHandler implements DefaultOptionsHandler { - private static final Pattern KEY_PATTERN = Pattern.compile("key_([^:]+):([^:]+)(?::(.+))?"); + private static final Pattern KEY_PATTERN = Pattern.compile("key_([^:]+):([^:]+)(?::(.+)?)?"); private static final Map defaultKeys = new HashMap<>(); private static final List knownKeys = new ArrayList<>(); @@ -56,7 +56,7 @@ public void saveCurrentOptionsAsDefault() { .map(KeyModifier::name) .collect(Collectors.joining(","))); } - } catch (IOException e) { + } catch (Exception e) { DefaultOptions.logger.error("Failed to save default key mappings", e); } @@ -117,11 +117,13 @@ public void loadDefaults() { knownKeys.add(line); } } - } catch (IOException e) { + } catch (Exception e) { DefaultOptions.logger.error("Error loading known key bindings", e); } } + DefaultOptions.logger.info("Found {} default keys and {} known keys", defaultKeys.size(), knownKeys.size()); + // Override the default mappings and set the initial key codes, if the key is not known yet for (KeyMapping keyMapping : Minecraft.getInstance().options.keyMappings) { if (defaultKeys.containsKey(keyMapping.getName())) {