Add custom data to all Entities instead of Factions only.
This commit is contained in:
parent
f4b3924dc3
commit
b9dd57b7e3
@ -21,6 +21,7 @@ import com.massivecraft.mcore.store.accessor.Accessor;
|
|||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
import com.massivecraft.mcore.xlib.gson.Gson;
|
import com.massivecraft.mcore.xlib.gson.Gson;
|
||||||
import com.massivecraft.mcore.xlib.gson.JsonElement;
|
import com.massivecraft.mcore.xlib.gson.JsonElement;
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonObject;
|
||||||
import com.massivecraft.mcore.xlib.gson.JsonSyntaxException;
|
import com.massivecraft.mcore.xlib.gson.JsonSyntaxException;
|
||||||
|
|
||||||
public class Coll<E> implements CollInterface<E>
|
public class Coll<E> implements CollInterface<E>
|
||||||
@ -180,6 +181,17 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// COPY AND CREATE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -196,6 +208,7 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
Entity eto = (Entity)oto;
|
Entity eto = (Entity)oto;
|
||||||
|
|
||||||
eto.load(efrom);
|
eto.load(efrom);
|
||||||
|
eto.setCustomData(efrom.getCustomData());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -480,7 +493,7 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass());
|
JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass());
|
||||||
this.lastRaw.put(id, raw);
|
this.lastRaw.put(id, raw);
|
||||||
|
|
||||||
if (this.isDefault(entity))
|
if (this.isDefault(entity) && isCustomDataDefault(entity))
|
||||||
{
|
{
|
||||||
this.db.getDriver().delete(this, id);
|
this.db.getDriver().delete(this, id);
|
||||||
this.lastDefault.add(id);
|
this.lastDefault.add(id);
|
||||||
|
@ -4,6 +4,7 @@ import com.massivecraft.mcore.MCore;
|
|||||||
import com.massivecraft.mcore.NaturalOrderComparator;
|
import com.massivecraft.mcore.NaturalOrderComparator;
|
||||||
import com.massivecraft.mcore.store.accessor.Accessor;
|
import com.massivecraft.mcore.store.accessor.Accessor;
|
||||||
import com.massivecraft.mcore.xlib.gson.Gson;
|
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
|
* Usage of this class is highly optional. You may persist anything. If you are
|
||||||
@ -35,6 +36,17 @@ public abstract class Entity<E extends Entity<E>> implements Comparable<E>
|
|||||||
return coll.getUniverse();
|
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
|
// ATTACH AND DETACH
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user