Require Plugin only and not MPlugin in MStore.

This commit is contained in:
Olof Larsson 2013-04-11 07:19:05 +02:00
parent d4f30331ef
commit 95f1dc8dd0
7 changed files with 39 additions and 24 deletions

View File

@ -55,7 +55,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
// Collection shutdowns. // Collection shutdowns.
for (Coll<?, ?> coll : Coll.instances) for (Coll<?, ?> coll : Coll.instances)
{ {
if (coll.getMplugin() != this) continue; if (coll.getPlugin() != this) continue;
coll.examineThread().interrupt(); coll.examineThread().interrupt();
coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage... coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage...
Coll.instances.remove(coll); Coll.instances.remove(coll);

View File

@ -12,12 +12,15 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.plugin.Plugin;
import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.MPlugin; import com.massivecraft.mcore.MPlugin;
import com.massivecraft.mcore.Predictate; import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.store.accessor.Accessor; import com.massivecraft.mcore.store.accessor.Accessor;
import com.massivecraft.mcore.store.idstrategy.IdStrategy; import com.massivecraft.mcore.store.idstrategy.IdStrategy;
import com.massivecraft.mcore.store.storeadapter.StoreAdapter; import com.massivecraft.mcore.store.storeadapter.StoreAdapter;
import com.massivecraft.mcore.xlib.gson.Gson;
public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E, L> public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E, L>
{ {
@ -50,8 +53,19 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
// SUPPORTING SYSTEM // SUPPORTING SYSTEM
// -------------------------------------------- // // -------------------------------------------- //
protected MPlugin mplugin; protected Plugin plugin;
@Override public MPlugin getMplugin() { return this.mplugin; } @Override public Plugin getPlugin() { return this.plugin; }
public Gson getGson()
{
if (this.getPlugin() instanceof MPlugin)
{
return ((MPlugin)this.getPlugin()).gson;
}
else
{
return MCore.gson;
}
}
protected Db<?> db; protected Db<?> db;
@Override public Db<?> getDb() { return this.db; } @Override public Db<?> getDb() { return this.db; }
@ -577,7 +591,7 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public Coll(Db<?> db, MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative, Comparator<? super L> idComparator, Comparator<? super E> entityComparator) public Coll(Db<?> db, Plugin plugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative, Comparator<? super L> idComparator, Comparator<? super E> entityComparator)
{ {
// Setup the name and the parsed parts // Setup the name and the parsed parts
this.name = name; this.name = name;
@ -598,7 +612,7 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
this.creative = creative; this.creative = creative;
// SUPPORTING SYSTEM // SUPPORTING SYSTEM
this.mplugin = mplugin; this.plugin = plugin;
this.db = db; this.db = db;
this.storeAdapter = this.db.getDriver().getStoreAdapter(); this.storeAdapter = this.db.getDriver().getStoreAdapter();
this.idStrategy = this.db.getDriver().getIdStrategy(idStrategyName); this.idStrategy = this.db.getDriver().getIdStrategy(idStrategyName);
@ -633,14 +647,14 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
}; };
} }
public Coll(Db<?> db, MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative) public Coll(Db<?> db, Plugin plugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
{ {
this(db, mplugin, idStrategyName, name, entityClass, idClass, creative, null, null); this(db, plugin, idStrategyName, name, entityClass, idClass, creative, null, null);
} }
public Coll(MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative) public Coll(Plugin plugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
{ {
this(MCore.getDb(), mplugin, idStrategyName, name, entityClass, idClass, creative); this(MCore.getDb(), plugin, idStrategyName, name, entityClass, idClass, creative);
} }
@Override @Override

View File

@ -4,7 +4,8 @@ import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
import com.massivecraft.mcore.MPlugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.mcore.Predictate; import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.store.idstrategy.IdStrategy; import com.massivecraft.mcore.store.idstrategy.IdStrategy;
import com.massivecraft.mcore.store.storeadapter.StoreAdapter; import com.massivecraft.mcore.store.storeadapter.StoreAdapter;
@ -23,7 +24,7 @@ public interface CollInterface<E, L extends Comparable<? super L>>
// -------------------------------------------- // // -------------------------------------------- //
// SUPPORTING SYSTEM // SUPPORTING SYSTEM
// -------------------------------------------- // // -------------------------------------------- //
public MPlugin getMplugin(); public Plugin getPlugin();
public Db<?> getDb(); public Db<?> getDb();
public Driver<?> getDriver(); public Driver<?> getDriver();

View File

@ -140,7 +140,7 @@ public class DriverGson extends DriverAbstract<JsonElement>
public <L extends Comparable<? super L>> Long save(Coll<?, L> coll, L id, Object rawData) public <L extends Comparable<? super L>> Long save(Coll<?, L> coll, L id, Object rawData)
{ {
File file = fileFromId(coll, id); File file = fileFromId(coll, id);
String content = coll.getMplugin().gson.toJson((JsonElement)rawData); String content = coll.getGson().toJson((JsonElement)rawData);
if (DiscUtil.writeCatch(file, content) == false) return null; if (DiscUtil.writeCatch(file, content) == false) return null;
return file.lastModified(); return file.lastModified();
} }

View File

@ -90,7 +90,7 @@ public abstract class Entity<E extends Entity<E, L>, L extends Comparable<? supe
{ {
Gson gson = MCore.gson; Gson gson = MCore.gson;
Coll<E, L> coll = this.getColl(); Coll<E, L> coll = this.getColl();
if (coll != null) gson = coll.getMplugin().gson; if (coll != null) gson = coll.getGson();
return this.getClass().getSimpleName()+gson.toJson(this, this.getClass()); return this.getClass().getSimpleName()+gson.toJson(this, this.getClass());
} }

View File

@ -6,8 +6,8 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import com.massivecraft.mcore.MPlugin;
import com.massivecraft.mcore.Predictate; import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
@ -39,25 +39,25 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String> imple
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public SenderColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator) public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing, Comparator<? super String> idComparator, Comparator<? super E> entityComparator)
{ {
super(db, mplugin, "ai", name, entityClass, String.class, creative, idComparator, entityComparator); super(db, plugin, "ai", name, entityClass, String.class, creative, idComparator, entityComparator);
this.lowercasing = lowercasing; this.lowercasing = lowercasing;
} }
public SenderColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing) public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing)
{ {
this(db, mplugin, name, entityClass, creative, lowercasing, null, null); this(db, plugin, name, entityClass, creative, lowercasing, null, null);
} }
public SenderColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass, boolean creative) public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass, boolean creative)
{ {
this(db, mplugin, name, entityClass, creative, DEFAULT_LOWERCASING); this(db, plugin, name, entityClass, creative, DEFAULT_LOWERCASING);
} }
public SenderColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass) public SenderColl(Db<?> db, Plugin plugin, String name, Class<E> entityClass)
{ {
this(db, mplugin, name, entityClass, DEFAULT_CREATIVE); this(db, plugin, name, entityClass, DEFAULT_CREATIVE);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -13,7 +13,7 @@ public class StoreAdapterGson extends StoreAdapterAbstract
@Override @Override
public Object read(Coll<?, ?> coll, Object entity) public Object read(Coll<?, ?> coll, Object entity)
{ {
return coll.getMplugin().gson.toJsonTree(entity, coll.getEntityClass()); return coll.getGson().toJsonTree(entity, coll.getEntityClass());
} }
@Override @Override
@ -21,7 +21,7 @@ public class StoreAdapterGson extends StoreAdapterAbstract
{ {
if (raw == null) throw new NullPointerException("raw"); if (raw == null) throw new NullPointerException("raw");
if (entity == null) throw new NullPointerException("entity"); if (entity == null) throw new NullPointerException("entity");
Object temp = coll.getMplugin().gson.fromJson((JsonElement)raw, coll.getEntityClass()); Object temp = coll.getGson().fromJson((JsonElement)raw, coll.getEntityClass());
coll.copy(temp, entity); coll.copy(temp, entity);
} }