mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
The /copylvl command should also copy portals,message blocks, and zones. (thanks yorkiebarz)
This commit is contained in:
parent
13cd3a56b3
commit
f68ff9dfca
@ -45,13 +45,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
if (LevelInfo.ExistsOffline(dst)) { Player.Message(p, "The level \"" + dst + "\" already exists."); return; }
|
if (LevelInfo.ExistsOffline(dst)) { Player.Message(p, "The level \"" + dst + "\" already exists."); return; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.Copy(LevelInfo.LevelPath(src), LevelInfo.LevelPath(dst));
|
LevelActions.CopyLevel(src, dst);
|
||||||
if (File.Exists(LevelInfo.PropertiesPath(src)))
|
|
||||||
File.Copy(LevelInfo.PropertiesPath(src), LevelInfo.PropertiesPath(dst), false);
|
|
||||||
if (File.Exists("blockdefs/lvl_" + src + ".json"))
|
|
||||||
File.Copy("blockdefs/lvl_" + src + ".json", "blockdefs/lvl_" + dst + ".json");
|
|
||||||
} catch (System.IO.FileNotFoundException) {
|
|
||||||
Player.Message(p, dst + " does not exist!"); return;
|
|
||||||
} catch (System.IO.IOException) {
|
} catch (System.IO.IOException) {
|
||||||
Player.Message(p, "The level &c" + dst + " %S already exists!"); return;
|
Player.Message(p, "The level &c" + dst + " %S already exists!"); return;
|
||||||
}
|
}
|
||||||
@ -61,7 +55,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/copylvl [level] [copied level]");
|
Player.Message(p, "%T/copylvl [level] [copied level]");
|
||||||
Player.Message(p, "%HMakes a copy of [level] called [copied Level].");
|
Player.Message(p, "%HMakes a copy of [level] called [copied Level].");
|
||||||
Player.Message(p, "%HNote: Only the level file and level properties are copied.");
|
Player.Message(p, "%HNote: The level's BlockDB is not copied.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,5 +51,12 @@ namespace MCGalaxy.SQL {
|
|||||||
|
|
||||||
/// <summary> Removes all entries from the given table. </summary>
|
/// <summary> Removes all entries from the given table. </summary>
|
||||||
public abstract void ClearTable(string table);
|
public abstract void ClearTable(string table);
|
||||||
|
|
||||||
|
/// <summary> Inserts/Copies all the entries from the source table into the destination table. </summary>
|
||||||
|
/// <remarks> Note: This may work incorrectly if the tables have different schema. </remarks>
|
||||||
|
public virtual void CopyAllEntries(string srcTable, string dstTable) {
|
||||||
|
string syntax = "INSERT INTO `" + dstTable + "` SELECT * FROM `" + srcTable + "`";
|
||||||
|
Database.Execute(syntax);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,18 +34,22 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.Move("levels/level properties/" + src + ".properties", "levels/level properties/" + dst + ".properties");
|
File.Move("levels/level properties/" + src + ".properties",
|
||||||
|
"levels/level properties/" + dst + ".properties");
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.Move("levels/level properties/" + src, "levels/level properties/" + dst + ".properties");
|
File.Move("levels/level properties/" + src,
|
||||||
|
"levels/level properties/" + dst + ".properties");
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (File.Exists("blockdefs/lvl_" + src + ".json"))
|
if (File.Exists("blockdefs/lvl_" + src + ".json")) {
|
||||||
File.Move("blockdefs/lvl_" + src + ".json", "blockdefs/lvl_" + dst + ".json");
|
File.Move("blockdefs/lvl_" + src + ".json",
|
||||||
|
"blockdefs/lvl_" + dst + ".json");
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,15 +58,23 @@ namespace MCGalaxy {
|
|||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
BotsFile.MoveBots(src, dst);
|
BotsFile.MoveBots(src, dst);
|
||||||
|
RenameDatabaseTables(src, dst);
|
||||||
Database.Backend.RenameTable("Block" + src, "Block" + dst);
|
}
|
||||||
object locker = ThreadSafeCache.DBCache.Get(src);
|
|
||||||
lock (locker) {
|
static void RenameDatabaseTables(string src, string dst) {
|
||||||
|
Database.Backend.RenameTable("Block" + src, "Block" + dst);
|
||||||
|
object srcLocker = ThreadSafeCache.DBCache.Get(src);
|
||||||
|
object dstLockder = ThreadSafeCache.DBCache.Get(dst);
|
||||||
|
|
||||||
|
lock (srcLocker)
|
||||||
|
lock (dstLockder)
|
||||||
|
{
|
||||||
if (Database.TableExists("Portals" + src)) {
|
if (Database.TableExists("Portals" + src)) {
|
||||||
Database.Backend.RenameTable("Portals" + src, "Portals" + dst);
|
Database.Backend.RenameTable("Portals" + src, "Portals" + dst);
|
||||||
string updateSyntax = "UPDATE `Portals" + dst + "` SET ExitMap=@1 WHERE ExitMap=@0";
|
string updateSyntax = "UPDATE `Portals" + dst + "` SET ExitMap=@1 WHERE ExitMap=@0";
|
||||||
Database.Execute(updateSyntax, src, dst);
|
Database.Execute(updateSyntax, src, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.TableExists("Messages" + src)) {
|
if (Database.TableExists("Messages" + src)) {
|
||||||
Database.Backend.RenameTable("Messages" + src, "Messages" + dst);
|
Database.Backend.RenameTable("Messages" + src, "Messages" + dst);
|
||||||
}
|
}
|
||||||
@ -168,5 +180,45 @@ namespace MCGalaxy {
|
|||||||
if (p != null && p.hidden) { who.SendMessage("&bMap reloaded"); }
|
if (p != null && p.hidden) { who.SendMessage("&bMap reloaded"); }
|
||||||
Player.Message(p, "&4Finished reloading for " + who.name);
|
Player.Message(p, "&4Finished reloading for " + who.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void CopyLevel(string src, string dst) {
|
||||||
|
File.Copy(LevelInfo.LevelPath(src), LevelInfo.LevelPath(dst));
|
||||||
|
if (File.Exists(LevelInfo.PropertiesPath(src))) {
|
||||||
|
File.Copy(LevelInfo.PropertiesPath(src),
|
||||||
|
LevelInfo.PropertiesPath(dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists("blockdefs/lvl_" + src + ".json")) {
|
||||||
|
File.Copy("blockdefs/lvl_" + src + ".json",
|
||||||
|
"blockdefs/lvl_" + dst + ".json");
|
||||||
|
}
|
||||||
|
CopyDatabaseTables(src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CopyDatabaseTables(string src, string dst) {
|
||||||
|
object srcLocker = ThreadSafeCache.DBCache.Get(src);
|
||||||
|
object dstLockder = ThreadSafeCache.DBCache.Get(dst);
|
||||||
|
|
||||||
|
lock (srcLocker)
|
||||||
|
lock (dstLockder)
|
||||||
|
{
|
||||||
|
if (Database.TableExists("Portals" + src)) {
|
||||||
|
Database.Execute(String.Format(LevelDB.createPortals, dst));
|
||||||
|
Database.Backend.CopyAllEntries("Portals" + src, "Portals" + dst);
|
||||||
|
string updateSyntax = "UPDATE `Portals" + dst + "` SET ExitMap=@1 WHERE ExitMap=@0";
|
||||||
|
Database.Execute(updateSyntax, src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Database.TableExists("Messages" + src)) {
|
||||||
|
Database.Execute(String.Format(LevelDB.createMessages, dst));
|
||||||
|
Database.Backend.CopyAllEntries("Messages" + src, "Messages" + dst);
|
||||||
|
}
|
||||||
|
if (Database.TableExists("Zone" + src)) {
|
||||||
|
Database.Execute(String.Format(LevelDB.createZones, dst));
|
||||||
|
Database.Backend.CopyAllEntries("Zone" + src, "Zone" + dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user