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);
}
}
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations