Add an mstore command with a todo dbcopy command. Also cache database instances in mstore.

This commit is contained in:
Olof Larsson 2013-05-01 13:07:21 +02:00
parent a46caad008
commit f6206d0392
8 changed files with 117 additions and 18 deletions

View File

@ -13,7 +13,9 @@ permissions:
mcore.cmd.mcore: {description: use the mcore command, default: false} mcore.cmd.mcore: {description: use the mcore command, default: false}
mcore.cmd.mcore.id: {description: see the server id, default: false} mcore.cmd.mcore.id: {description: see the server id, default: false}
mcore.cmd.mcore.version: {description: diplay plugin version, default: false} mcore.cmd.mcore.version: {description: diplay plugin version, default: false}
mcore.cmd.mcore.usys: {description: manage the universe system, default: false} mcore.cmd.mcore.mstore: {description: use the mstore command, default: false}
mcore.cmd.mcore.mstore.copydb: {description: copy database content, default: false}
mcore.cmd.mcore.usys: {description: use the usys command, default: false}
mcore.cmd.mcore.usys.multiverse: {description: manage multiverses, default: false} mcore.cmd.mcore.usys.multiverse: {description: manage multiverses, default: false}
mcore.cmd.mcore.usys.multiverse.list: {description: list multiverses, default: false} mcore.cmd.mcore.usys.multiverse.list: {description: list multiverses, default: false}
mcore.cmd.mcore.usys.multiverse.show: {description: show multiverse, default: false} mcore.cmd.mcore.usys.multiverse.show: {description: show multiverse, default: false}

View File

@ -1,6 +1,7 @@
package com.massivecraft.mcore; package com.massivecraft.mcore;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
@ -21,9 +22,15 @@ public class ConfServer extends SimpleConfig
// -------------------------------------------- // // -------------------------------------------- //
public static String serverid = UUID.randomUUID().toString(); public static String serverid = UUID.randomUUID().toString();
public static String dburi = "gson://./mstore";
public static Map<String, String> alias2uri = MUtil.map(
"default", "gson://./mstore"
);
public static String dburi = "default";
public static List<String> aliasesOuterMCore = MUtil.list("mcore"); public static List<String> aliasesOuterMCore = MUtil.list("mcore");
public static List<String> aliasesOuterMCoreUsys = MUtil.list("usys"); public static List<String> aliasesOuterMCoreUsys = MUtil.list("usys");
public static List<String> aliasesOuterMCoreMStore = MUtil.list("mstore");
} }

View File

