/*
 * Copyright 2018 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.config;

import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.terasology.engine.TerasologyConstants;
import org.terasology.world.internal.WorldInfo;

import java.lang.reflect.Type;
import java.util.List;

public class UniverseConfig {
    private List<WorldInfo> worlds = Lists.newArrayList();
    private WorldInfo spawnWorld;
    private String universeSeed;

    public UniverseConfig() {
        worlds.clear();
    }

    public void addWorldManager(WorldInfo worldManager) {
        if (worldManager.getTitle().equals(TerasologyConstants.MAIN_WORLD)) {
            worlds.clear();
            this.spawnWorld = worldManager;
        }
        worlds.add(worldManager);
    }

    public void setSpawnWorld(WorldInfo targetWorld) {
        spawnWorld = targetWorld;
    }

    public void setUniverseSeed(String seed) {
        universeSeed = seed;
    }

//    static class Handler implements JsonSerializer<UniverseConfig>, JsonDeserializer<UniverseConfig> {
//
//        private static final String WORLDS = "worlds";
//        private static final String SPAWN_WORLD = "spawnWorld";
//        private static final String UNIVERSE_SEED = "universeSeed";
//
//        @Override
//        public UniverseConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
//            UniverseConfig result = new UniverseConfig();
//            JsonObject jsonObject = json.getAsJsonObject();
//            if (jsonObject.has(WORLDS)) {
//                JsonArray worldsArray = jsonObject.getAsJsonArray(WORLDS);
//                for (JsonElement jsonElement : worldsArray) {
//                    WorldInfo worldInfo = context.deserialize(jsonElement, WorldInfo.class);
//                    result.addWorldManager(worldInfo);
//                }
//            }
//            if (jsonObject.has(SPAWN_WORLD)) {
//                result.spawnWorld = context.deserialize(jsonObject.getAsJsonObject(SPAWN_WORLD), WorldInfo.class);
//            }
//            if (jsonObject.has(UNIVERSE_SEED)) {
//                result.universeSeed = context.deserialize(jsonObject.getAsJsonObject(UNIVERSE_SEED), String.class);
//            }
//            return result;
//        }
//
//        @Override
//        public JsonElement serialize(UniverseConfig src, Type typeOfBindsConfig, JsonSerializationContext context) {
//            JsonObject result = new JsonObject();
//            result.add(WORLDS, context.serialize(src.worlds));
//            result.add(SPAWN_WORLD, context.serialize(src.spawnWorld));
//            result.add(UNIVERSE_SEED, context.serialize(src.universeSeed));
//            return result;
//        }
//    }
}

@@ -666,336 +666,8 @@
 ts;%0A
-import com.google.gson.JsonArray;%0Aimport com.google.gson.JsonDeserializationContext;%0Aimport com.google.gson.JsonDeserializer;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParseException;%0Aimport com.google.gson.JsonSerializationContext;%0Aimport com.google.gson.JsonSerializer;%0A
 impo
@@ -708,24 +708,24 @@
 yConstants;%0A
+
 import org.t
@@ -765,39 +765,8 @@
 o;%0A%0A
-import java.lang.reflect.Type;%0A
 impo
@@ -1445,1833 +1445,6 @@
  %7D%0A%0A
-//    static class Handler implements JsonSerializer%3CUniverseConfig%3E, JsonDeserializer%3CUniverseConfig%3E %7B%0A//%0A//        private static final String WORLDS = %22worlds%22;%0A//        private static final String SPAWN_WORLD = %22spawnWorld%22;%0A//        private static final String UNIVERSE_SEED = %22universeSeed%22;%0A//%0A//        @Override%0A//        public UniverseConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException %7B%0A//            UniverseConfig result = new UniverseConfig();%0A//            JsonObject jsonObject = json.getAsJsonObject();%0A//            if (jsonObject.has(WORLDS)) %7B%0A//                JsonArray worldsArray = jsonObject.getAsJsonArray(WORLDS);%0A//                for (JsonElement jsonElement : worldsArray) %7B%0A//                    WorldInfo worldInfo = context.deserialize(jsonElement, WorldInfo.class);%0A//                    result.addWorldManager(worldInfo);%0A//                %7D%0A//            %7D%0A//            if (jsonObject.has(SPAWN_WORLD)) %7B%0A//                result.spawnWorld = context.deserialize(jsonObject.getAsJsonObject(SPAWN_WORLD), WorldInfo.class);%0A//            %7D%0A//            if (jsonObject.has(UNIVERSE_SEED)) %7B%0A//                result.universeSeed = context.deserialize(jsonObject.getAsJsonObject(UNIVERSE_SEED), String.class);%0A//            %7D%0A//            return result;%0A//        %7D%0A//%0A//        @Override%0A//        public JsonElement serialize(UniverseConfig src, Type typeOfBindsConfig, JsonSerializationContext context) %7B%0A//            JsonObject result = new JsonObject();%0A//            result.add(WORLDS, context.serialize(src.worlds));%0A//            result.add(SPAWN_WORLD, context.serialize(src.spawnWorld));%0A//            result.add(UNIVERSE_SEED, context.serialize(src.universeSeed));%0A//            return result;%0A//        %7D%0A//    %7D%0A
 %7D%0A

Remove redundant comments