public static bool claimChunk(Vector3Int position, NetworkID playerid, bool isSpawn = false)
        {
            Vector3Int p         = position.ToChunk();
            string     chunkname = ColonyAPI.Managers.WorldManager.XZPositionToString(p);

            if (ChunkDataList.ContainsKey(chunkname))
            {
                Data.ChunkData c = ChunkDataList[chunkname];

                bool result = c.setOwner(playerid);
                SaveJSON();

                return(result);
            }
            else
            {
                Data.ChunkData c = new Data.ChunkData(p, true, playerid, new List <NetworkID>()
                {
                    playerid
                }, isSpawn);

                ChunkDataList.Add(chunkname, c);
                SaveJSON();

                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);
                }
            }
        }
        public static bool unclaimChunk(Vector3Int position, NetworkID playerid, bool force = false)
        {
            Vector3Int p         = position.ToChunk();
            string     chunkname = ColonyAPI.Managers.WorldManager.XZPositionToString(p);

            if (ChunkDataList.ContainsKey(chunkname))
            {
                Data.ChunkData c = ChunkDataList[chunkname];
                if (c.getOwner() == playerid || force)
                {
                    bool result = c.removeOwner();
                    SaveJSON();
                    return(result);
                }
                return(false);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        protected override bool RunCommand(Players.Player ply, string[] args, NetworkID target)
        {
            if (PermissionsManager.CheckAndWarnPermission(ply, "chunk.info") && ColonyAPI.Managers.ConfigManager.getConfigBoolean("ColonyPlusPlus-Utilities", "chunks.enabled"))
            {
                Vector3Int pos       = ColonyAPI.Managers.WorldManager.positionToVector3Int(ply.Position).ToChunk();
                string     chunkName = ColonyAPI.Managers.WorldManager.XZPositionToString(pos);
                if (Managers.WorldManager.ChunkDataList.ContainsKey(chunkName))
                {
                    Data.ChunkData c = Managers.WorldManager.ChunkDataList[chunkName];
                    ColonyAPI.Helpers.Chat.sendSilent(ply, String.Format("Chunk data for chunk: {0}", chunkName), ColonyAPI.Helpers.Chat.ChatColour.lime, ColonyAPI.Helpers.Chat.ChatStyle.bold);
                    ColonyAPI.Helpers.Chat.sendSilent(ply, String.Format("Currently owned: {0}", c.hasOwner()), ColonyAPI.Helpers.Chat.ChatColour.lime, ColonyAPI.Helpers.Chat.ChatStyle.bold);

                    if (c.hasOwner())
                    {
                        ColonyAPI.Helpers.Chat.sendSilent(ply, String.Format("Currently owned by: {0}", Players.GetPlayer(c.getOwner()).Name), ColonyAPI.Helpers.Chat.ChatColour.lime, ColonyAPI.Helpers.Chat.ChatStyle.bold);
                    }

                    string prevOwners = "";

                    foreach (NetworkID n in c.ownerHistory)
                    {
                        prevOwners += Players.GetPlayer(n).Name + ", ";
                    }

                    ColonyAPI.Helpers.Chat.sendSilent(ply, String.Format("Previous Owners ({0}): {1}", c.ownerHistory.Count, prevOwners), ColonyAPI.Helpers.Chat.ChatColour.lime, ColonyAPI.Helpers.Chat.ChatStyle.bold);
                }
                else
                {
                    ColonyAPI.Helpers.Chat.sendSilent(ply, "No chunk data", ColonyAPI.Helpers.Chat.ChatColour.red, ColonyAPI.Helpers.Chat.ChatStyle.bold);
                }
            }
            else
            {
                ColonyAPI.Helpers.Chat.sendSilent(ply, "You cannot check chunk info", ColonyAPI.Helpers.Chat.ChatColour.red, ColonyAPI.Helpers.Chat.ChatStyle.bold);
            }

            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);
            }
        }
        public static void LoadJSON()
        {
            try
            {
                JSONNode array;
                if (Pipliz.JSON.JSON.Deserialize(GetJSONPath(), out array, false))
                {
                    if (array != null)
                    {
                        int chunksloaded = 0;
                        foreach (JSONNode node in array.LoopArray())
                        {
                            try
                            {
                                // recapture location
                                Pipliz.Vector3Int location = new Pipliz.Vector3Int();
                                location = (Pipliz.Vector3Int)node["location"];

                                // recapture instance class
                                string chunkID = node["chunkID"].GetAs <string>();

                                Data.ChunkData instanceclass;

                                bool             owned        = node["owned"].GetAs <bool>();
                                ulong            playerID     = node["playerID"].GetAs <ulong>();
                                JSONNode         history      = node["ownerHistory"].GetAs <JSONNode>();
                                List <NetworkID> ownerHistory = new List <NetworkID>();

                                foreach (JSONNode j in history.LoopArray())
                                {
                                    ownerHistory.Add(new NetworkID(new CSteamID(j.GetAs <ulong>("id"))));
                                }

                                if (playerID > 0)
                                {
                                    instanceclass = new Data.ChunkData(location, owned, new NetworkID(new CSteamID(playerID)), ownerHistory);

                                    ChunkDataList.Add(chunkID, instanceclass);

                                    chunksloaded += 1;
                                }
                            }
                            catch (Exception exception)
                            {
                                ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus-Utilities", "Exception loading a wheat block;" + exception.Message);
                            }
                        }

                        ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus-Utilities", "Loaded Chunk Data (" + chunksloaded + " chunks)");
                    }
                    else
                    {
                        ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus-Utilities", "Loading Chunk Data Returned 0 results");
                    }
                }
                else
                {
                    ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus-Utilities", "Found no chunk data (read error?)");
                }
            }
            catch (Exception exception2)
            {
                ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus-Utilities", "Exception in loading all Chunk Data:" + exception2.Message);
            }

            worldManagerLoaded = true;
        }