diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index 420a33c9..696055b2 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -528,6 +528,10 @@ public class Coll> extends CollAbstract // Then attach! this.attach(entity, id, false); + + // On creation it might be modified by addition or removal of new/old fields. + // So we must do a check for that. + entity.changed(); } entity.setLastRaw(raw); @@ -782,7 +786,6 @@ public class Coll> extends CollAbstract @Override public void identifyModifications(Modification veto) { - // Get remote id2mtime snapshot Map id2RemoteMtime = this.getDb().getId2mtime(this); @@ -960,7 +963,7 @@ public class Coll> extends CollAbstract @Override public void init() { - if (this.inited()) return; // TODO: Would throwing an exception make more sense? + if (this.inited()) throw new IllegalStateException("Already initialised."); if (this.supportsPusher()) { @@ -968,7 +971,7 @@ public class Coll> extends CollAbstract } this.initLoadAllFromRemote(); - // this.syncAll(); + this.syncIdentified(); name2instance.put(this.getName(), this); } @@ -976,7 +979,7 @@ public class Coll> extends CollAbstract @Override public void deinit() { - if ( ! this.inited()) return; // TODO: Would throwing an exception make more sense? + if ( ! this.inited()) throw new IllegalStateException("Not initialised."); if (this.supportsPusher()) { diff --git a/src/com/massivecraft/massivecore/store/IndexUniqueField.java b/src/com/massivecraft/massivecore/store/IndexUniqueField.java index 8329947e..6d7a22ff 100644 --- a/src/com/massivecraft/massivecore/store/IndexUniqueField.java +++ b/src/com/massivecraft/massivecore/store/IndexUniqueField.java @@ -1,70 +1,70 @@ -package com.massivecraft.massivecore.store; - -import java.util.HashMap; -import java.util.Map; - -public class IndexUniqueField -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private Map f2o; - private Map o2f; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public IndexUniqueField(Map map) - { - this.f2o = map; - this.o2f = new HashMap(); - } - - // -------------------------------------------- // - // STUFF - // -------------------------------------------- // - - public void update(O object, F field) - { - if (object == null) return; - if (field == null) return; - - this.f2o.put(field, object); - this.o2f.put(object, field); - } - - public O removeField(F field) - { - if (field == null) return null; - - O object = this.f2o.remove(field); - if (object != null) this.o2f.remove(object); - return object; - } - - public F removeObject(O object) - { - if (object == null) return null; - - F field = this.o2f.remove(object); - if (field != null) this.f2o.remove(object); - return field; - } - - public O getObject(F field) - { - if (field == null) return null; - - return this.f2o.get(field); - } - - public F getField(O object) - { - if (object == null) return null; - - return this.o2f.get(object); - } - -} +package com.massivecraft.massivecore.store; + +import java.util.HashMap; +import java.util.Map; + +public class IndexUniqueField +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private Map f2o; + private Map o2f; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public IndexUniqueField(Map map) + { + this.f2o = map; + this.o2f = new HashMap(); + } + + // -------------------------------------------- // + // STUFF + // -------------------------------------------- // + + public void update(O object, F field) + { + if (object == null) return; + if (field == null) return; + + this.f2o.put(field, object); + this.o2f.put(object, field); + } + + public O removeField(F field) + { + if (field == null) return null; + + O object = this.f2o.remove(field); + if (object != null) this.o2f.remove(object); + return object; + } + + public F removeObject(O object) + { + if (object == null) return null; + + F field = this.o2f.remove(object); + if (field != null) this.f2o.remove(object); + return field; + } + + public O getObject(F field) + { + if (field == null) return null; + + return this.f2o.get(field); + } + + public F getField(O object) + { + if (object == null) return null; + + return this.o2f.get(object); + } + +}