diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index a9cc2739..a4898b3f 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -473,27 +473,33 @@ namespace TShockAPI.DB return false; } - public bool AllowGroup(string regionName, string groups) + public bool AllowGroup(string regionName, string groupName) { - string groupsNew = ""; + string mergedGroups = ""; using ( - var reader = database.QueryReader("SELECT * FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, + var reader = database.QueryReader("SELECT Groups FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, Main.worldID.ToString())) { if (reader.Read()) - groupsNew = reader.Get("Groups"); + mergedGroups = reader.Get("Groups"); } - if (groupsNew != "") - groupsNew += ","; - groupsNew += groups; - int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", groupsNew, + string[] groups = mergedGroups.Split(','); + // Is the user already allowed to the region? + if (groups.Contains(groupName)) + return true; + + if (mergedGroups != "") + mergedGroups += ","; + mergedGroups += groupName; + + int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", mergedGroups, regionName, Main.worldID.ToString()); Region r = GetRegionByName(regionName); if (r != null) { - r.SetAllowedGroups(groupsNew); + r.SetAllowedGroups(mergedGroups); } else {