I'm writing a Spigot plugin for spawning crates. This JsonReader scans the treasure pool file for a specific setting that I request. Thing is, I didn't wanna copy the same while loop over and over again, so I just decided to make this.
It reads the first six tokens successfully, but it stops at token six, where the "max-axis" array stops. There isn't a comma there. It even reads it when I add a fourth number to the array, but stops at that number because there's no comma there. JsonReader.setLenient(true)
is used, and JsonWriter.setLenient(true)
is used for writing the file. I have tried setting the writer false.
The way this is written is weird, but it's all just for testing. No need to actually return values from the file right now.
PoolFile.scanDocument()
private Object scanDocument(JsonReader reader, Shell handleObj) {
reader.setLenient(true);
int retval = -2;
try {
JsonToken token = null; Object current = -5;
while (reader.hasNext()) {
token = reader.peek();
//if (token == JsonToken.END_DOCUMENT) break;
// Output while reading: 0 2 1 3 3 3
switch(token) {
case BEGIN_OBJECT: reader.beginObject(); retval = 0; break;
case BEGIN_ARRAY: reader.beginArray(); retval = 1; break;
case NAME: current = reader.nextName(); retval = 2; break;
case NUMBER: current = reader.nextDouble(); retval = 3; break;
case BOOLEAN: current = reader.nextBoolean(); retval = 4; break;
case STRING: current = reader.nextString(); retval = 5; break;
case END_ARRAY: reader.endArray(); retval = 6; break;
case END_OBJECT: reader.endObject(); retval = 7; break;
default: reader.skipValue(); retval = -1;
}
handleObj.doWithJSONObject(token, retval);
}
} catch (IOException e) { retval = -1; e.printStackTrace(); }
return retval;
}
defaultpool.json
{
"max-axis": [
50.0,
-1.0,
50.0 // It stops here.
],
"pools": [
{
"label": "test",
"items": {}
}
]
}
EDIT If you'd like to see the application, visit the GitHub page. Source is located under skycrates/src/main