Ejemplo n.º 1
0
        public static void Save(RegionList regions)
        {
            if (regions == null)
                return;

            lock (regions)
            {
                //Remove all empty regions
                List<WorldRegion > rem = new List<WorldRegion>();
                foreach (WorldRegion w in regions.List)
                    if (Empty(w))
                        rem.Add(w);
                foreach (WorldRegion r in rem)
                    regions.List.Remove(r);
			
                //Only save WorldREgion no static regions
                RegionList saveList = new RegionList();
                foreach (WorldRegion w in regions.List)
                {
                    if (w.GetType() == typeof(WorldRegion))
                        saveList.List.Add(w);
                }

                Json.Save(regions.FilePath, saveList);

                MineProxy.Regions.WarpPortalVisuals.RegionsUpdated(regions.List);
            }
        }
Ejemplo n.º 2
0
 public static void CleanBanned(RegionList regions)
 {
     lock (regions)
     {
         int rem = CleanBanned(regions.List);
         Save(regions);
         Chatting.Parser.TellAdmin("Removed banned residents: " + rem);
     }
 }
Ejemplo n.º 3
0
        public static RegionList Load(string regionPath)
        {
            RegionList r = Json.Load<RegionList>(regionPath);

            if (r == null)
                r = new RegionList();
            r.FilePath = regionPath;
            Update(r.List);
            return r;
        }
Ejemplo n.º 4
0
        public static RegionList Load(string regionPath)
        {
            RegionList r = Json.Load <RegionList>(regionPath);

            if (r == null)
            {
                r = new RegionList();
            }
            r.FilePath = regionPath;
            Update(r.List);
            return(r);
        }
Ejemplo n.º 5
0
        internal void AddPlayer(string residentPlayer, string newResident, RegionList region)
        {
            Residents.Add(newResident);
            RegionLoader.Save(region);
            Log.WritePlayer(residentPlayer, "Region added resident " + newResident);
            Client nr = PlayerList.GetPlayerByName(newResident);

            if (nr != null)
            {
                nr.TellSystem(Chat.Aqua, residentPlayer + " added you to " + Name);
                RegionCrossing.SetRegion(nr.Session);
            }
        }
Ejemplo n.º 6
0
        internal void Rename(Client player, string name)
        {
            RegionList region = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            Log.WritePlayer(player, "Region renamed " + Name + " to " + name);
            TellResidentsSystem(null, Chat.Blue, player.Name + " renamed " + Name + " to " + name);
            Name = name;
            RegionLoader.Save(region);
            Entering(player);
        }
