From 5d7f14c21f486d13651c8f143c8862f6bfc864ba Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 24 Oct 2019 18:11:18 -0400 Subject: [PATCH] Better error messages --- .../io/anuke/mindustry/mod/ContentParser.java | 18 +++++++++++++++--- gradle.properties | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/io/anuke/mindustry/mod/ContentParser.java b/core/src/io/anuke/mindustry/mod/ContentParser.java index c19c22733c..a8b0d4b2d0 100644 --- a/core/src/io/anuke/mindustry/mod/ContentParser.java +++ b/core/src/io/anuke/mindustry/mod/ContentParser.java @@ -128,11 +128,11 @@ public class ContentParser{ block = Vars.content.getByName(ContentType.block, name); if(value.has("type")){ - throw new IllegalArgumentException("When overwriting an existing block, you must not re-declared its type. The original type will be used. Block: " + name); + throw new IllegalArgumentException("When overwriting an existing block, you must not re-declare its type. The original type will be used. Block: " + name); } }else{ //TODO generate dynamically instead of doing.. this - Class type = resolve(value.getString("type"), + Class type = resolve(getType(value), "io.anuke.mindustry.world", "io.anuke.mindustry.world.blocks", "io.anuke.mindustry.world.blocks.defense", @@ -209,7 +209,7 @@ public class ContentParser{ ContentType.unit, (TypeParser)(mod, name, value) -> { readBundle(ContentType.unit, name, value); - Class type = resolve(value.getString("type"), "io.anuke.mindustry.entities.type.base"); + Class type = resolve(getType(value), "io.anuke.mindustry.entities.type.base"); UnitType unit = new UnitType(mod + "-" + name, supply(type)); currentContent = unit; read(() -> readFields(unit, value, true)); @@ -222,6 +222,18 @@ public class ContentParser{ ContentType.zone, parser(ContentType.zone, Zone::new) ); + private String getString(JsonValue value, String key){ + if(value.has(key)){ + return value.getString(key); + }else{ + throw new IllegalArgumentException((currentContent == null ? "" : currentContent.sourceFile + ": ") + "You are missing a \"" + key + "\". It must be added before the file can be parsed."); + } + } + + private String getType(JsonValue value){ + return getString(value, "type"); + } + private T find(ContentType type, String name){ Content c = Vars.content.getByName(type, name); if(c == null) c = Vars.content.getByName(type, currentMod.name + "-" + name); diff --git a/gradle.properties b/gradle.properties index 7c8749e926..cbc49eb9de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=411d2784f538dfc10db2962a62833938029dafdd +archash=6ca636f2f51352022b2c770deafc3b549eb0421c