diff --git a/src/com/massivecraft/mcore/store/Coll.java b/src/com/massivecraft/mcore/store/Coll.java index 71dd9426..b91ed21d 100644 --- a/src/com/massivecraft/mcore/store/Coll.java +++ b/src/com/massivecraft/mcore/store/Coll.java @@ -21,6 +21,7 @@ import com.massivecraft.mcore.store.accessor.Accessor; import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.xlib.gson.Gson; import com.massivecraft.mcore.xlib.gson.JsonElement; +import com.massivecraft.mcore.xlib.gson.JsonObject; import com.massivecraft.mcore.xlib.gson.JsonSyntaxException; public class Coll implements CollInterface @@ -180,6 +181,17 @@ public class Coll implements CollInterface } } + // 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 // -------------------------------------------- // @@ -196,6 +208,7 @@ public class Coll implements CollInterface Entity eto = (Entity)oto; eto.load(efrom); + eto.setCustomData(efrom.getCustomData()); } else { @@ -480,7 +493,7 @@ public class Coll implements CollInterface JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass()); this.lastRaw.put(id, raw); - if (this.isDefault(entity)) + if (this.isDefault(entity) && isCustomDataDefault(entity)) { this.db.getDriver().delete(this, id); this.lastDefault.add(id); diff --git a/src/com/massivecraft/mcore/store/Entity.java b/src/com/massivecraft/mcore/store/Entity.java index f805b358..62fb0b7a 100644 --- a/src/com/massivecraft/mcore/store/Entity.java +++ b/src/com/massivecraft/mcore/store/Entity.java @@ -4,6 +4,7 @@ import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.NaturalOrderComparator; import com.massivecraft.mcore.store.accessor.Accessor; import com.massivecraft.mcore.xlib.gson.Gson; +import com.massivecraft.mcore.xlib.gson.JsonObject; /** * Usage of this class is highly optional. You may persist anything. If you are @@ -35,6 +36,17 @@ 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 // -------------------------------------------- //