A bugfix and a simple config class.
This commit is contained in:
parent
6089d5e0ed
commit
7e0305aec0
@ -3,31 +3,21 @@ package com.massivecraft.mcore4;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.massivecraft.mcore4.util.DiscUtil;
|
||||
|
||||
public class Conf
|
||||
public class Conf extends SimpleConfig
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONTENT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String dburi = "gson://./mstore";
|
||||
public static String serverid = UUID.randomUUID().toString();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Persistance
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
private static transient File file = new File("plugins/mcore/conf.json");
|
||||
private static transient Conf i = new Conf();
|
||||
public static void load()
|
||||
public static transient Conf i = new Conf();
|
||||
private Conf()
|
||||
{
|
||||
if (file.isFile())
|
||||
{
|
||||
String content = DiscUtil.readCatch(file);
|
||||
MCore.gson.fromJson(content, Conf.class);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
String content = MCore.gson.toJson(i, i.getClass());
|
||||
DiscUtil.writeCatch(file, content);
|
||||
super(MCore.p, new File("plugins/mcore/conf.json"));
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,16 @@ public class MCore extends MPlugin
|
||||
private static Db<?> db;
|
||||
public static Db<?> getDb() { return db; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected static MCore p;
|
||||
public MCore()
|
||||
{
|
||||
p = this;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// NON STATIC :)
|
||||
// -------------------------------------------- //
|
||||
@ -68,7 +78,7 @@ public class MCore extends MPlugin
|
||||
|
||||
if ( ! preEnable()) return;
|
||||
|
||||
Conf.load();
|
||||
Conf.i.load();
|
||||
|
||||
// Setup the default database
|
||||
db = MStore.getDb(Conf.dburi);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.massivecraft.mcore4;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -67,14 +66,12 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
||||
Persist.instances.remove(this.persist);
|
||||
|
||||
// Collection shutdowns for new system.
|
||||
Iterator<Coll<?, ?>> iter = Coll.instances.iterator();
|
||||
while (iter.hasNext())
|
||||
for (Coll<?, ?> coll : Coll.instances)
|
||||
{
|
||||
Coll<?, ?> coll = iter.next();
|
||||
if (coll.mplugin() != this) continue;
|
||||
coll.examineThread().interrupt();
|
||||
coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage...
|
||||
iter.remove();
|
||||
Coll.instances.remove(coll);
|
||||
}
|
||||
|
||||
log("Disabled");
|
||||
|
55
src/com/massivecraft/mcore4/SimpleConfig.java
Normal file
55
src/com/massivecraft/mcore4/SimpleConfig.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.massivecraft.mcore4;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.massivecraft.mcore4.store.accessor.Accessor;
|
||||
import com.massivecraft.mcore4.util.DiscUtil;
|
||||
|
||||
public class SimpleConfig
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
protected transient MPlugin mplugin;
|
||||
protected MPlugin mplugin() { return this.mplugin; }
|
||||
|
||||
protected transient File file = new File("plugins/mcore/conf.json");
|
||||
protected File file() { return this.file; }
|
||||
|
||||
public SimpleConfig(MPlugin mplugin, File file)
|
||||
{
|
||||
this.mplugin = mplugin;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public SimpleConfig(MPlugin mplugin, String confname)
|
||||
{
|
||||
this(mplugin, new File(mplugin.getDataFolder(), confname+".json"));
|
||||
}
|
||||
|
||||
public SimpleConfig(MPlugin mplugin)
|
||||
{
|
||||
this(mplugin, "conf");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// IO
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void load()
|
||||
{
|
||||
if (this.file().isFile())
|
||||
{
|
||||
String content = DiscUtil.readCatch(this.file());
|
||||
SimpleConfig loaded = this.mplugin().gson.fromJson(content, this.getClass());
|
||||
Accessor.get(this.getClass()).copy(loaded, this);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
String content = this.mplugin().gson.toJson(this);
|
||||
DiscUtil.writeCatch(file, content);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user