Require Plugin only and not MPlugin in MStore.
This commit is contained in:
parent
d4f30331ef
commit
95f1dc8dd0
@ -55,7 +55,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
||||
// Collection shutdowns.
|
||||
for (Coll<?, ?> coll : Coll.instances)
|
||||
{
|
||||
if (coll.getMplugin() != this) continue;
|
||||
if (coll.getPlugin() != this) continue;
|
||||
coll.examineThread().interrupt();
|
||||
coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage...
|
||||
Coll.instances.remove(coll);
|
||||
|
@ -12,12 +12,15 @@ import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.mcore.MCore;
|
||||
import com.massivecraft.mcore.MPlugin;
|
||||
import com.massivecraft.mcore.Predictate;
|
||||
import com.massivecraft.mcore.store.accessor.Accessor;
|
||||
import com.massivecraft.mcore.store.idstrategy.IdStrategy;
|
||||
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>
|
||||
{
|
||||
@ -50,8 +53,19 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
|
||||
// SUPPORTING SYSTEM
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected MPlugin mplugin;
|
||||
@Override public MPlugin getMplugin() { return this.mplugin; }
|
||||
protected Plugin plugin;
|
||||
@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;
|
||||
@Override public Db<?> getDb() { return this.db; }
|
||||
@ -577,7 +591,7 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
|
||||
// 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
|
||||
this.name = name;
|
||||
@ -598,7 +612,7 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
|
||||
this.creative = creative;
|
||||
|
||||
// SUPPORTING SYSTEM
|
||||
this.mplugin = mplugin;
|
||||
this.plugin = plugin;
|
||||
this.db = db;
|
||||
this.storeAdapter = this.db.getDriver().getStoreAdapter();
|
||||
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
|
||||
|
@ -4,7 +4,8 @@ import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.massivecraft.mcore.MPlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.mcore.Predictate;
|
||||
import com.massivecraft.mcore.store.idstrategy.IdStrategy;
|
||||
import com.massivecraft.mcore.store.storeadapter.StoreAdapter;
|
||||
@ -23,7 +24,7 @@ public interface CollInterface<E, L extends Comparable<? super L>>
|
||||
// -------------------------------------------- //
|
||||
// SUPPORTING SYSTEM
|
||||
// -------------------------------------------- //
|
||||
public MPlugin getMplugin();
|
||||
public Plugin getPlugin();
|
||||
|
||||
public Db<?> getDb();
|
||||
public Driver<?> getDriver();
|
||||
|
@ -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)
|
||||
{
|
||||
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;
|
||||
return file.lastModified();
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public abstract class Entity<E extends Entity<E, L>, L extends Comparable<? supe
|
||||
{
|
||||
Gson gson = MCore.gson;
|
||||
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());
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.mcore.MPlugin;
|
||||
import com.massivecraft.mcore.Predictate;
|
||||
import com.massivecraft.mcore.mixin.Mixin;
|
||||
import com.massivecraft.mcore.util.MUtil;
|
||||
@ -39,25 +39,25 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String> imple
|
||||
// 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
@ -13,7 +13,7 @@ public class StoreAdapterGson extends StoreAdapterAbstract
|
||||
@Override
|
||||
public Object read(Coll<?, ?> coll, Object entity)
|
||||
{
|
||||
return coll.getMplugin().gson.toJsonTree(entity, coll.getEntityClass());
|
||||
return coll.getGson().toJsonTree(entity, coll.getEntityClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -21,7 +21,7 @@ public class StoreAdapterGson extends StoreAdapterAbstract
|
||||
{
|
||||
if (raw == null) throw new NullPointerException("raw");
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user