Improvements to the simple config. Added an init method to the store coll.
This commit is contained in:
parent
7e0305aec0
commit
f706ea7ac2
@ -13,7 +13,7 @@ public class SimpleConfig
|
|||||||
protected transient MPlugin mplugin;
|
protected transient MPlugin mplugin;
|
||||||
protected MPlugin mplugin() { return this.mplugin; }
|
protected MPlugin mplugin() { return this.mplugin; }
|
||||||
|
|
||||||
protected transient File file = new File("plugins/mcore/conf.json");
|
protected transient File file;
|
||||||
protected File file() { return this.file; }
|
protected File file() { return this.file; }
|
||||||
|
|
||||||
public SimpleConfig(MPlugin mplugin, File file)
|
public SimpleConfig(MPlugin mplugin, File file)
|
||||||
@ -36,20 +36,31 @@ public class SimpleConfig
|
|||||||
// IO
|
// IO
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
protected static boolean contentRequestsDefaults(String content)
|
||||||
|
{
|
||||||
|
if (content == null) return false;
|
||||||
|
char c = content.charAt(0);
|
||||||
|
return c == 'd' || c == 'D';
|
||||||
|
}
|
||||||
|
|
||||||
public void load()
|
public void load()
|
||||||
{
|
{
|
||||||
if (this.file().isFile())
|
if (this.file().isFile())
|
||||||
{
|
{
|
||||||
String content = DiscUtil.readCatch(this.file());
|
String content = DiscUtil.readCatch(this.file());
|
||||||
SimpleConfig loaded = this.mplugin().gson.fromJson(content, this.getClass());
|
if (contentRequestsDefaults(content)) return;
|
||||||
Accessor.get(this.getClass()).copy(loaded, this);
|
Object createdByGson = this.mplugin().gson.fromJson(content, this.getClass());
|
||||||
|
Accessor.get(this.getClass()).copy(createdByGson, this);
|
||||||
}
|
}
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save()
|
public void save()
|
||||||
{
|
{
|
||||||
String content = this.mplugin().gson.toJson(this);
|
String content = DiscUtil.readCatch(this.file());
|
||||||
|
if (contentRequestsDefaults(content)) return;
|
||||||
|
content = this.mplugin().gson.toJson(this);
|
||||||
DiscUtil.writeCatch(file, content);
|
DiscUtil.writeCatch(file, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +504,7 @@ public class Coll<E, L> implements CollInterface<E, L>
|
|||||||
@Override public Thread examineThread() { return this.examineThread; }
|
@Override public Thread examineThread() { return this.examineThread; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCTORS
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public Coll(Db<?> db, MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
|
public Coll(Db<?> db, MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
|
||||||
@ -533,15 +533,19 @@ public class Coll<E, L> implements CollInterface<E, L>
|
|||||||
{
|
{
|
||||||
@Override public void run() { me.onTick(); }
|
@Override public void run() { me.onTick(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
this.examineThread = new ExamineThread<E, L>(this);
|
|
||||||
this.examineThread.start();
|
|
||||||
this.syncAll();
|
|
||||||
instances.add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coll(MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
|
public Coll(MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
|
||||||
{
|
{
|
||||||
this(MCore.getDb(), mplugin, idStrategyName, name, entityClass, idClass, creative);
|
this(MCore.getDb(), mplugin, idStrategyName, name, entityClass, idClass, creative);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
this.syncAll();
|
||||||
|
this.examineThread = new ExamineThread<E, L>(this);
|
||||||
|
this.examineThread.start();
|
||||||
|
instances.add(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,5 +133,11 @@ public interface CollInterface<E, L>
|
|||||||
|
|
||||||
public Thread examineThread();
|
public Thread examineThread();
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public void init();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -46,6 +46,7 @@ public abstract class Entity<E extends Entity<E, L>, L>
|
|||||||
|
|
||||||
public L getId()
|
public L getId()
|
||||||
{
|
{
|
||||||
|
if (this.getColl() == null) return null;
|
||||||
return this.getColl().id(getThis());
|
return this.getColl().id(getThis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user