Getting rid of the persist-maps in mcore.

This commit is contained in:
Olof Larsson 2012-08-31 10:32:49 +02:00
parent 7e7435e614
commit 36c8d217c8
4 changed files with 19 additions and 23 deletions

View File

@ -29,9 +29,9 @@ public class InternalListener implements Listener
PlayerUtil.getAllVisitorNames().add(id);
for (Persist realm : MCore.getPersistInstances().values())
for (Persist instance : Persist.instances)
{
for (IClassManager<?> manager : realm.getClassManagers().values())
for (IClassManager<?> manager : instance.getClassManagers().values())
{
if (manager.idCanFix(Player.class) == false) continue;
if (manager.containsId(id)) continue;

View File

@ -1,8 +1,6 @@
package com.massivecraft.mcore4;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -25,20 +23,6 @@ public class MCore extends JavaPlugin
{
InternalListener listener;
// -------------------------------------------- //
// PERSIST
// -------------------------------------------- //
private static Map<Object, Persist> persistInstances = new HashMap<Object, Persist>();
public static Map<Object, Persist> getPersistInstances() { return persistInstances; }
public static Persist getPersist(Object owner) { return persistInstances.get(owner); }
public static void removePersist(Object owner) { persistInstances.remove(owner); }
public static void createPersist(Object owner)
{
if (persistInstances.containsKey(owner)) return;
persistInstances.put(owner, new Persist());
}
// -------------------------------------------- //
// DERP
// -------------------------------------------- //
@ -62,7 +46,7 @@ public class MCore extends JavaPlugin
PlayerUtil.populateAllVisitorNames();
// This is safe since all plugins using Persist should bukkit-depend this plugin.
getPersistInstances().clear();
Persist.instances.clear();
// Register events
this.listener = new InternalListener(this);

View File

@ -43,10 +43,9 @@ public abstract class MPlugin extends JavaPlugin implements Listener
// Create Gson
this.gson = this.getGsonBuilder().create();
MCore.createPersist(this);
// Create tools
this.cmd = new Cmd();
this.persist = MCore.getPersist(this);
this.persist = new Persist();
this.one = new One(this);
this.lib = new LibLoader(this);
@ -65,7 +64,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
public void onDisable()
{
this.persist.saveAll();
MCore.removePersist(this);
Persist.instances.remove(this.persist);
this.cmd = null;
this.persist = null;

View File

@ -5,15 +5,19 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.Timer;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
import com.massivecraft.mcore4.Predictate;
public class Persist
{
public static List<Persist> instances = new CopyOnWriteArrayList<Persist>();
private Map<Class<?>, IClassManager<?>> classManagers = new HashMap<Class<?>, IClassManager<?>>();
public <T> void setManager(Class<T> clazz, IClassManager<T> manager)
{
@ -57,6 +61,15 @@ public class Persist
return (IClassManager<T>) this.getManager(entity.getClass());
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public Persist()
{
instances.add(this);
}
// -------------------------------------------- //
// SAVE ALL
// -------------------------------------------- //