Commit 86035a2477f8fd783049886c585abc37e364cbdf
1 parent
cc2a64ee
Quality of life tweaks to CloudConfig
Showing
2 changed files
with
24 additions
and
7 deletions
src/client/java/com/mumfrey/liteloader/modconfig/CloudConfig.java
... | ... | @@ -67,7 +67,7 @@ public abstract class CloudConfig |
67 | 67 | /** |
68 | 68 | * Same as normal key pattern except that $ gets translated to . for key |
69 | 69 | */ |
70 | - private static final Pattern keyPattern = Pattern.compile("^[a-z0-9_\\-\\$]{1,32}$"); | |
70 | + private static final Pattern keyPattern = Pattern.compile("(?i)^[a-z0-9_\\-\\$]{1,32}$"); | |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * A field value tracker |
... | ... | @@ -85,7 +85,7 @@ public abstract class CloudConfig |
85 | 85 | TrackedField(Field handle) |
86 | 86 | { |
87 | 87 | this.handle = handle; |
88 | - this.name = handle.getName().replace("$", "."); | |
88 | + this.name = handle.getName().replace("$", ".").toLowerCase(); | |
89 | 89 | } |
90 | 90 | |
91 | 91 | @SuppressWarnings("unchecked") |
... | ... | @@ -139,6 +139,14 @@ public abstract class CloudConfig |
139 | 139 | } |
140 | 140 | else if (value != this.localValue && value != null) |
141 | 141 | { |
142 | + if (value.length() > 255) | |
143 | + { | |
144 | + LiteLoaderLogger.warning("Unable to synchronise setting [%s], length > 255 chars. The value will be truncated!", this.name); | |
145 | + value = value.substring(0, 255); | |
146 | + this.<String>setValue(value); | |
147 | + this.isDirty(); | |
148 | + } | |
149 | + | |
142 | 150 | CloudConfig.this.preferences.set(this.name, value); |
143 | 151 | } |
144 | 152 | else if (CloudConfig.this.preferences.has(this.name)) |
... | ... | @@ -147,7 +155,7 @@ public abstract class CloudConfig |
147 | 155 | if (value != remoteValue) |
148 | 156 | { |
149 | 157 | value = remoteValue; |
150 | - this.setValue(value); | |
158 | + this.<String>setValue(value); | |
151 | 159 | } |
152 | 160 | } |
153 | 161 | |
... | ... | @@ -185,7 +193,7 @@ public abstract class CloudConfig |
185 | 193 | if (value != remoteValue) |
186 | 194 | { |
187 | 195 | value = remoteValue; |
188 | - this.setValue(value); | |
196 | + this.<Integer>setValue(value); | |
189 | 197 | } |
190 | 198 | } |
191 | 199 | |
... | ... | @@ -235,7 +243,7 @@ public abstract class CloudConfig |
235 | 243 | if (value != remoteValue) |
236 | 244 | { |
237 | 245 | value = remoteValue; |
238 | - this.setValue(value); | |
246 | + this.<Float>setValue(value); | |
239 | 247 | } |
240 | 248 | } |
241 | 249 | |
... | ... | @@ -282,16 +290,22 @@ public abstract class CloudConfig |
282 | 290 | } |
283 | 291 | else if (CloudConfig.this.preferences.has(this.name)) |
284 | 292 | { |
285 | - boolean remoteValue = "true".equals(CloudConfig.this.preferences.get(this.name)); | |
293 | + boolean remoteValue = this.tryParse(CloudConfig.this.preferences.get(this.name), value); | |
286 | 294 | if (value != remoteValue) |
287 | 295 | { |
288 | 296 | value = remoteValue; |
289 | - this.setValue(value); | |
297 | + this.<Boolean>setValue(value); | |
290 | 298 | } |
291 | 299 | } |
292 | 300 | |
293 | 301 | this.localValue = value; |
294 | 302 | } |
303 | + | |
304 | + private boolean tryParse(String string, boolean value) | |
305 | + { | |
306 | + boolean isTrue = "true".equals(string); | |
307 | + return (isTrue || "false".equals(string)) ? isTrue : value; | |
308 | + } | |
295 | 309 | } |
296 | 310 | |
297 | 311 | static final class UpdateTicker implements InitCompleteListener |
... | ... | @@ -474,11 +488,13 @@ public abstract class CloudConfig |
474 | 488 | if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers)) |
475 | 489 | { |
476 | 490 | LiteLoaderLogger.debug("Skipping transient field %s in %s", field.getName(), this.getClass().getName()); |
491 | + continue; | |
477 | 492 | } |
478 | 493 | |
479 | 494 | if (!CloudConfig.keyPattern.matcher(field.getName()).matches()) |
480 | 495 | { |
481 | 496 | LiteLoaderLogger.warning("Skipping field with invalid name %s in %s", field.getName(), this.getClass().getName()); |
497 | + continue; | |
482 | 498 | } |
483 | 499 | |
484 | 500 | Class<?> type = field.getType(); | ... | ... |
src/main/java/com/mumfrey/liteloader/core/LiteLoaderMods.java