TShockAPI.DB.Region.SetAllowedGroups C# (CSharp) Method

SetAllowedGroups() public method

Sets the group names which are allowed to use the region
public SetAllowedGroups ( String groups ) : void
groups String String of group names to set
return void
        public void SetAllowedGroups(String groups)
        {
            // prevent null pointer exceptions
            if (!string.IsNullOrEmpty(groups))
            {
                List<String> groupList = groups.Split(',').ToList();

                for (int i = 0; i < groupList.Count; i++)
                {
                    groupList[i] = groupList[i].Trim();
                }

                AllowedGroups = groupList;
            }
        }

Usage Example

Beispiel #1
0
        public bool AllowGroup(string regionName, string groups)
        {
            string groupsNew = "";

            using (
                var reader = database.QueryReader("SELECT * FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName,
                                                  Main.worldID.ToString()))
            {
                if (reader.Read())
                {
                    groupsNew = reader.Get <string>("Groups");
                }
            }
            if (groupsNew != "")
            {
                groupsNew += ",";
            }
            groupsNew += groups;

            int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", groupsNew,
                                   regionName, Main.worldID.ToString());

            Region r = GetRegionByName(regionName);

            if (r != null)
            {
                r.SetAllowedGroups(groupsNew);
            }
            else
            {
                return(false);
            }

            return(q > 0);
        }
All Usage Examples Of TShockAPI.DB.Region::SetAllowedGroups