示例#1
0
        public static void UpdateWarp(Warp warp)
        {
            int Index;

            if (ContainsWarp(warp.Name, out Index))
            {
                WarpList.ToArray()[Index] = warp;
            }
        }
示例#2
0
 public override bool Equals(object obj)
 {
     if (obj is Warp)
     {
         Warp warp = (Warp)obj;
         return(warp == this);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
 public static Warp GetWarp(string WarpName, out int Index)
 {
     Index = -1;
     for (int i = 0; i < WarpList.Count; i++)
     {
         Warp warp = WarpList.ToArray()[i];
         if (warp.Name.Trim().ToLower() == WarpName.Trim().ToLower())
         {
             Index = i;
             return(warp);
         }
     }
     return(default(Warp));
 }
示例#4
0
 public static bool ContainsWarp(string WarpName, out int Index)
 {
     Index = -1;
     for (int i = 0; i < WarpList.Count; i++)
     {
         Warp warp = WarpList.ToArray()[i];
         if (warp.Name.Trim().ToLower() == WarpName.Trim().ToLower())
         {
             Index = i;
             return(true);
         }
     }
     return(false);
 }
        public override void OnExecute( ICommandSource source, ICommandArgs parameters )
        {
            switch ( parameters.Length )
            {
                case 1:
                    if ( source.IsConsole )
                    {
                        ShowUsage( source );
                        break;
                    }

                    var player = source.ToPlayer();
                    var warp = new Warp( parameters[0].ToString(),  player.Position, player.Rotation );
                    EssProvider.WarpManager.Add( warp );
                    EssLang.WARP_SET.SendTo( source, parameters[0] );
                    break;

                case 4:
                    var pos = parameters.GetVector3( 1 );

                    if ( pos.HasValue )
                    {
                        warp = new Warp( parameters[0].ToString(), pos.Value, 0.0F );

                        EssProvider.WarpManager.Add( warp );

                        EssLang.WARP_SET.SendTo( source, parameters[0] );
                    }
                    else
                    {
                        EssLang.INVALID_COORDS.SendTo( source, parameters[1], parameters[2], parameters[3] );
                    }
                    break;

                default:
                    ShowUsage( source );
                    break;
            }
        }
示例#6
0
        public static List<Warp> LoadData(string WarpRecords)
        {
            WarpList = new List<Warp>();

            XmlDocument xmlReader = new XmlDocument();

            xmlReader.Load(WarpRecords);

            foreach (XmlElement element in xmlReader.DocumentElement.ChildNodes)
            {
                Warp warp = new Warp()
                {
                    Name = "<LOADING>",
                    Type = WarpType.PUBLIC,
                    Location = default(Vector2),
                    Users = new List<String>()
                };

                foreach (XmlNode nodeList in element.ChildNodes)
                {
                    switch (nodeList.Name.Trim().ToLower())
                    {
                        case "name":
                            {
                                warp.Name = nodeList.InnerText;
                                break;
                            }
                        case "type":
                            {
                                int Type;
                                if (Int32.TryParse(nodeList.InnerText, out Type))
                                    warp.Type = (WarpType)Type;

                                break;
                            }
                        case "location":
                            {
                                float X, Y;
                                if (float.TryParse(nodeList.Attributes["X"].Value, out X) && float.TryParse(nodeList.Attributes["Y"].Value, out Y))
                                    warp.Location = new Vector2(X, Y);
                                else
                                    Essentials.Log("Error loading {0} Location is not a float", warp.Name);
                                break;
                            }
                        case "users":
                            {
                                if(nodeList.HasChildNodes)
                                    foreach (XmlNode node in nodeList.ChildNodes)
                                    {
                                        warp.Users.Add(
                                            CleanUserName(
                                                node.InnerText
                                            )
                                        );
                                    }

                                break;
                            }
                    }
                }

                WarpList.Add(warp);
            }
            return WarpList;
        }
示例#7
0
        public static void WriteWarpElement(XmlWriter xmlWriter, Warp Warp)
        {
            xmlWriter.WriteStartElement("Warp");

                xmlWriter.WriteStartElement("Name");
                xmlWriter.WriteString(Warp.Name);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Location");
                xmlWriter.WriteAttributeString("X", Warp.Location.X.ToString());
                xmlWriter.WriteAttributeString("Y", Warp.Location.Y.ToString());
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Type");
                xmlWriter.WriteString(((int)Warp.Type).ToString());
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Users");
                foreach (string usr in Warp.Users)
                {
                    xmlWriter.WriteStartElement("Name");
                    xmlWriter.WriteString(usr);
                    xmlWriter.WriteEndElement();
                }

                xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
        }
示例#8
0
 public static void UpdateWarp(Warp warp)
 {
     int Index;
     if (ContainsWarp(warp.Name, out Index))
         WarpList.ToArray()[Index] = warp;
 }
示例#9
0
        public static List <Warp> LoadData(string WarpRecords)
        {
            WarpList = new List <Warp>();

            XmlDocument xmlReader = new XmlDocument();

            xmlReader.Load(WarpRecords);

            foreach (XmlElement element in xmlReader.DocumentElement.ChildNodes)
            {
                Warp warp = new Warp()
                {
                    Name     = "<LOADING>",
                    Type     = WarpType.PUBLIC,
                    Location = default(Vector2),
                    Users    = new List <String>()
                };

                foreach (XmlNode nodeList in element.ChildNodes)
                {
                    switch (nodeList.Name.Trim().ToLower())
                    {
                    case "name":
                    {
                        warp.Name = nodeList.InnerText;
                        break;
                    }

                    case "type":
                    {
                        int Type;
                        if (Int32.TryParse(nodeList.InnerText, out Type))
                        {
                            warp.Type = (WarpType)Type;
                        }

                        break;
                    }

                    case "location":
                    {
                        float X, Y;
                        if (float.TryParse(nodeList.Attributes["X"].Value, out X) && float.TryParse(nodeList.Attributes["Y"].Value, out Y))
                        {
                            warp.Location = new Vector2(X, Y);
                        }
                        else
                        {
                            Essentials.Log("Error loading {0} Location is not a float", warp.Name);
                        }
                        break;
                    }

                    case "users":
                    {
                        if (nodeList.HasChildNodes)
                        {
                            foreach (XmlNode node in nodeList.ChildNodes)
                            {
                                warp.Users.Add(
                                    CleanUserName(
                                        node.InnerText
                                        )
                                    );
                            }
                        }

                        break;
                    }
                    }
                }

                WarpList.Add(warp);
            }
            return(WarpList);
        }
示例#10
0
 public void Delete( Warp warp )
 {
     Delete( warp.Name );
 }
示例#11
0
 public bool Contains( Warp warp )
 {
     return WarpMap.ContainsValue( warp );
 }
示例#12
0
 public void Add( Warp warp )
 {
     WarpMap.Add( warp.Name, warp );
     Save();
 }
示例#13
0
        public static void SetWarp(ISender sender, ArgumentList args)
        {
            Vector2 Location = default(Vector2);

            if (!(sender is Player))
            {
                int x, y;
                if (!args.TryParseTwo<Int32, Int32>("", out x, "", out y))
                    throw new CommandError("Non Player Senders need to provide -x & -y tile indices.");
            }
            else
                Location = (sender as Player).Position / 16;

            string name = args.GetString(0);

            Warp warp = new Warp()
            {
                Name = name,
                Location = Location,
                Type = WarpType.PUBLIC,
                Users = new List<String>()
            };

            WarpManager.WarpList.Add(warp);
            WarpManager.Save((args.Plugin as Essentials).WarpFile, "warp");

            sender.Message("Warp {0} has been created.", warp.Name);
        }