minecraft-source/src/com/mojang/realmsclient/dto/RealmsWorldOptions.java

117 lines
4.8 KiB
Java

package com.mojang.realmsclient.dto;
import java.util.Objects;
import net.minecraft.client.resources.language.I18n;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
public class RealmsWorldOptions extends ValueObject {
public Boolean pvp;
public Boolean spawnAnimals;
public Boolean spawnMonsters;
public Boolean spawnNPCs;
public Integer spawnProtection;
public Boolean commandBlocks;
public Boolean forceGameMode;
public Integer difficulty;
public Integer gameMode;
public String slotName;
public long templateId;
public String templateImage;
public boolean adventureMap;
public boolean empty;
private static final String DEFAULT_TEMPLATE_IMAGE;
public RealmsWorldOptions(final Boolean boolean1, final Boolean boolean2, final Boolean boolean3, final Boolean boolean4, final Integer integer5, final Boolean boolean6, final Integer integer7, final Integer integer8, final Boolean boolean9, final String string) {
this.pvp = boolean1;
this.spawnAnimals = boolean2;
this.spawnMonsters = boolean3;
this.spawnNPCs = boolean4;
this.spawnProtection = integer5;
this.commandBlocks = boolean6;
this.difficulty = integer7;
this.gameMode = integer8;
this.forceGameMode = boolean9;
this.slotName = string;
}
public static RealmsWorldOptions createDefaults() {
return new RealmsWorldOptions(true, true, true, true, 0, false, 2, 0, false, "");
}
public static RealmsWorldOptions createEmptyDefaults() {
final RealmsWorldOptions div1 = createDefaults();
div1.setEmpty(true);
return div1;
}
public void setEmpty(final boolean boolean1) {
this.empty = boolean1;
}
public static RealmsWorldOptions parse(final JsonObject jsonObject) {
final RealmsWorldOptions div2 = new RealmsWorldOptions(JsonUtils.getBooleanOr("pvp", jsonObject, true), JsonUtils.getBooleanOr("spawnAnimals", jsonObject, true), JsonUtils.getBooleanOr("spawnMonsters", jsonObject, true), JsonUtils.getBooleanOr("spawnNPCs", jsonObject, true), JsonUtils.getIntOr("spawnProtection", jsonObject, 0), JsonUtils.getBooleanOr("commandBlocks", jsonObject, false), JsonUtils.getIntOr("difficulty", jsonObject, 2), JsonUtils.getIntOr("gameMode", jsonObject, 0), JsonUtils.getBooleanOr("forceGameMode", jsonObject, false), JsonUtils.getStringOr("slotName", jsonObject, ""));
div2.templateId = JsonUtils.getLongOr("worldTemplateId", jsonObject, -1L);
div2.templateImage = JsonUtils.getStringOr("worldTemplateImage", jsonObject, RealmsWorldOptions.DEFAULT_TEMPLATE_IMAGE);
div2.adventureMap = JsonUtils.getBooleanOr("adventureMap", jsonObject, false);
return div2;
}
public String getSlotName(final int integer) {
if (this.slotName != null && !this.slotName.isEmpty()) {
return this.slotName;
}
if (this.empty) {
return I18n.get("mco.configure.world.slot.empty");
}
return this.getDefaultSlotName(integer);
}
public String getDefaultSlotName(final int integer) {
return I18n.get("mco.configure.world.slot", integer);
}
public String toJson() {
final JsonObject jsonObject2 = new JsonObject();
if (!this.pvp) {
jsonObject2.addProperty("pvp", this.pvp);
}
if (!this.spawnAnimals) {
jsonObject2.addProperty("spawnAnimals", this.spawnAnimals);
}
if (!this.spawnMonsters) {
jsonObject2.addProperty("spawnMonsters", this.spawnMonsters);
}
if (!this.spawnNPCs) {
jsonObject2.addProperty("spawnNPCs", this.spawnNPCs);
}
if (this.spawnProtection != 0) {
jsonObject2.addProperty("spawnProtection", this.spawnProtection);
}
if (this.commandBlocks) {
jsonObject2.addProperty("commandBlocks", this.commandBlocks);
}
if (this.difficulty != 2) {
jsonObject2.addProperty("difficulty", this.difficulty);
}
if (this.gameMode != 0) {
jsonObject2.addProperty("gameMode", this.gameMode);
}
if (this.forceGameMode) {
jsonObject2.addProperty("forceGameMode", this.forceGameMode);
}
if (!Objects.equals(this.slotName, "")) {
jsonObject2.addProperty("slotName", this.slotName);
}
return jsonObject2.toString();
}
public RealmsWorldOptions clone() {
return new RealmsWorldOptions(this.pvp, this.spawnAnimals, this.spawnMonsters, this.spawnNPCs, this.spawnProtection, this.commandBlocks, this.difficulty, this.gameMode, this.forceGameMode, this.slotName);
}
static {
DEFAULT_TEMPLATE_IMAGE = null;
}
}