From dbb79ba297e457a783814605efb5d8cc96c34f3c Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Fri, 15 May 2015 14:34:29 +0200 Subject: [PATCH] Remove custom data in MStore --- .../massivecraft/massivecore/store/Coll.java | 24 ++++++------------- .../massivecore/store/Entity.java | 12 ---------- .../massivecore/store/Modification.java | 12 ++++++++++ .../massivecore/store/SenderColl.java | 1 + 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index 5452a1be..b4111b49 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -197,18 +197,7 @@ public class Coll implements CollInterface return false; } } - - // This is used in parallel with the isDefault. - // Parallel usage is useful since we can then override isDeafult just like before. - public static boolean isCustomDataDefault(Object entity) - { - if (!(entity instanceof Entity)) return true; - JsonObject customData = ((Entity)entity).getCustomData(); - if (customData == null) return true; - if (customData.entrySet().size() == 0) return true; - return false; - } - + // -------------------------------------------- // // COPY AND CREATE // -------------------------------------------- // @@ -225,7 +214,6 @@ public class Coll implements CollInterface Entity eto = (Entity)oto; eto.load(efrom); - eto.setCustomData(efrom.getCustomData()); } else if (ofrom instanceof JsonObject) { @@ -450,7 +438,8 @@ public class Coll implements CollInterface // -------------------------------------------- // // SYNCLOG // -------------------------------------------- // - + + // The strings are the ids. protected Map lastMtime; protected Map lastRaw; protected Set lastDefault; @@ -547,7 +536,7 @@ public class Coll implements CollInterface JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass()); this.lastRaw.put(id, raw); - if (this.isDefault(entity) && isCustomDataDefault(entity)) + if (this.isDefault(entity)) { this.getDb().delete(this, id); this.lastDefault.add(id); @@ -658,9 +647,9 @@ public class Coll implements CollInterface { // Fix Id if (oid == null) throw new NullPointerException("oid"); - String id = this.fixId(oid); + //String id = this.fixId(oid); // Was done twice - return this.examineId(id, null); + return this.examineId(oid, null); } @Override @@ -684,6 +673,7 @@ public class Coll implements CollInterface E localEntity = this.id2entity.get(id); if (remoteMtime == null) { + // TODO: This is slow remoteMtime = this.getDb().getMtime(this, id); } diff --git a/src/com/massivecraft/massivecore/store/Entity.java b/src/com/massivecraft/massivecore/store/Entity.java index 2ca1a636..6d0df5e8 100644 --- a/src/com/massivecraft/massivecore/store/Entity.java +++ b/src/com/massivecraft/massivecore/store/Entity.java @@ -4,7 +4,6 @@ import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.NaturalOrderComparator; import com.massivecraft.massivecore.store.accessor.Accessor; import com.massivecraft.massivecore.xlib.gson.Gson; -import com.massivecraft.massivecore.xlib.gson.JsonObject; /** * Usage of this class is highly optional. You may persist anything. If you are @@ -36,17 +35,6 @@ public abstract class Entity> implements Comparable return coll.getUniverse(); } - // -------------------------------------------- // - // CUSTOM DATA - // -------------------------------------------- // - // We offer custom data storage for all entities extending this class. - // Do you want to use this in your plugin? - // Make sure you don't overwrites some other plugins data! - - private JsonObject customData = null; - public JsonObject getCustomData() { return this.customData; } - public void setCustomData(JsonObject customData) { this.customData = customData; } - // -------------------------------------------- // // ATTACH AND DETACH // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/store/Modification.java b/src/com/massivecraft/massivecore/store/Modification.java index 812d4422..3d0a5167 100644 --- a/src/com/massivecraft/massivecore/store/Modification.java +++ b/src/com/massivecraft/massivecore/store/Modification.java @@ -2,6 +2,10 @@ package com.massivecraft.massivecore.store; public enum Modification { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + LOCAL_ALTER (true, true), LOCAL_ATTACH (true, true), LOCAL_DETACH (true, true), @@ -12,6 +16,10 @@ public enum Modification UNKNOWN (false, false), ; + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + private final boolean modified; public boolean isModified() { return this.modified; } @@ -19,6 +27,10 @@ public enum Modification public boolean isLocal() { return this.local; } public boolean isRemote() { return this.local == false; } + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + private Modification(boolean modified, boolean local) { this.modified = modified; diff --git a/src/com/massivecraft/massivecore/store/SenderColl.java b/src/com/massivecraft/massivecore/store/SenderColl.java index f94a3b86..7582f46f 100644 --- a/src/com/massivecraft/massivecore/store/SenderColl.java +++ b/src/com/massivecraft/massivecore/store/SenderColl.java @@ -128,6 +128,7 @@ public class SenderColl> extends Coll implements Se // GET ALL ONLINE / OFFLINE // -------------------------------------------- // + // TODO: Stop mkaing a new predicate everytime. public Collection getAllOnline() { return this.getAll(new Predictate()