private static bool allowBlockFarEnoughFromSpawn(ModLoader.OnTryChangeBlockUserData d)
        {
            if (ColonyAPI.Managers.ConfigManager.getConfigBoolean("ColonyPlusPlus-Utilities", "spawnprotection.enabled"))
            {
                int startingX = ColonyAPI.Helpers.ServerVariableParser.GetVariableAsInt("Terrain.StartingX");
                int startingZ = ColonyAPI.Helpers.ServerVariableParser.GetVariableAsInt("Terrain.StartingZ");

                int distancex, distancez = 0;

                int playerX = (int)Pipliz.Math.RoundToInt(d.voxelHit.x);
                int playerZ = (int)Pipliz.Math.RoundToInt(d.voxelHit.z);

                distancex = System.Math.Abs(playerX - startingX);
                distancez = System.Math.Abs(playerZ - startingZ);

                int SpawnProtectionDistance = ColonyAPI.Managers.ConfigManager.getConfigInt("ColonyPlusPlus-Utilities", "spawnprotection.radius");

                //Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), String.Format("Distance from spawn: X {0}, Z {1}. Protection Radius: {2}", distancex, distancez, SpawnProtectionDistance));



                if (distancex > SpawnProtectionDistance || distancez > SpawnProtectionDistance)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
Example #2
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.TypeNew == HerbStage1.ItemIndex && d.typeTillNow == BuiltinBlocks.Air)
            {
                Items.UpdatableBlocks.Herbs.OnAdd(d.VoxelToChange, HerbStage1.ItemIndex, d.requestedBy);
            }
            else if (d.TypeNew == BuiltinBlocks.Air && (d.typeTillNow == HerbStage1.ItemIndex || d.typeTillNow == HerbStage2.ItemIndex))
            {
                Items.UpdatableBlocks.Herbs.OnRemove(d.VoxelToChange, d.typeTillNow, d.requestedBy);
            }
            else if (d.TypeNew == HerbBench.ItemIndex && d.typeTillNow == BuiltinBlocks.Air)
            {
                _areaJobTracker.Add(new HerbalistJob(new Bounds(d.VoxelToChange.Vector, new Vector3(6, 0, 6)), d.requestedBy, 0));
            }
            else if (d.TypeNew == BuiltinBlocks.Air && d.typeTillNow == HerbBench.ItemIndex)
            {
                var bounds = new Bounds(d.VoxelToChange.Vector, new Vector3(6, 0, 6));
                var jobPos = new Vector3Int(bounds.min);

                _areaJobTracker.GetList(d.requestedBy)[jobPos].OnRemove();
                _areaJobTracker.Remove(jobPos);
            }

            return(true);
        }
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.requestedBy.ID.steamID.m_SteamID == 0)
            {
                return(true);
            }
            bool allowed = Classes.Managers.WorldManager.AllowPlaceBlock(d);

            //Chat.Send(Players.GetPlayer(d.requestedBy.ID), "Block place allowed: " + allowed);
            return(allowed);
        }
