private void LoadHouseData() { XmlNode playerNode, houseNode, dataNode; XmlNodeList playerNodes; IEnumerator playerEnum, houseEnum, dataEnum; PlayerHouses playerHouse; PlayerHouseCoords playerHouseCoords; bool lockChests = true, lockDoors = true, lockSigns = true; xmlFilename = pluginFolder + Path.DirectorySeparatorChar + xmlFilename; if (!File.Exists(xmlFilename)) { houseXML = new XmlDocument(); XmlNode node = houseXML.CreateNode(XmlNodeType.XmlDeclaration, "xml", xmlNamespace); houseXML.AppendChild(node); node = houseXML.CreateNode(XmlNodeType.Element, "players", xmlNamespace); houseXML.AppendChild(node); houseXML.Save(xmlFilename); Program.tConsole.WriteLine(houseXML.InnerText); } houseXML.Load(xmlFilename); playerNodes = houseXML.GetElementsByTagName("player"); playerEnum = playerNodes.GetEnumerator(); while (playerEnum.MoveNext()) { // Set player information playerNode = (XmlNode)playerEnum.Current; playerHouse = new PlayerHouses(); playerHouse.PlayerName = playerNode.Attributes["id"].Value; playerHouse.Houses = new List<PlayerHouseCoords>(); // Loop through player data dataEnum = playerNode.ChildNodes.GetEnumerator(); while (dataEnum.MoveNext()) { // Set House Information dataNode = (XmlNode)dataEnum.Current; switch (dataNode.Name.ToUpper()) { case "LOCKCHESTS": lockChests = Boolean.Parse(dataNode.InnerXml); break; case "LOCKDOORS": lockDoors = Boolean.Parse(dataNode.InnerXml); break; case "LOCKSIGNS": lockSigns = Boolean.Parse(dataNode.InnerXml); break; case "HOUSES": // Loop through house data int houseCount = 0; houseEnum = dataNode.ChildNodes.GetEnumerator(); while (houseEnum.MoveNext()) { string houseName = null; houseNode = (XmlNode)houseEnum.Current; for (int i = 0; i < houseNode.Attributes.Count; i++) { if (houseNode.Attributes[i].Name.ToUpper() == "NAME") houseName = houseNode.Attributes[i].Value; } if (houseName == null) houseName = "house" + houseCount; playerHouseCoords = new PlayerHouseCoords(houseName); playerHouseCoords.TopLeft.X = Int32.Parse(houseNode["topleft"]["x"].InnerXml); playerHouseCoords.TopLeft.Y = Int32.Parse(houseNode["topleft"]["y"].InnerXml); playerHouseCoords.BottomRight.X = Int32.Parse(houseNode["bottomright"]["x"].InnerXml); playerHouseCoords.BottomRight.Y = Int32.Parse(houseNode["bottomright"]["y"].InnerXml); playerHouseCoords.LockChests = lockChests; playerHouseCoords.LockDoors = lockDoors; playerHouseCoords.LockSigns = lockSigns; for (int i = 0; i < houseNode.ChildNodes.Count; i++) { switch (houseNode.ChildNodes[i].Name.ToUpper()) { case "ALLOW": for (int j = 0; j < houseNode.ChildNodes[i].ChildNodes.Count; j++) { playerHouseCoords.Allowed.Add(houseNode.ChildNodes[i].ChildNodes[j].InnerXml); } break; case "LOCKCHESTS": playerHouseCoords.LockChests = Boolean.Parse(houseNode.ChildNodes[i].InnerXml); break; case "LOCKDOORS": playerHouseCoords.LockDoors = Boolean.Parse(houseNode.ChildNodes[i].InnerXml); break; case "LOCKSIGNS": playerHouseCoords.LockSigns = Boolean.Parse(houseNode.ChildNodes[i].InnerXml); break; case "TELEPORTPOINT": playerHouseCoords.TeleportPoint.X = Int32.Parse(houseNode.ChildNodes[i]["x"].InnerXml); playerHouseCoords.TeleportPoint.Y = Int32.Parse(houseNode.ChildNodes[i]["y"].InnerXml); break; } } playerHouse.Houses.Add(playerHouseCoords); houseCount++; } break; } } playerHouses.Add(playerHouse); } }
public bool CreatePlayerHouse(string PlayerName, int houseIndex = 0) { foreach (PlayerHouses i in playerHouses) { if (i.PlayerName == PlayerName) { return false; } } PlayerHouses playerHouse = new PlayerHouses(PlayerName); playerHouses.Add(playerHouse); return true; }