35 lines
1.4 KiB
Java
35 lines
1.4 KiB
Java
package io.gitlab.jfronny.inceptum.launcher.gson;
|
|
|
|
import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.mojang.Rules.GC_Rules;
|
|
import io.gitlab.jfronny.gson.JsonParseException;
|
|
import io.gitlab.jfronny.gson.compile.util.GList;
|
|
import io.gitlab.jfronny.gson.stream.*;
|
|
import io.gitlab.jfronny.inceptum.launcher.model.mojang.*;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
public class MinecraftArgumentAdapter {
|
|
public static void write(JsonWriter writer, MinecraftArgument rules) throws IOException {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public static MinecraftArgument read(JsonReader reader) throws IOException {
|
|
if (reader.peek() == JsonToken.STRING) return new MinecraftArgument(Set.of(reader.nextString()));
|
|
Rules rules = null;
|
|
List<String> value = null;
|
|
reader.beginObject();
|
|
while (reader.hasNext()) {
|
|
switch (reader.nextName()) {
|
|
case "rules" -> rules = GC_Rules.read(reader);
|
|
case "value" -> value = GList.read(reader, JsonReader::nextString);
|
|
}
|
|
}
|
|
reader.endObject();
|
|
if (rules == null || value == null) throw new JsonParseException("Not a valid minecraft argument");
|
|
if (!rules.allow()) return new MinecraftArgument(Set.of());
|
|
return new MinecraftArgument(Set.copyOf(value));
|
|
}
|
|
}
|