Example #4
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData userData)
        {
            Players.Player requestedBy = userData.requestedBy;
            Vector3Int     position    = userData.VoxelToChange;
            Vector3Int     spawn       = TerrainGenerator.GetSpawnLocation();
            int            ox          = position.x - spawn.x;
            int            oz          = position.z - spawn.z;

            if (((ox >= 0 && ox <= SpawnProtectionRangeXPos) || (ox < 0 && ox >= -SpawnProtectionRangeXNeg)) && ((oz >= 0 && oz <= SpawnProtectionRangeZPos) || (oz < 0 && oz >= -SpawnProtectionRangeZNeg)))
            {
                if (!PermissionsManager.HasPermission(requestedBy, PERMISSION_SPAWN_CHANGE))
                {
                    Chat.Send(requestedBy, "<color=red>You don't have permission to change the spawn area!</color>");
                    // TODO add counter and report to admins or auto-kick
                    return(false);
                }
            }
            else
            {
                Banner homeBanner = BannerTracker.Get(requestedBy);
                if (homeBanner != null)
                {
                    Vector3Int homeBannerLocation = homeBanner.KeyLocation;
                    if (System.Math.Abs(homeBannerLocation.x - position.x) <= BannerProtectionRangeX && System.Math.Abs(homeBannerLocation.z - position.z) <= BannerProtectionRangeZ)
                    {
                        return(true);
                    }
                }
                int checkRangeX = BannerProtectionRangeX;
                int checkRangeZ = BannerProtectionRangeZ;
                if (userData.typeToBuild == BlockTypes.Builtin.BuiltinBlocks.Banner)
                {
                    checkRangeX *= 2;
                    checkRangeZ *= 2;
                }
                foreach (Banner b in BannerTracker.GetBanners())
                {
                    Vector3Int bannerLocation = b.KeyLocation;
                    if (System.Math.Abs(bannerLocation.x - position.x) <= checkRangeX && System.Math.Abs(bannerLocation.z - position.z) <= checkRangeZ)
                    {
                        if (b.Owner != requestedBy && !PermissionsManager.HasPermission(requestedBy, PERMISSION_BANNER_PREFIX + b.Owner.ID.steamID))
                        {
                            Chat.Send(requestedBy, "<color=red>You don't have permission to change this area!</color>");
                            return(false);
                        }
                        break;
                    }
                }
            }
            return(true);
        }
 public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData userData)
 {
     if (!userData.isPrimaryAction)
     {
         VoxelSide side = userData.voxelHitSide;
         string    suffix;
         if (side == VoxelSide.xPlus)
         {
             suffix = "right";
         }
         else if (side == VoxelSide.xMin)
         {
             suffix = "left";
         }
         else if (side == VoxelSide.yPlus)
         {
             suffix = "bottom";
         }
         else if (side == VoxelSide.yMin)
         {
             suffix = "top";
         }
         else if (side == VoxelSide.zPlus)
         {
             suffix = "front";
         }
         else if (side == VoxelSide.zMin)
         {
             suffix = "back";
         }
         else
         {
             return(true);
         }
         ushort newType = userData.typeToBuild;
         string typename;
         if (newType != userData.typeTillNow && ItemTypes.IndexLookup.TryGetName(newType, out typename))
         {
             string otherTypename = typename + suffix;
             ushort otherIndex;
             if (ItemTypes.IndexLookup.TryGetIndex(otherTypename, out otherIndex))
             {
                 Vector3Int position = userData.VoxelToChange;
                 ThreadManager.InvokeOnMainThread(delegate() {
                     ServerManager.TryChangeBlock(position, otherIndex, ServerManager.SetBlockFlags.DefaultAudio);
                 }, 0.1f);
             }
         }
     }
     return(true);
 }
