@Override protected EntityData deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException { final String codeName = fields.getAndRemoveObject("codeName", String.class); if (codeName == null) throw new StreamCorruptedException(); final EntityDataInfo<?> info = getInfo(codeName); if (info == null) throw new StreamCorruptedException("Invalid EntityData code name " + codeName); try { final EntityData<?> d = info.c.newInstance(); d.deserialize(fields); return d; } catch (final InstantiationException e) { Skript.exception(e); } catch (final IllegalAccessException e) { Skript.exception(e); } throw new StreamCorruptedException(); }
@Override public Fields serialize(final EntityData o) throws NotSerializableException { final Fields f = o.serialize(); f.putObject("codeName", o.info.codeName); return f; }
@Override public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException { fields.setFields(this); }