Search in sources :

Example 1 with JsonProcessorInjectionMap

use of com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap 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 2 with JsonProcessorInjectionMap

use of com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap in project Engine by VoltzEngine-Project.

the class TestProcessorInjection method testFloat.

@Test
public void testFloat() {
    JsonProcessorInjectionMap map = new JsonProcessorInjectionMap(InjectionTestClass.class);
    InjectionTestClass object = new InjectionTestClass();
    assertTrue(map.handle(object, "f", 1f));
    assertEquals(1f, object.f);
    assertTrue(map.handle(object, "f2", 2f));
    assertEquals(2f, object.f);
}
Also used : JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) Test(org.junit.Test)

Example 3 with JsonProcessorInjectionMap

use of com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap in project Engine by VoltzEngine-Project.

the class TestProcessorInjection method testLong.

@Test
public void testLong() {
    JsonProcessorInjectionMap map = new JsonProcessorInjectionMap(InjectionTestClass.class);
    InjectionTestClass object = new InjectionTestClass();
    assertTrue(map.handle(object, "l", 1l));
    assertEquals(1l, object.l);
    assertTrue(map.handle(object, "l2", 2l));
    assertEquals(2l, object.l);
}
Also used : JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) Test(org.junit.Test)

Example 4 with JsonProcessorInjectionMap

use of com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap in project Engine by VoltzEngine-Project.

the class TestProcessorInjection method testJsonDouble.

@Test
public void testJsonDouble() {
    JsonProcessorInjectionMap map = new JsonProcessorInjectionMap(InjectionTestClass.class);
    InjectionTestClass object = new InjectionTestClass();
    assertTrue(map.handle(object, "d", new JsonPrimitive(1.1)));
    assertEquals(1.1, object.d);
    assertTrue(map.handle(object, "d2", new JsonPrimitive(2.2)));
    assertEquals(2.2, object.d);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) Test(org.junit.Test)

Example 5 with JsonProcessorInjectionMap

use of com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap in project Engine by VoltzEngine-Project.

the class TestProcessorInjection method testJsonFloat.

@Test
public void testJsonFloat() {
    JsonProcessorInjectionMap map = new JsonProcessorInjectionMap(InjectionTestClass.class);
    InjectionTestClass object = new InjectionTestClass();
    assertTrue(map.handle(object, "f", new JsonPrimitive(1f)));
    assertEquals(1f, object.f);
    assertTrue(map.handle(object, "f2", new JsonPrimitive(2f)));
    assertEquals(2f, object.f);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) Test(org.junit.Test)

Aggregations

JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)19 Test (org.junit.Test)18 JsonPrimitive (com.google.gson.JsonPrimitive)7 JsonElement (com.google.gson.JsonElement)2 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1