Example #6
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.typeTillNow == BuiltinBlocks.Air)
            {
                var turret = TurretSettings.FirstOrDefault(t => t.Value.TurretItem.ItemIndex == d.typeToBuild).Value;

                if (turret != null)
                {
                    MachineManager.RegisterMachineState(d.requestedBy, new MachineState(d.VoxelToChange, d.requestedBy, turret.Name));
                }
            }

            return(true);
        }
        private static bool allowBlockPlaceChunkOwnership(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.requestedBy.ID.steamID.m_SteamID == 0)
            {
                return(true);
            }

            string ChunkID = ColonyAPI.Managers.WorldManager.XZPositionToString(d.voxelHit.ToChunk());

            if (Managers.WorldManager.ChunkDataList.ContainsKey(ChunkID))
            {
                Data.ChunkData cd = Managers.WorldManager.ChunkDataList[ChunkID];
                NetworkID      id = cd.getOwner();
                if (cd.hasOwner())
                {
                    if (id == d.requestedBy.ID)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    //Utilities.WriteLog("Enforce: " + ConfigManager.getConfigBoolean("chunks.enforce"));
                    if (ColonyAPI.Managers.ConfigManager.getConfigBoolean("ColonyPlusPlus-Utilities", "chunks.enforce") == true)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            else
            {
                //Utilities.WriteLog("Enforce: " + ConfigManager.getConfigBoolean("chunks.enforce"));
                if (ColonyAPI.Managers.ConfigManager.getConfigBoolean("ColonyPlusPlus-Utilities", "chunks.enforce") == true)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Example #8
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData userData)
        {
            Players.Player requestedBy = userData.requestedBy;
            Vector3Int     position    = userData.VoxelToChange;

            if (userData.isPrimaryAction && allDoorTypes.Contains(userData.typeTillNow))
            {
                return(DoorBlockTracker.RemoveDoor(position, requestedBy));
            }
            else if (allDoorTypes.Contains(userData.typeToBuild))
            {
                return(DoorBlockTracker.AddDoor(position, userData.typeToBuild, requestedBy));
            }
            return(true);
        }
Example #9
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.TypeNew == Item.ItemIndex && d.typeTillNow == BuiltinBlocks.Air)
            {
                if (World.TryGetTypeAt(d.VoxelToChange.Add(0, -1, 0), out ushort itemBelow))
                {
                    if (CanMineBlock(itemBelow))
                    {
                        MachineManager.RegisterMachineState(d.requestedBy, new MachineState(d.VoxelToChange, d.requestedBy, nameof(Miner)));
                        return(true);
                    }
                }

                PandaChat.Send(d.requestedBy, "The mining machine must be placed on stone or ore.", ChatColor.orange);
                return(false);
            }

            return(true);
        }
Example #10
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.TypeNew == Item.ItemIndex && d.typeTillNow == BuiltinBlocks.Air)
            {
                MachineManager.RegisterMachineState(d.requestedBy, new MachineState(d.VoxelToChange, d.requestedBy, nameof(GateLever)));
            }
            else if (d.typeTillNow == BuiltinBlocks.Air && (d.TypeNew == GateItem.ItemIndex ||
                                                            d.TypeNew == GateItemXN.ItemIndex ||
                                                            d.TypeNew == GateItemXP.ItemIndex ||
                                                            d.TypeNew == GateItemZN.ItemIndex ||
                                                            d.TypeNew == GateItemZP.ItemIndex))
            {
                if (!_gatePositions.ContainsKey(d.requestedBy))
                {
                    _gatePositions.Add(d.requestedBy, new Dictionary <Vector3Int, GateState>());
                }

                _gatePositions[d.requestedBy].Add(d.VoxelToChange, new GateState(GatePosition.Closed, VoxelSide.None, d.VoxelToChange));
            }

            if (d.TypeNew == BuiltinBlocks.Air)
            {
                if (!_gatePositions.ContainsKey(d.requestedBy))
                {
                    _gatePositions.Add(d.requestedBy, new Dictionary <Vector3Int, GateState>());
                }

                if (_gatePositions[d.requestedBy].ContainsKey(d.VoxelToChange))
                {
                    _gatePositions[d.requestedBy].Remove(d.VoxelToChange);

                    if (!Inventory.GetInventory(d.requestedBy).TryAdd(GateItem.ItemIndex))
                    {
                        Stockpile.GetStockPile(d.requestedBy).Add(GateItem.ItemIndex);
                    }
                }
            }

            return(true);
        }
