ArrayList<Mob> getMobs() { ArrayList<Mob> realMobs = new ArrayList<Mob>(); for (JsonMob jm : mobs) { Mob xyz = null; Class<?> cl; try { cl = Class.forName(jm.getName()); Constructor<?> con = cl.getConstructor(float.class, float.class); xyz = (Mob) con.newInstance(jm.getX(), jm.getY()); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } xyz.setID(jm.getID()); realMobs.add(xyz); } return realMobs; }
public void setMobs(ArrayList<Mob> realMobs) { for (Mob m : realMobs) { JsonMob jm = new JsonMob(m.getX(), m.getY(), m.getClass().getName()); jm.setID(m.getID()); mobs.add(jm); } }