Ejemplo n.º 7
0
        internal void AddPlayer(Client player, string newResident)
        {
            RegionList regions = player.Session.World.Regions;

            if (IsResident(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                if (player.Admin() == false)
                {
                    return;
                }
            }

            AddPlayer(player.MinecraftUsername, newResident, regions);
            player.TellSystem(Chat.Aqua, newResident + " added to " + Name);
        }
Ejemplo n.º 8
0
        internal void SetReport(Client player, string state)
        {
            RegionList regions = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            if (state == "on")
            {
                ReportVisits = true;
            }
            if (state == "off")
            {
                ReportVisits = false;
            }
            RegionLoader.Save(regions);
        }
Ejemplo n.º 9
0
        internal void SetMessage(Client player, string message)
        {
            RegionList regions = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            if (message == "-" || message == "off" || message == "rem" || message == "remove")
            {
                message = null;
            }
            Message = message;
            Log.WritePlayer(player, "Message for " + Name + " set to " + Message);
            RegionLoader.Save(regions);

            TellResidentsSystem(null, Chat.Blue, player.Name + " changed region message to " + Message);
        }
Ejemplo n.º 10
0
        public static void Save(RegionList regions)
        {
            if (regions == null)
            {
                return;
            }

            lock (regions)
            {
                //Remove all empty regions
                List <WorldRegion> rem = new List <WorldRegion>();
                foreach (WorldRegion w in regions.List)
                {
                    if (Empty(w))
                    {
                        rem.Add(w);
                    }
                }
                foreach (WorldRegion r in rem)
                {
                    regions.List.Remove(r);
                }

                //Only save WorldREgion no static regions
                RegionList saveList = new RegionList();
                foreach (WorldRegion w in regions.List)
                {
                    if (w.GetType() == typeof(WorldRegion))
                    {
                        saveList.List.Add(w);
                    }
                }

                Json.Save(regions.FilePath, saveList);

                MineProxy.Regions.WarpPortalVisuals.RegionsUpdated(regions.List);
            }
        }
Ejemplo n.º 11
0
        internal void RemovePlayer(Client player, string removeUsername)
        {
            RegionList regions = player.Session.World.Regions;

            if (ResidentPermissions(player) == false)
            {
                Log.WritePlayer(player, "Failed to remove " + removeUsername + " from region " + Name);
                player.TellSystem(Chat.Yellow, " You are not a resident of this region");
                return;
            }

            removeUsername = removeUsername.ToLowerInvariant();
            foreach (string s in Residents)
            {
                if (s.ToLowerInvariant() == removeUsername)
                {
                    removeUsername = s;
                    break;
                }
            }
            if (Residents.Remove(removeUsername) == false)
            {
                player.TellSystem(Chat.Red, removeUsername + " not found in region " + Name);
                return;
            }

            Log.WritePlayer(player, "Region: removed resident " + removeUsername);
            RegionLoader.Save(regions);
            player.TellSystem(Chat.Aqua, removeUsername + " removed from " + Name);
            Client p = PlayerList.GetPlayerByName(removeUsername);

            if (p != null && p != player)
            {
                p.TellSystem(Chat.Aqua, player.Name + " removed you from " + Name);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// return the list "region" is located in
 /// </summary>
 public static List <WorldRegion> GetParentList(RegionList regions, WorldRegion region)
 {
     return(GetParentList(regions.List, region));
 }
Ejemplo n.º 13
0
        public void Resize(int minX, int maxX, int minY, int maxY, int minZ, int maxZ, Client player)
        {
            RegionList regions = player.Session.World.Regions;

            Region      test   = new Region(minX, maxX, minY, maxY, minZ, maxZ);
            WorldRegion parent = RegionCrossing.GetParentRegion(regions.List, this);

            if (parent == null)
            {
                player.TellSystem(Chat.Red, "parent not found");
                return;
            }

            if (player.Admin() == false)
            {
                if ((Donors.IsDonor(player) == false))
                {
                    player.TellSystem(Chat.Aqua, "Only for donors and admins may resize a region");
                    return;
                }
                //Useless since when only donors get this far:
                if (minY < 50 && (!player.Donor))
                {
                    player.TellSystem(Chat.Red, "Only admins and donors may make regions below Y=50");
                    return;
                }
                if (ResidentPermissions(player) == false)
                {
                    player.TellSystem(Chat.Yellow, "You are not a resident of this region");
                    return;
                }

                if (parent.ResidentPermissions(player) == false)
                {
                    player.TellSystem(Chat.Yellow, "You are not a resident of the parent region");
                    return;
                }
            }

            List <WorldRegion> list;

            if (parent == this)
            {
                list = player.Session.World.Regions.List;
            }
            else
            {
                list = parent.SubRegions;
            }

            //Make sure the new size overlaps the old one so we don't make huge mistakes
            if (test.Overlap(this) == false)
            {
                player.TellSystem(Chat.Red, "New size must overlap old one");
                player.TellSystem(Chat.Red, "New size " + test);
                player.TellSystem(Chat.Red, "Old size " + this.Coords());
                return;
            }

            //Check that the new size fits in the parent
            if (parent != this)
            {
                if (parent.Cover(test) == false)
                {
                    player.TellSystem(Chat.Red, "parent " + parent.Name + " is too small " + parent.Coords());
                    return;
                }
            }
            //else we are in the top level, no limit there

            //Make sure new size does not collide with siblings
            foreach (WorldRegion w in list)
            {
                if (w.Dimension != Dimension) //If toplevel "siblings" are all toplevel regions
                {
                    continue;
                }
                if (w == this)
                {
                    continue;
                }
                if (w.Overlap(test))
                {
                    player.TellSystem(Chat.Red, "new size overlap sibling " + w);
                    return;
                }
            }

            //Chech that subregions still fit into the new size
            if (SubRegions != null)
            {
                foreach (WorldRegion w in SubRegions)
                {
                    if (test.Cover(w) == false)
                    {
                        player.TellSystem(Chat.Red, "New size does not cover subregion:");
                        player.TellSystem(Chat.Red, w.ToString());
                        return;
                    }
                }
            }

            Log.WritePlayer(player, "Region Resized: from " + this + " to " + test);
            MinX = test.MinX;
            MaxX = test.MaxX;
            MinY = test.MinY;
            MaxY = test.MaxY;
            MinZ = test.MinZ;
            MaxZ = test.MaxZ;
            RegionLoader.Save(regions);
            player.TellSystem(Chat.Purple, "Region resized: " + this);
        }
Ejemplo n.º 14
0
 public static WorldRegion GetRegion(CoordDouble pos, Dimensions dimension, RegionList regions)
 {
     if (regions == null)
         return null;
     return GetRegion(regions.List, pos, dimension);
 }
Ejemplo n.º 15
0
 public void LoadRegions()
 {
     Regions = RegionLoader.Load("main/regions.json");
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Find region and send message
        /// </summary>
        internal static void SetRegion(WorldSession session)
        {
            RegionList regions = session.World.Regions;

            if (regions == null)
            {
                return;
            }

            try
            {
                //This is called every single player movement, 20 times a second, some optimization might be needed.
                WorldRegion w = null;
                //First test if we are in the same as before
                WorldRegion current = session.CurrentRegion;
                if (current != null)
                {
                    if (current.Deleted == false && current.Contains(session.Position))
                    {
                        w = GetRegion(current.SubRegions, session.Position, session.Dimension);
                        if (w == null)
                        {
                            w = current;
                        }
                    }
                }
                if (w == null)
                {
                    w = GetRegion(regions.List, session.Position, session.Dimension);
                }

                //Debug.Write("Setregion: " + w);

                //If different
                if (session.CurrentRegion != w)
                {
                    //Leaving
                    if (session.CurrentRegion != null && (session.CurrentRegion.HasChild(w) == false))
                    {
                        session.CurrentRegion.Leaving(session.Player, w);
                    }

                    //Entering
                    if (w != null && w.HasChild(session.CurrentRegion) == false)
                    {
                        w.Entering(session.Player);
                    }

                    //Stats
                    SetStats(session.CurrentRegion, session.Player);
                    SetStats(w, session.Player);
                }
                //Adjust Survival/Adventure mode
                if (session.Mode != GameMode.Creative &&
                    session.Mode != GameMode.Spectator)
                {
                    bool protect = Protected.IsBlockProtected(session, w);
                    if (protect && w.IsResident(session.Player))
                    {
                        protect = false;
                    }

                    if (protect)
                    {
                        session.SetMode(GameMode.Adventure);
                    }
                    else
                    {
                        session.SetMode(GameMode.Survival);
                    }
                }

                if (w != null && w.Type == WarpZone.Type)
                {
                    if (session.Mode != GameMode.Creative)
                    {
                        WarpZone wz = new WarpZone(w.Name);
                        session.Player.Warp(wz.Destination, (Dimensions)wz.DestinationDimension, wz.DesinationWorld);
                    }
                }

                bool update = (w != session.CurrentRegion);
                session.CurrentRegion = w;
                if (update)
                {
                    ScoreboardRegionManager.UpdateRegion(session.Player);
                }
#if !DEBUG
            } catch (Exception e)
            {
                Log.WriteServer(e);
                return;
#endif
            } finally
            {
            }
        }