Example #11
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.TypeNew == BuiltinBlocks.Air)
            {
                lock (Machines)
                {
                    if (!Machines.ContainsKey(d.requestedBy))
                    {
                        Machines.Add(d.requestedBy, new List <MachineState>());
                    }

                    var mach = Machines[d.requestedBy].FirstOrDefault(m => m.Position == d.VoxelToChange);

                    if (mach != null)
                    {
                        Machines[d.requestedBy].Remove(mach);
                    }
                }
            }

            return(true);
        }
        public static bool AllowPlaceBlock(ModLoader.OnTryChangeBlockUserData d)
        {
            if (PermissionsManager.CheckAndWarnPermission(Players.GetPlayer(d.requestedBy.ID), "world.admin"))
            {
                return(true);
            }

            // Check permissions
            if (PermissionsManager.CheckAndWarnPermission(Players.GetPlayer(d.requestedBy.ID), "world.build"))
            {
                //Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You have build permissions");

                // first check if near spawn
                if (allowBlockFarEnoughFromSpawn(d))
                {
                    //Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You are far enough from spawn");
                    // what about chunk ownership
                    if (allowBlockPlaceChunkOwnership(d))
                    {
                        if (d.TypeNew == ItemTypes.IndexLookup.GetIndex("water"))
                        {
                            if (PermissionsManager.CheckAndWarnPermission(Players.GetPlayer(d.requestedBy.ID), "world.spawnbuilder"))
                            {
                                return(true);
                            }
                            return(false);
                        }
                        //Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You own the chunk");
                        return(true);
                    }
                    else
                    {
                        if (d.TypeNew == ItemTypes.IndexLookup.GetIndex("banner"))
                        {
                            string ChunkID = ColonyAPI.Managers.WorldManager.XZPositionToString(d.voxelHit.ToChunk());
                            if (Managers.WorldManager.ChunkDataList.ContainsKey(ChunkID))
                            {
                                Data.ChunkData cd = Managers.WorldManager.ChunkDataList[ChunkID];
                                if (cd.hasOwner())
                                {
                                    NetworkID id = cd.getOwner();
                                    if (id == d.requestedBy.ID)
                                    {
                                        return(true);
                                    }
                                    return(false);
                                }
                            }
                        }
                        ColonyAPI.Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You don't own the chunk");
                        return(false);
                    }
                }
                else
                {
                    //This section is for spawn.
                    if (PermissionsManager.CheckAndWarnPermission(Players.GetPlayer(d.requestedBy.ID), "spawnbuilder"))
                    {
                        //Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You aren't far enough from spawn, but you are admin");
                        return(true);
                    }
                    else
                    {
                        ColonyAPI.Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You aren't far enough from spawn");
                        return(false);
                    }
                }
            }
            else
            {
                ColonyAPI.Helpers.Chat.send(Players.GetPlayer(d.requestedBy.ID), "You don't have build permissions");
                return(false);
            }
        }
Example #13
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.typeTillNow == PatrolFlag.ItemIndex)
            {
                Knight toRemove = default(Knight);

                var state     = PlayerState.GetPlayerState(d.requestedBy);
                var stockpile = Stockpile.GetStockPile(d.requestedBy);

                if (!Knight.Knights.ContainsKey(d.requestedBy))
                {
                    Knight.Knights.Add(d.requestedBy, new List <Knight>());
                }

                foreach (var knight in Knight.Knights[d.requestedBy])
                {
                    try
                    {
                        if (knight.PatrolPoints.Contains(d.voxelHit))
                        {
                            knight.OnRemove();

                            foreach (var flagPoint in knight.PatrolPoints)
                            {
                                if (flagPoint != d.voxelHit)
                                {
                                    if (World.TryGetTypeAt(flagPoint, out var objType) && objType == PatrolFlag.ItemIndex)
                                    {
                                        ServerManager.TryChangeBlock(flagPoint, BuiltinBlocks.Air);
                                        stockpile.Add(PatrolFlag.ItemIndex);
                                    }
                                }
                            }

                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        PandaLogger.LogError(ex);
                    }
                }

                if (toRemove != default(Knight))
                {
                    PandaChat.Send(d.requestedBy, $"Patrol with {toRemove.PatrolPoints.Count} patrol points no longer active.", ChatColor.orange);
                    Knight.Knights[d.requestedBy].Remove(toRemove);

                    if (((JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(d.requestedBy)).openJobs.Contains(toRemove))
                    {
                        ((JobTracker.JobFinder)JobTracker.GetOrCreateJobFinder(d.requestedBy)).openJobs.Remove(toRemove);
                    }

                    JobTracker.Update();
                }

                if (state.FlagsPlaced.Contains(d.voxelHit))
                {
                    state.FlagsPlaced.Remove(d.voxelHit);
                    ServerManager.TryChangeBlock(d.voxelHit, BuiltinBlocks.Air);
                }

                stockpile.Add(PatrolFlag.ItemIndex);
            }

            return(true);
        }