mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Also allow /lb copy from another map
This commit is contained in:
parent
289a52133b
commit
589050848a
@ -45,11 +45,11 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
AddHandler(p, parts, global, cmd); break;
|
AddHandler(p, parts, global, cmd); break;
|
||||||
case "copyall":
|
case "copyall":
|
||||||
case "copyfrom":
|
case "copyfrom":
|
||||||
CopyAllHandler(p, parts, data,global, cmd); break;
|
CopyAllHandler(p, parts, data, global, cmd); break;
|
||||||
case "copy":
|
case "copy":
|
||||||
case "clone":
|
case "clone":
|
||||||
case "duplicate":
|
case "duplicate":
|
||||||
CopyHandler(p, parts, global, cmd); break;
|
CopyHandler(p, parts, data, global, cmd); break;
|
||||||
case "delete":
|
case "delete":
|
||||||
case "remove":
|
case "remove":
|
||||||
RemoveHandler(p, parts, global, cmd); break;
|
RemoveHandler(p, parts, global, cmd); break;
|
||||||
@ -108,20 +108,31 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
SendStepHelp(p, global);
|
SendStepHelp(p, global);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyAllHandler(Player p, string[] parts, CommandData data, bool global, string cmd) {
|
static BlockDefinition[] GetDefs(Player p, CommandData data, string map, ref string coloredMap) {
|
||||||
if (parts.Length < 2) { Help(p, cmd); return; }
|
map = Matcher.FindMaps(p, map);
|
||||||
string map = Matcher.FindMaps(p, parts[1]);
|
if (map == null) return null;
|
||||||
if (map == null) return;
|
|
||||||
|
|
||||||
Level lvl = null;
|
Level lvl = null;
|
||||||
LevelConfig cfg = LevelInfo.GetConfig(map, out lvl);
|
LevelConfig cfg = LevelInfo.GetConfig(map, out lvl);
|
||||||
AccessController visit = new LevelAccessController(cfg, map, true);
|
AccessController visit = new LevelAccessController(cfg, map, true);
|
||||||
|
|
||||||
if (!visit.CheckDetailed(p, data.Rank)) {
|
if (!visit.CheckDetailed(p, data.Rank)) {
|
||||||
p.Message("Hence, you cannot copy custom blocks from that level"); return;
|
p.Message("Hence, you cannot copy custom blocks from that level");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coloredMap = cfg.Color + map;
|
||||||
|
return BlockDefinition.Load(false, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CopyAllHandler(Player p, string[] parts, CommandData data, bool global, string cmd) {
|
||||||
|
if (parts.Length < 2) { Help(p, cmd); return; }
|
||||||
|
string coloredMap = null;
|
||||||
int copied = 0;
|
int copied = 0;
|
||||||
BlockDefinition[] defs = BlockDefinition.Load(false, map);
|
|
||||||
|
BlockDefinition[] defs = GetDefs(p, data, parts[1], ref coloredMap);
|
||||||
|
if (defs == null) return;
|
||||||
|
|
||||||
for (int i = 0; i < defs.Length; i++) {
|
for (int i = 0; i < defs.Length; i++) {
|
||||||
if (defs[i] == null) continue;
|
if (defs[i] == null) continue;
|
||||||
|
|
||||||
@ -134,17 +145,23 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string prefix = copied > 0 ? copied.ToString() : "No";
|
string prefix = copied > 0 ? copied.ToString() : "No";
|
||||||
p.Message("{0} custom blocks were copied from level {1}",
|
p.Message("{0} custom blocks were copied from level {1}", prefix, coloredMap);
|
||||||
prefix, cfg.Color + map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyHandler(Player p, string[] parts, bool global, string cmd) {
|
static void CopyHandler(Player p, string[] parts, CommandData data, bool global, string cmd) {
|
||||||
if (parts.Length < 2) { Help(p, cmd); return; }
|
if (parts.Length < 2) { Help(p, cmd); return; }
|
||||||
BlockID src, dst;
|
BlockID src, dst;
|
||||||
if (!CheckBlock(p, parts[1], out src, true)) return;
|
if (!CheckBlock(p, parts[1], out src, true)) return;
|
||||||
|
|
||||||
|
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
||||||
if (parts.Length > 2) {
|
if (parts.Length > 2) {
|
||||||
if (!CheckBlock(p, parts[2], out dst)) return;
|
if (!CheckBlock(p, parts[2], out dst)) return;
|
||||||
|
|
||||||
|
if (parts.Length > 3) {
|
||||||
|
string coloredMap = null;
|
||||||
|
defs = GetDefs(p, data, parts[3], ref coloredMap);
|
||||||
|
if (defs == null) return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dst = GetFreeBlock(global, p.IsSuper ? null : p.level);
|
dst = GetFreeBlock(global, p.IsSuper ? null : p.level);
|
||||||
if (dst == Block.Invalid) {
|
if (dst == Block.Invalid) {
|
||||||
@ -154,10 +171,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
if (!DoCopy(p, global, cmd, false, defs[src], src, dst)) return;
|
||||||
BlockDefinition srcDef = defs[src];
|
|
||||||
if (!DoCopy(p, global, cmd, false, srcDef, src, dst)) return;
|
|
||||||
|
|
||||||
string scope = global ? "global" : "level";
|
string scope = global ? "global" : "level";
|
||||||
p.Message("Duplicated the {0} custom block with id \"{1}\" to \"{2}\".",
|
p.Message("Duplicated the {0} custom block with id \"{1}\" to \"{2}\".",
|
||||||
scope, Block.ToRaw(src), Block.ToRaw(dst));
|
scope, Block.ToRaw(src), Block.ToRaw(dst));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user