Fix /museum not loading custom blocks and env

This commit is contained in:
UnknownShadow200 2017-02-13 21:54:31 +11:00
parent fb652663c6
commit bd09b32b52
6 changed files with 78 additions and 72 deletions

View File

@ -70,7 +70,7 @@ namespace MCGalaxy {
internal static BlockDefinition[] Load(bool global, Level lvl) { internal static BlockDefinition[] Load(bool global, Level lvl) {
BlockDefinition[] defs = new BlockDefinition[256]; BlockDefinition[] defs = new BlockDefinition[256];
string path = global ? GlobalPath : "blockdefs/lvl_" + lvl.name + ".json"; string path = global ? GlobalPath : "blockdefs/lvl_" + lvl.MapName + ".json";
try { try {
if (File.Exists(path)) { if (File.Exists(path)) {
string json = File.ReadAllText(path); string json = File.ReadAllText(path);
@ -109,7 +109,7 @@ namespace MCGalaxy {
} }
string json = JsonConvert.SerializeObject(defs, Formatting.Indented); string json = JsonConvert.SerializeObject(defs, Formatting.Indented);
string path = global ? GlobalPath : "blockdefs/lvl_" + lvl.name + ".json"; string path = global ? GlobalPath : "blockdefs/lvl_" + lvl.MapName + ".json";
File.WriteAllText(path, json); File.WriteAllText(path, json);
} }

View File

@ -37,8 +37,8 @@ namespace MCGalaxy.Commands
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/trust <name>"); Player.Message(p, "%T/trust [name]");
Player.Message(p, "%HTurns off the anti-grief for <name>"); Player.Message(p, "%HTurns off the anti-grief for [name]");
} }
} }
} }

View File

