public World([NotNull] string name, [NotNull] XElement el)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (el == null)
{
throw new ArgumentNullException("el");
}
if (!IsValidName(name))
{
throw new ArgumentException("Unacceptable world name.");
}
Name = name;
BlockDB = new BlockDB(this);
UpdatePlayerList();
XAttribute tempAttr;
// load hidden status
if ((tempAttr = el.Attribute("hidden")) != null)
{
bool isHidden;
if (Boolean.TryParse(tempAttr.Value, out isHidden))
{
IsHidden = isHidden;
}
else
{
Logger.Log(LogType.Warning,
"World: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.",
Name);
}
}
// load access and build security
XElement tempEl;
if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null)
{
AccessSecurity = new SecurityController(tempEl, true);
}
else if ((tempEl = el.Element("accessSecurity")) != null)
{
AccessSecurity = new SecurityController(tempEl, true);
}
else
{
AccessSecurity = new SecurityController();
}
if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null)
{
BuildSecurity = new SecurityController(tempEl, true);
}
else if ((tempEl = el.Element("buildSecurity")) != null)
{
BuildSecurity = new SecurityController(tempEl, true);
}
else
{
BuildSecurity = new SecurityController();
}
// load backup interval
if ((tempAttr = el.Attribute("backup")) != null)
{
if (!tempAttr.Value.ToTimeSpan(out backupInterval))
{
backupInterval = BackupIntervalDefault;
Logger.Log(LogType.Warning,
"WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).",
Name,
BackupInterval.ToMiniString());
}
}
else
{
BackupInterval = BackupIntervalDefault;
}
// load BlockDB settings
XElement blockEl = el.Element(BlockDB.XmlRootName);
if (blockEl != null)
{
BlockDB.LoadSettings(blockEl);
}
// load map (if needed)
Preload = (el.Attribute("noUnload") != null);
// load environment settings
XElement envEl = el.Element(EnvironmentXmlTagName);
if (envEl != null)
{
if ((tempAttr = envEl.Attribute("cloud")) != null)
{
if (!Int32.TryParse(tempAttr.Value, out CloudColor))
{
CloudColor = -1;
Logger.Log(LogType.Warning,
"WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
Name);
}
}
if ((tempAttr = envEl.Attribute("fog")) != null)
{
if (!Int32.TryParse(tempAttr.Value, out FogColor))
{
FogColor = -1;
Logger.Log(LogType.Warning,
"WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
Name);
}
}
if ((tempAttr = envEl.Attribute("sky")) != null)
{
if (!Int32.TryParse(tempAttr.Value, out SkyColor))
{
SkyColor = -1;
Logger.Log(LogType.Warning,
"WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
Name);
}
}
if ((tempAttr = envEl.Attribute("level")) != null)
{
if (!Int32.TryParse(tempAttr.Value, out EdgeLevel))
{
EdgeLevel = -1;
Logger.Log(LogType.Warning,
"WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
Name);
}
}
if ((tempAttr = envEl.Attribute("edge")) != null)
{
Block block;
if (!Map.GetBlockByName(tempAttr.Value, false, out block))
{
EdgeBlock = Block.Water;
Logger.Log(LogType.Warning,
"WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
Name);
}
else
{
if (Map.GetEdgeTexture(block) == null)
{
EdgeBlock = Block.Water;
Logger.Log(LogType.Warning,
"WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
Name);
}
else
{
EdgeBlock = block;
}
}
}
}
}