Commit 86035a2477f8fd783049886c585abc37e364cbdf

Authored by Mumfrey
1 parent cc2a64ee

Quality of life tweaks to CloudConfig

src/client/java/com/mumfrey/liteloader/modconfig/CloudConfig.java
@@ -67,7 +67,7 @@ public abstract class CloudConfig @@ -67,7 +67,7 @@ public abstract class CloudConfig
67 /** 67 /**
68 * Same as normal key pattern except that $ gets translated to . for key 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 * A field value tracker 73 * A field value tracker
@@ -85,7 +85,7 @@ public abstract class CloudConfig @@ -85,7 +85,7 @@ public abstract class CloudConfig
85 TrackedField(Field handle) 85 TrackedField(Field handle)
86 { 86 {
87 this.handle = handle; 87 this.handle = handle;
88 - this.name = handle.getName().replace("$", "."); 88 + this.name = handle.getName().replace("$", ".").toLowerCase();
89 } 89 }
90 90
91 @SuppressWarnings("unchecked") 91 @SuppressWarnings("unchecked")
@@ -139,6 +139,14 @@ public abstract class CloudConfig @@ -139,6 +139,14 @@ public abstract class CloudConfig
139 } 139 }
140 else if (value != this.localValue && value != null) 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 CloudConfig.this.preferences.set(this.name, value); 150 CloudConfig.this.preferences.set(this.name, value);
143 } 151 }
144 else if (CloudConfig.this.preferences.has(this.name)) 152 else if (CloudConfig.this.preferences.has(this.name))
@@ -147,7 +155,7 @@ public abstract class CloudConfig @@ -147,7 +155,7 @@ public abstract class CloudConfig
147 if (value != remoteValue) 155 if (value != remoteValue)
148 { 156 {
149 value = remoteValue; 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,7 +193,7 @@ public abstract class CloudConfig
185 if (value != remoteValue) 193 if (value != remoteValue)
186 { 194 {
187 value = remoteValue; 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,7 +243,7 @@ public abstract class CloudConfig
235 if (value != remoteValue) 243 if (value != remoteValue)
236 { 244 {
237 value = remoteValue; 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,16 +290,22 @@ public abstract class CloudConfig
282 } 290 }
283 else if (CloudConfig.this.preferences.has(this.name)) 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 if (value != remoteValue) 294 if (value != remoteValue)
287 { 295 {
288 value = remoteValue; 296 value = remoteValue;
289 - this.setValue(value); 297 + this.<Boolean>setValue(value);
290 } 298 }
291 } 299 }
292 300
293 this.localValue = value; 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 static final class UpdateTicker implements InitCompleteListener 311 static final class UpdateTicker implements InitCompleteListener
@@ -474,11 +488,13 @@ public abstract class CloudConfig @@ -474,11 +488,13 @@ public abstract class CloudConfig
474 if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers)) 488 if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers))
475 { 489 {
476 LiteLoaderLogger.debug("Skipping transient field %s in %s", field.getName(), this.getClass().getName()); 490 LiteLoaderLogger.debug("Skipping transient field %s in %s", field.getName(), this.getClass().getName());
  491 + continue;
477 } 492 }
478 493
479 if (!CloudConfig.keyPattern.matcher(field.getName()).matches()) 494 if (!CloudConfig.keyPattern.matcher(field.getName()).matches())
480 { 495 {
481 LiteLoaderLogger.warning("Skipping field with invalid name %s in %s", field.getName(), this.getClass().getName()); 496 LiteLoaderLogger.warning("Skipping field with invalid name %s in %s", field.getName(), this.getClass().getName());
  497 + continue;
482 } 498 }
483 499
484 Class<?> type = field.getType(); 500 Class<?> type = field.getType();
src/main/java/com/mumfrey/liteloader/core/LiteLoaderMods.java
@@ -465,6 +465,7 @@ public class LiteLoaderMods @@ -465,6 +465,7 @@ public class LiteLoaderMods
465 } 465 }
466 catch (Throwable th) 466 catch (Throwable th)
467 { 467 {
  468 + th.printStackTrace();
468 this.onModLoadFailed(container, mod.getModClassName(), "an error occurred", th); 469 this.onModLoadFailed(container, mod.getModClassName(), "an error occurred", th);
469 this.registerModStartupError(mod, th); 470 this.registerModStartupError(mod, th);
470 } 471 }