@ -20,6 +20,7 @@ import com.massivecraft.mcore.adapter.UUIDAdapter;
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures; import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
import com.massivecraft.mcore.integration.vault.VaultFeatures; import com.massivecraft.mcore.integration.vault.VaultFeatures;
import com.massivecraft.mcore.mcorecmd.CmdMCore; import com.massivecraft.mcore.mcorecmd.CmdMCore;
import com.massivecraft.mcore.mcorecmd.CmdMCoreMStore;
import com.massivecraft.mcore.mcorecmd.CmdMCoreUsys; import com.massivecraft.mcore.mcorecmd.CmdMCoreUsys;
import com.massivecraft.mcore.mixin.ScheduledTeleportEngine; import com.massivecraft.mcore.mixin.ScheduledTeleportEngine;
import com.massivecraft.mcore.mixin.SenderIdMixinDefault; import com.massivecraft.mcore.mixin.SenderIdMixinDefault;
@ -27,9 +28,7 @@ import com.massivecraft.mcore.mixin.TeleportMixinCauseEngine;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.ps.PSAdapter; import com.massivecraft.mcore.ps.PSAdapter;
import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Db;
import com.massivecraft.mcore.store.ExamineThread; import com.massivecraft.mcore.store.ExamineThread;
import com.massivecraft.mcore.store.MStore;
import com.massivecraft.mcore.util.PlayerUtil; import com.massivecraft.mcore.util.PlayerUtil;
import com.massivecraft.mcore.util.TimeDiffUtil; import com.massivecraft.mcore.util.TimeDiffUtil;
import com.massivecraft.mcore.util.TimeUnit; import com.massivecraft.mcore.util.TimeUnit;
@ -76,8 +75,8 @@ public class MCore extends MPlugin
} }
public static String getServerId() { return ConfServer.serverid; } public static String getServerId() { return ConfServer.serverid; }
private static Db<?> db; //private static Db<?> db;
public static Db<?> getDb() { return db; } //public static Db<?> getDb() { return db; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -95,6 +94,9 @@ public class MCore extends MPlugin
private CmdMCoreUsys outerCmdMCoreUsys; private CmdMCoreUsys outerCmdMCoreUsys;
public CmdMCoreUsys getOuterCmdMCoreUsys() { return this.outerCmdMCoreUsys; } public CmdMCoreUsys getOuterCmdMCoreUsys() { return this.outerCmdMCoreUsys; }
private CmdMCoreMStore outerCmdMCoreMStore;
public CmdMCoreMStore getOuterCmdMCoreMStore() { return this.outerCmdMCoreMStore; }
// Runnables // Runnables
// TODO: Make this one a singleton // TODO: Make this one a singleton
private Runnable collTickTask = new Runnable() private Runnable collTickTask = new Runnable()
@ -128,7 +130,7 @@ public class MCore extends MPlugin
ConfServer.get().load(); ConfServer.get().load();
// Setup the default database // Setup the default database
db = MStore.getDb(ConfServer.dburi); //db = MStore.getDb(ConfServer.dburi);
// Setup PlayerUtil and it's events // Setup PlayerUtil and it's events
new PlayerUtil(this); new PlayerUtil(this);
@ -162,6 +164,9 @@ public class MCore extends MPlugin
this.outerCmdMCoreUsys = new CmdMCoreUsys(ConfServer.aliasesOuterMCoreUsys); this.outerCmdMCoreUsys = new CmdMCoreUsys(ConfServer.aliasesOuterMCoreUsys);
this.outerCmdMCoreUsys.register(this); this.outerCmdMCoreUsys.register(this);
this.outerCmdMCoreMStore = new CmdMCoreMStore(ConfServer.aliasesOuterMCoreMStore);
this.outerCmdMCoreMStore.register(this);
// Integration // Integration
this.integrate( this.integrate(
ProtocolLibFeatures.get(), ProtocolLibFeatures.get(),

View File

@ -13,6 +13,8 @@ public enum MCorePerm
CMD_MCORE("cmd.mcore"), CMD_MCORE("cmd.mcore"),
CMD_MCORE_ID("cmd.mcore.id"), CMD_MCORE_ID("cmd.mcore.id"),
CMD_MCORE_VERSION("cmd.mcore.version"), CMD_MCORE_VERSION("cmd.mcore.version"),
CMD_MCORE_MSTORE("cmd.mcore.mstore"),
CMD_MCORE_MSTORE_COPYDB("cmd.mcore.mstore.copydb"),
CMD_MCORE_USYS("cmd.mcore.usys"), CMD_MCORE_USYS("cmd.mcore.usys"),
CMD_MCORE_USYS_MULTIVERSE("cmd.mcore.usys.multiverse"), CMD_MCORE_USYS_MULTIVERSE("cmd.mcore.usys.multiverse"),
CMD_MCORE_USYS_MULTIVERSE_LIST("cmd.mcore.usys.multiverse.list"), CMD_MCORE_USYS_MULTIVERSE_LIST("cmd.mcore.usys.multiverse.list"),

View File

@ -0,0 +1,29 @@
package com.massivecraft.mcore.mcorecmd;
import java.util.List;
import com.massivecraft.mcore.MCorePerm;
import com.massivecraft.mcore.cmd.HelpCommand;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.MUtil;
public class CmdMCoreMStore extends MCoreCommand
{
public CmdMCoreMStoreCopydb cmdMCoreMStoreCopydb = new CmdMCoreMStoreCopydb(MUtil.list("copydb"));
public CmdMCoreMStore(List<String> aliases)
{
super(aliases);
this.addSubCommand(this.cmdMCoreMStoreCopydb);
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE.node));
}
@Override
public void perform()
{
this.getCommandChain().add(this);
HelpCommand.getInstance().execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.mcore.mcorecmd;
import java.util.List;
import com.massivecraft.mcore.MCorePerm;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdMCoreMStoreCopydb extends MCoreCommand
{
public CmdMCoreMStoreCopydb(List<String> aliases)
{
super(aliases);
this.addRequiredArg("fromuri");
this.addRequiredArg("touri");
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE_COPYDB.node));
}
@Override
public void perform()
{
// TODO
}
}