@ -53,15 +53,17 @@ namespace MCGalaxy.Commands.World {
} }
try { try {
JoinMuseum(p, name, path); JoinMuseum(p, name, args[0].ToLower(), path);
} finally { } finally {
Interlocked.Exchange(ref p.LoadingMuseum, 0); Interlocked.Exchange(ref p.LoadingMuseum, 0);
} }
} }
static void JoinMuseum(Player p, string name, string path) { static void JoinMuseum(Player p, string name, string mapName, string path) {
Level lvl = IMapImporter.Formats[0].Read(path, name, false); Level lvl = IMapImporter.Formats[0].Read(path, name, false);
lvl.MapName = mapName;
SetLevelProps(lvl); SetLevelProps(lvl);
Level.LoadMetadata(lvl);
p.Loading = true; p.Loading = true;
Entities.DespawnEntities(p); Entities.DespawnEntities(p);

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Levels.IO {
} }
public static void LoadEnv(Level level) { public static void LoadEnv(Level level) {
string path = "levels/level properties/" + level.name + ".env"; string path = "levels/level properties/" + level.MapName.ToLower() + ".env";
PropertiesFile.Read(path, ref level, EnvLineProcessor); PropertiesFile.Read(path, ref level, EnvLineProcessor);
} }

View File

@ -28,7 +28,7 @@ using MCGalaxy.Util;
namespace MCGalaxy { namespace MCGalaxy {
public sealed partial class Level : IDisposable { public sealed partial class Level : IDisposable {
public string name; public string name, MapName;
[ConfigString("MOTD", "General", null, "ignore", true, null, 128)] [ConfigString("MOTD", "General", null, "ignore", true, null, 128)]
public string motd = "ignore"; public string motd = "ignore";

View File

@ -38,7 +38,7 @@ namespace MCGalaxy {
public enum BuildType { Normal, ModifyOnly, NoModify }; public enum BuildType { Normal, ModifyOnly, NoModify };
public sealed partial class Level : IDisposable { public sealed partial class Level : IDisposable {
public Level(string n, ushort x, ushort y, ushort z) { Init(n, x, y, z); } public Level(string n, ushort x, ushort y, ushort z) { Init(n, x, y, z); }
@ -56,9 +56,7 @@ namespace MCGalaxy {
} }
void Init(string n, ushort x, ushort y, ushort z) { void Init(string n, ushort x, ushort y, ushort z) {
Width = x; Width = x; Height = y; Length = z;
Height = y;
Length = z;
if (Width < 16) Width = 16; if (Width < 16) Width = 16;
if (Height < 16) Height = 16; if (Height < 16) Height = 16;
if (Length < 16) Length = 16; if (Length < 16) Length = 16;
@ -74,9 +72,9 @@ namespace MCGalaxy {
CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i]; CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
CustomBlockProps = new BlockProps[256]; CustomBlockProps = new BlockProps[256];
for (int i = 0; i < CustomBlockProps.Length; i++) for (int i = 0; i < CustomBlockProps.Length; i++)
CustomBlockProps[i] = BlockDefinition.GlobalProps[i]; CustomBlockProps[i] = BlockDefinition.GlobalProps[i];
name = n; name = n; MapName = n;
BlockDB = new BlockDB(this); BlockDB = new BlockDB(this);
EdgeLevel = (short)(y / 2); EdgeLevel = (short)(y / 2);
CloudsHeight = (short)(y + 2); CloudsHeight = (short)(y + 2);
@ -85,7 +83,7 @@ namespace MCGalaxy {
ChunksX = (Width + 15) >> 4; ChunksX = (Width + 15) >> 4;
ChunksY = (Height + 15) >> 4; ChunksY = (Height + 15) >> 4;
ChunksZ = (Length + 15) >> 4; ChunksZ = (Length + 15) >> 4;
CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][]; CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][];
spawnx = (ushort)(Width / 2); spawnx = (ushort)(Width / 2);
spawny = (ushort)(Height * 0.75f); spawny = (ushort)(Height * 0.75f);
@ -124,36 +122,36 @@ namespace MCGalaxy {
return String.IsNullOrEmpty(p.group.MOTD) ? Server.motd : p.group.MOTD; return String.IsNullOrEmpty(p.group.MOTD) ? Server.motd : p.group.MOTD;
} }
/// <summary> Whether block changes made on this level should be /// <summary> Whether block changes made on this level should be
/// saved to the BlockDB and .lvl files. </summary> /// saved to the BlockDB and .lvl files. </summary>
public bool ShouldSaveChanges() { public bool ShouldSaveChanges() {
if (!saveLevel) return false; if (!saveLevel) return false;
ZombieGame zs = Server.zombie; ZombieGame zs = Server.zombie;
if (zs.Running && !ZombieGameProps.SaveLevelBlockchanges && if (zs.Running && !ZombieGameProps.SaveLevelBlockchanges &&
(name.CaselessEq(zs.CurLevelName) || name.CaselessEq(zs.LastLevelName))) (name.CaselessEq(zs.CurLevelName) || name.CaselessEq(zs.LastLevelName)))
return false; return false;
if (Server.lava.active && Server.lava.HasMap(name)) if (Server.lava.active && Server.lava.HasMap(name))
return false; return false;
return true; return true;
} }
public bool ShouldShowJoinMessage(Level prev) { public bool ShouldShowJoinMessage(Level prev) {
ZombieGame zs = Server.zombie; ZombieGame zs = Server.zombie;
if (zs.Running && name.CaselessEq(zs.CurLevelName) && if (zs.Running && name.CaselessEq(zs.CurLevelName) &&
(prev == this || zs.LastLevelName == "" || prev.name.CaselessEq(zs.LastLevelName))) (prev == this || zs.LastLevelName == "" || prev.name.CaselessEq(zs.LastLevelName)))
return false; return false;
if (Server.lava.active && Server.lava.HasMap(name)) if (Server.lava.active && Server.lava.HasMap(name))
return false; return false;
return true; return true;
} }
/// <summary> The currently active game running on this map, /// <summary> The currently active game running on this map,
/// or null if there is no game running. </summary> /// or null if there is no game running. </summary>
public IGame CurrentGame() { public IGame CurrentGame() {
if (Server.zombie.Running && name.CaselessEq(Server.zombie.CurLevelName)) if (Server.zombie.Running && name.CaselessEq(Server.zombie.CurLevelName))
return Server.zombie; return Server.zombie;
if (Server.lava.active && Server.lava.map == this) if (Server.lava.active && Server.lava.map == this)
return Server.lava; return Server.lava;
return null; return null;
} }
@ -213,14 +211,14 @@ namespace MCGalaxy {
} }
void MovePlayersToMain() { void MovePlayersToMain() {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) { foreach (Player p in players) {
if (p.level == this) { if (p.level == this) {
Player.Message(p, "You were moved to the main level as " + ColoredName + " %Swas unloaded."); Player.Message(p, "You were moved to the main level as " + ColoredName + " %Swas unloaded.");
PlayerActions.ChangeMap(p, Server.mainLevel); PlayerActions.ChangeMap(p, Server.mainLevel);
} }
} }
} }
/// <summary> Returns whether the given coordinates are insides the boundaries of this level. </summary> /// <summary> Returns whether the given coordinates are insides the boundaries of this level. </summary>
public bool InBound(ushort x, ushort y, ushort z) { public bool InBound(ushort x, ushort y, ushort z) {
@ -257,7 +255,7 @@ namespace MCGalaxy {
if (!Directory.Exists("levels/level properties")) Directory.CreateDirectory("levels/level properties"); if (!Directory.Exists("levels/level properties")) Directory.CreateDirectory("levels/level properties");
if (!Directory.Exists("levels/prev")) Directory.CreateDirectory("levels/prev"); if (!Directory.Exists("levels/prev")) Directory.CreateDirectory("levels/prev");
if (changed || !File.Exists(path) || Override || (physicschanged && clearPhysics)) { if (changed || !File.Exists(path) || Override || (physicschanged && clearPhysics)) {
lock (saveLock) lock (saveLock)
SaveCore(path); SaveCore(path);
@ -350,56 +348,62 @@ namespace MCGalaxy {
} }
try { try {
Level level = IMapImporter.Formats[0].Read(path, name, true); Level lvl = IMapImporter.Formats[0].Read(path, name, true);
level.setPhysics(phys); lvl.setPhysics(phys);
level.backedup = true; lvl.backedup = true;
level.jailx = (ushort)(level.spawnx * 32); lvl.jailx = (ushort)(lvl.spawnx * 32);
level.jaily = (ushort)(level.spawny * 32); lvl.jaily = (ushort)(lvl.spawny * 32);
level.jailz = (ushort)(level.spawnz * 32); lvl.jailz = (ushort)(lvl.spawnz * 32);
level.jailrotx = level.rotx; lvl.jailrotx = lvl.rotx;
level.jailroty = level.roty; lvl.jailroty = lvl.roty;
level.StartPhysics(); lvl.StartPhysics();
try {
string propsPath = LevelInfo.FindPropertiesFile(level.name);
if (propsPath != null)
LvlProperties.Load(level, propsPath);
else
Server.s.Log(".properties file for level " + level.name + " was not found.");
// Backwards compatibility for older levels which had .env files.
LvlProperties.LoadEnv(level);
} catch (Exception e) {
Server.ErrorLog(e);
}
level.BlockDB.Cache.Enabled = level.UseBlockDB;
BlockDefinition[] defs = BlockDefinition.Load(false, level);
for (int i = 0; i < defs.Length; i++) {
if (defs[i] == null) continue;
level.CustomBlockDefs[i] = defs[i];
level.CustomBlockProps[i] = new BlockProps((byte)i);
}
BlockProps.Load("lvl_" + level.name, level.CustomBlockProps);
Bots.BotsFile.LoadBots(level);
LoadMetadata(lvl);
Bots.BotsFile.LoadBots(lvl);
object locker = ThreadSafeCache.DBCache.Get(name); object locker = ThreadSafeCache.DBCache.Get(name);
lock (locker) { lock (locker) {
LevelDB.LoadZones(level, name); LevelDB.LoadZones(lvl, name);
LevelDB.LoadPortals(level, name); LevelDB.LoadPortals(lvl, name);
LevelDB.LoadMessages(level, name); LevelDB.LoadMessages(lvl, name);
} }
Server.s.Log(string.Format("Level \"{0}\" loaded.", level.name)); Server.s.Log(string.Format("Level \"{0}\" loaded.", lvl.name));
if (LevelLoaded != null) if (LevelLoaded != null)
LevelLoaded(level); LevelLoaded(lvl);
OnLevelLoadedEvent.Call(level); OnLevelLoadedEvent.Call(lvl);
return level; return lvl;
} catch (Exception ex) { } catch (Exception ex) {
Server.ErrorLog(ex); Server.ErrorLog(ex);
return null; return null;
} }
} }
public static void LoadMetadata(Level lvl) {
try {
string propsPath = LevelInfo.FindPropertiesFile(lvl.MapName);
if (propsPath != null) {
LvlProperties.Load(lvl, propsPath);
} else {
Server.s.Log(".properties file for level " + lvl.MapName + " was not found.");
}
// Backwards compatibility for older levels which had .env files.
LvlProperties.LoadEnv(lvl);
} catch (Exception e) {
Server.ErrorLog(e);
}
lvl.BlockDB.Cache.Enabled = lvl.UseBlockDB;
BlockDefinition[] defs = BlockDefinition.Load(false, lvl);
for (int i = 0; i < defs.Length; i++) {
if (defs[i] == null) continue;
lvl.CustomBlockDefs[i] = defs[i];
lvl.CustomBlockProps[i] = new BlockProps((byte)i);
}
BlockProps.Load("lvl_" + lvl.MapName, lvl.CustomBlockProps);
}
public static bool CheckLoadOnGoto(string givenName) { public static bool CheckLoadOnGoto(string givenName) {
string value = LevelInfo.FindOfflineProperty(givenName, "loadongoto"); string value = LevelInfo.FindOfflineProperty(givenName, "loadongoto");
@ -409,8 +413,8 @@ namespace MCGalaxy {
return load; return load;
} }
public void ChatLevel(string message) { public void ChatLevel(string message) {
ChatLevel(message, LevelPermission.Banned); ChatLevel(message, LevelPermission.Banned);
} }
public void ChatLevelOps(string message) { public void ChatLevelOps(string message) {
@ -418,14 +422,14 @@ namespace MCGalaxy {
ChatLevel(message, rank); ChatLevel(message, rank);
} }
public void ChatLevelAdmins(string message) { public void ChatLevelAdmins(string message) {
LevelPermission rank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin); LevelPermission rank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin);
ChatLevel(message, rank); ChatLevel(message, rank);
} }
/// <summary> Sends a chat messages to all players in the level, who have at least the minPerm rank. </summary> /// <summary> Sends a chat messages to all players in the level, who have at least the minPerm rank. </summary>
public void ChatLevel(string message, LevelPermission minPerm) { public void ChatLevel(string message, LevelPermission minPerm) {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { foreach (Player pl in players) {
if (pl.level != this) continue; if (pl.level != this) continue;
if (pl.Rank < minPerm) continue; if (pl.Rank < minPerm) continue;
@ -434,7 +438,7 @@ namespace MCGalaxy {
} }
public void UpdateBlockPermissions() { public void UpdateBlockPermissions() {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) { foreach (Player p in players) {
if (p.level != this) continue; if (p.level != this) continue;
if (!p.HasCpeExt(CpeExt.BlockPermissions)) continue; if (!p.HasCpeExt(CpeExt.BlockPermissions)) continue;
@ -452,7 +456,7 @@ namespace MCGalaxy {
public static string PermissionToName(LevelPermission perm) { return Group.GetName(perm); } public static string PermissionToName(LevelPermission perm) { return Group.GetName(perm); }
public bool HasPlayers() { public bool HasPlayers() {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) foreach (Player p in players)
if (p.level == this) return true; if (p.level == this) return true;
return false; return false;
@ -461,7 +465,7 @@ namespace MCGalaxy {
readonly object dbLock = new object(); readonly object dbLock = new object();
public void saveChanges() { public void saveChanges() {
lock (dbLock) lock (dbLock)
LevelDB.SaveBlockDB(this); LevelDB.SaveBlockDB(this);
} }
public List<Player> getPlayers() { public List<Player> getPlayers() {
@ -487,7 +491,7 @@ namespace MCGalaxy {
oldRawType = oldExtType; flags |= 1; oldRawType = oldExtType; flags |= 1;
} else { } else {
oldRawType = oldType; oldRawType = oldType;
} }
if (newType == Block.custom_block) { if (newType == Block.custom_block) {
newRawType = newExtType; flags |= 2; newRawType = newExtType; flags |= 2;
} else { } else {