Search in sources :

Example 66 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.

the class EffectJsonProcessor method process.

@Override
public EffectLayer process(JsonElement element) {
    final JsonObject effectDataJson = element.getAsJsonObject();
    ensureValuesExist(effectDataJson, "effectID", "key");
    String effectID = effectDataJson.get("effectID").getAsString();
    String key = effectDataJson.get("key").getAsString().toLowerCase();
    EffectLayer data = new EffectLayer(this, key, effectID);
    processAdditionalKeys(data, effectDataJson);
    return data;
}
Also used : JsonObject(com.google.gson.JsonObject)

Example 67 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.

the class JsonBlockListenerProcessor method process.

@Override
public void process(BlockBase block, JsonElement arrayElement, List<IJsonGenObject> objectList) {
    JsonArray array = arrayElement.getAsJsonArray();
    for (JsonElement element : array) {
        String key = null;
        JsonObject data = null;
        if (element.isJsonPrimitive()) {
            key = element.getAsString().toLowerCase();
        } else if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
            JsonProcessor.ensureValuesExist(object, "id");
            key = object.get("id").getAsString().toLowerCase();
            data = object;
        }
        if (builders.containsKey(key)) {
            ITileEventListener listener = builders.get(key).createListener(block);
            if (listener != null) {
                if (data != null) {
                    if (!injectionMaps.containsKey(listener.getClass())) {
                        injectionMaps.put(listener.getClass(), new JsonProcessorInjectionMap(listener.getClass()));
                    }
                    JsonProcessorInjectionMap injectionMap = injectionMaps.get(listener.getClass());
                    for (Map.Entry<String, JsonElement> entry : data.entrySet()) {
                        injectionMap.handle(listener, entry.getKey(), entry.getValue());
                    }
                }
                block.addListener(listener);
            }
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener) JsonObject(com.google.gson.JsonObject) JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) HashMap(java.util.HashMap) JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) Map(java.util.Map)

Example 68 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.

the class JsonBlockProcessor method process.

@Override
public boolean process(JsonElement element, List<IJsonGenObject> objectList) {
    debugPrinter.start("BlockProcessor", "Processing entry", Engine.runningAsDev);
    //Get object and ensure minimal keys exist
    JsonObject blockData = element.getAsJsonObject();
    ensureValuesExist(blockData, "name", "id", "mod");
    //Load default data
    String mod = blockData.getAsJsonPrimitive("mod").getAsString();
    String id = blockData.getAsJsonPrimitive("id").getAsString();
    String name = blockData.get("name").getAsString();
    debugPrinter.log("Name: " + name);
    debugPrinter.log("Mod: " + mod);
    debugPrinter.log("ID: " + id);
    //Generate object
    BlockPropertyData blockPropertyData = new BlockPropertyData(this, id, mod, name);
    //Load blocks
    BlockBase block;
    //Meta data loading
    if (blockData.has("subtypes")) {
        blockPropertyData.localization += "." + BlockMeta.META_LOCAL_KEY;
        block = new BlockMeta(blockPropertyData);
        //Call to load metadata
        readMeta((BlockMeta) block, blockData.get("subtypes").getAsJsonArray(), objectList);
    } else //No meta data
    {
        block = new BlockBase(blockPropertyData);
    }
    processAdditionalKeys(blockPropertyData, blockData, block, objectList);
    //Add block to object list
    objectList.add(block);
    debugPrinter.end("Done...");
    return true;
}
Also used : BlockPropertyData(com.builtbroken.mc.framework.block.BlockPropertyData) BlockBase(com.builtbroken.mc.framework.block.BlockBase) JsonObject(com.google.gson.JsonObject) BlockMeta(com.builtbroken.mc.framework.block.meta.BlockMeta)

Example 69 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.

the class JsonBlockProcessor method readMeta.

/**
     * Reads the meta data stored in the subtypes entry
     *
     * @param block - meta block, unregistered
     * @param array - array of subtypes
     */
public void readMeta(BlockMeta block, JsonArray array, List<IJsonGenObject> objectList) {
    //Loop every entry in the array, each entry should be meta values
    for (int i = 0; i < array.size() && i < 16; i++) {
        JsonObject json = array.get(i).getAsJsonObject();
        MetaData meta = new MetaData();
        //Reads the meta entry and then returns the meta to assign
        int m = readMetaEntry(block, meta, json, objectList);
        //Meta of -1 is invalid
        if (m != -1) {
            //Meta is locked to 0-15
            if (m >= 0 && m < 16) {
                //Prevent overriding by mistake
                if (block.metaDataValues[m] == null) {
                    meta.index = m;
                    block.metaDataValues[m] = meta;
                } else {
                    throw new IllegalArgumentException("JsonBlockProcessor: Meta value[" + m + "] was overridden inside the same file for block " + block.data.name);
                }
            } else {
                throw new IllegalArgumentException("JsonBlockProcessor: Meta values are restricted from 0 to 15");
            }
        } else {
            throw new IllegalArgumentException("JsonBlockProcessor: Each meta entry requires the value 'meta' of type Integer");
        }
    }
}
Also used : MetaData(com.builtbroken.mc.framework.block.meta.MetaData) JsonObject(com.google.gson.JsonObject)

Example 70 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.

the class JsonMissingMapEventProcessor method process.

@Override
public IJsonGenObject process(JsonElement element) {
    JsonObject data = element.getAsJsonObject();
    JsonProcessor.ensureValuesExist(data, "oldValue", "newValue");
    String oldValue = data.get("oldValue").getAsString().trim();
    String newValue = data.get("newValue").getAsString().trim();
    if (!oldValue.isEmpty() && !newValue.isEmpty()) {
        if (oldValue.contains(":") && newValue.contains(":")) {
            mappings.put(oldValue, newValue);
        } else {
            throw new IllegalArgumentException("Old and New value must contain : noting 'domain:name' ex: 'icbm:silo'");
        }
    } else {
        throw new IllegalArgumentException("Old and New value for missing mapping can not be empty");
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)5111 JsonArray (com.google.gson.JsonArray)1162 JsonElement (com.google.gson.JsonElement)1084 JsonParser (com.google.gson.JsonParser)710 Test (org.junit.Test)491 IOException (java.io.IOException)471 JsonPrimitive (com.google.gson.JsonPrimitive)387 ArrayList (java.util.ArrayList)376 Gson (com.google.gson.Gson)369 HashMap (java.util.HashMap)324 Map (java.util.Map)269 Test (org.testng.annotations.Test)208 Test (org.junit.jupiter.api.Test)201 File (java.io.File)146 List (java.util.List)142 InputStreamReader (java.io.InputStreamReader)135 JsonParseException (com.google.gson.JsonParseException)121 GsonBuilder (com.google.gson.GsonBuilder)93 JsonSyntaxException (com.google.gson.JsonSyntaxException)88 Nonnull (javax.annotation.Nonnull)87