View File

@ -11,15 +11,19 @@ import com.massivecraft.mcore.util.MUtil;
public class CmdMCore extends MCoreCommand public class CmdMCore extends MCoreCommand
{ {
public CmdMCoreId cmdMCoreId = new CmdMCoreId(MUtil.list("id"));
public CmdMCoreUsys cmdMCoreUsys = new CmdMCoreUsys(MUtil.list("usys")); public CmdMCoreUsys cmdMCoreUsys = new CmdMCoreUsys(MUtil.list("usys"));
public CmdMCoreMStore cmdMCoreMStore = new CmdMCoreMStore(MUtil.list("mstore"));
public CmdMCoreId cmdMCoreId = new CmdMCoreId(MUtil.list("id"));
public CmdMCore(List<String> aliases) public CmdMCore(List<String> aliases)
{ {
super(aliases); super(aliases);
this.addSubCommand(this.cmdMCoreUsys); this.addSubCommand(this.cmdMCoreUsys);
this.addSubCommand(this.cmdMCoreMStore);
this.addSubCommand(this.cmdMCoreId); this.addSubCommand(this.cmdMCoreId);
this.addSubCommand(new VersionCommand(MCore.get(), MCorePerm.CMD_MCORE_VERSION.node, "v", "version")); this.addSubCommand(new VersionCommand(MCore.get(), MCorePerm.CMD_MCORE_VERSION.node, "v", "version"));
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE.node)); this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE.node));

View File

@ -5,11 +5,14 @@ import java.net.URISyntaxException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.ConfServer;
public class MStore public class MStore
{ {
// -------------------------------------------- //
// DRIVER REGISTRY
// -------------------------------------------- //
protected static Map<String, Driver<?>> drivers = new HashMap<String, Driver<?>>(); protected static Map<String, Driver<?>> drivers = new HashMap<String, Driver<?>>();
public static boolean registerDriver(Driver<?> driver) public static boolean registerDriver(Driver<?> driver)
{ {
@ -23,18 +26,43 @@ public class MStore
return drivers.get(id); return drivers.get(id);
} }
public static Db<?> getDb(String uri) static
{ {
registerDriver(DriverMongo.get());
registerDriver(DriverGson.get());
}
// -------------------------------------------- //
// FROODLSCHTEIN
// -------------------------------------------- //
// We cache databases here
private static Map<String, Db<?>> uri2db = new HashMap<String, Db<?>>();
public static String resolveAlias(String alias)
{
String uri = ConfServer.alias2uri.get(alias);
if (uri == null) return alias;
return resolveAlias(uri);
}
public static Db<?> getDb(String alias)
{
String uri = resolveAlias(alias);
Db<?> ret = uri2db.get(uri);
if (ret != null) return ret;
try try
{ {
if (uri.equalsIgnoreCase("default")) return MCore.getDb(); ret = getDb(new URI(uri));
return getDb(new URI(uri));
} }
catch (URISyntaxException e) catch (URISyntaxException e)
{ {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
return ret;
} }
public static Db<?> getDb(URI uri) public static Db<?> getDb(URI uri)
@ -45,9 +73,5 @@ public class MStore
return driver.getDb(uri.toString()); return driver.getDb(uri.toString());
} }
static
{
registerDriver(DriverMongo.get());
registerDriver(DriverGson.get());
}
} }