Exemple #1
0
        // update/set the jail position in the world
        public static void setJailPosition(Players.Player causedBy, uint range = DEFAULT_RANGE)
        {
            // if an old jail position existed remove its protection area
            if (validJail)
            {
                Pipliz.Vector3Int    oldPos  = new Pipliz.Vector3Int(jailPosition);
                CustomProtectionArea oldJail = null;
                foreach (CustomProtectionArea area in AntiGrief.CustomAreas)
                {
                    if (area.Equals(oldPos, range))
                    {
                        oldJail = area;
                    }
                }
                if (oldJail != null)
                {
                    AntiGrief.RemoveCustomArea(oldJail);
                    Chat.Send(causedBy, String.Format("Removed old jail protection area at {0} {1}", (int)jailPosition.x, (int)jailPosition.z));
                }
            }

            jailPosition.x = causedBy.Position.x;
            jailPosition.y = causedBy.Position.y + 1; // one block higher to prevent clipping
            jailPosition.z = causedBy.Position.z;
            jailRange      = range;
            validJail      = true;
            Save();

            Pipliz.Vector3Int playerPos = new Pipliz.Vector3Int(causedBy.Position);
            AntiGrief.AddCustomArea(new CustomProtectionArea(playerPos, (int)range, (int)range));
            Chat.Send(causedBy, "Created new custom protection area");

            return;
        }
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/customarea"))
            {
                return(false);
            }
            Pipliz.Vector3Int    playerPos   = new Vector3Int(causedBy.Position);
            CustomProtectionArea closestArea = null;
            int shortestDistance             = int.MaxValue;

            foreach (CustomProtectionArea area in AntiGrief.CustomAreas)
            {
                if (area.Contains(playerPos))
                {
                    Chat.Send(causedBy, $"You are inside a custom area: from {area.StartX}, {area.StartZ} to {area.EndX}, {area.EndZ}");
                    return(true);
                }
                int distance = area.DistanceToCenter(playerPos);
                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                    closestArea      = area;
                }
            }

            if (closestArea != null)
            {
                Chat.Send(causedBy, $"The closest area is at: {closestArea.StartX}, {closestArea.StartZ} to {closestArea.EndX}, {closestArea.EndZ}. {shortestDistance} blocks away");
            }
            else
            {
                Chat.Send(causedBy, "No areas found - try /bannername?");
            }

            return(true);
        }
Exemple #3
0
 public static void RemoveCustomArea(CustomProtectionArea area)
 {
     CustomAreas.Remove(area);
     Save();
 }
Exemple #4
0
 public static void AddCustomArea(CustomProtectionArea area)
 {
     CustomAreas.Add(area);
     Save();
 }