1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-23 12:05:44 +01:00

Reduce game arguments to strings where possible

Helps to reduce the size of the manifest a little, and looks nicer!
This commit is contained in:
Henry Le Grys 2021-01-26 01:11:02 +00:00
parent ec7b1ac2ae
commit f880192919
2 changed files with 28 additions and 0 deletions

View File

@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.skcraft.launcher.model.minecraft.mapper.MinecraftArgumentsDeserializer;
import com.skcraft.launcher.model.minecraft.mapper.MinecraftArgumentsSerializer;
import lombok.Data;
import java.util.List;
@ -14,11 +16,13 @@ import java.util.List;
public class MinecraftArguments {
@JsonProperty("game")
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
@JsonSerialize(contentUsing = MinecraftArgumentsSerializer.class)
@JsonDeserialize(contentUsing = MinecraftArgumentsDeserializer.class)
private List<GameArgument> gameArguments;
@JsonProperty("jvm")
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
@JsonSerialize(contentUsing = MinecraftArgumentsSerializer.class)
@JsonDeserialize(contentUsing = MinecraftArgumentsDeserializer.class)
private List<GameArgument> jvmArguments;
}

View File

@ -0,0 +1,24 @@
package com.skcraft.launcher.model.minecraft.mapper;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.skcraft.launcher.model.minecraft.GameArgument;
import java.io.IOException;
public class MinecraftArgumentsSerializer extends StdSerializer<GameArgument> {
protected MinecraftArgumentsSerializer() {
super(GameArgument.class);
}
@Override
public void serialize(GameArgument value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
if (value.getValues().size() == 1 && (value.getRules() == null || value.getRules().size() == 0)) {
jgen.writeString(value.getValues().get(0));
} else {
provider.defaultSerializeValue(value, jgen);
}
}
}