From 410f6cf872fe7278770a778098cb0a21719fd281 Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Fri, 14 Dec 2012 23:40:38 -0500 Subject: [PATCH] Fixes some potential issues with concurrency, as well as cleaning up my z index check. --- TShockAPI/DB/RegionManager.cs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index 31519726..a0382a2e 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -238,25 +238,21 @@ namespace TShockAPI.DB return false; } Region top = null; - for (int i = 0; i < Regions.Count; i++) - { - if (Regions[i].InArea(x,y) ) - { - if (top == null) - top = Regions[i]; - else - { - if (Regions[i].Z > top.Z) - top = Regions[i]; - } - } - } + + foreach (Region region in Regions.ToList()) + { + if (region.InArea(x, y)) + { + if (top == null || region.Z > top.Z) + top = region; + } + } return top == null || top.HasPermissionToBuildInRegion(ply); } public bool InArea(int x, int y) { - foreach (Region region in Regions) + foreach (Region region in Regions.ToList()) { if (x >= region.Area.Left && x <= region.Area.Right && y >= region.Area.Top && y <= region.Area.Bottom && @@ -271,7 +267,7 @@ namespace TShockAPI.DB public List InAreaRegionName(int x, int y) { List regions = new List() { }; - foreach (Region region in Regions) + foreach (Region region in Regions.ToList()) { if (x >= region.Area.Left && x <= region.Area.Right && y >= region.Area.Top && y <= region.Area.Bottom && @@ -286,7 +282,7 @@ namespace TShockAPI.DB public List InAreaRegion(int x, int y) { List regions = new List() { }; - foreach (Region region in Regions) + foreach (Region region in Regions.ToList()) { if (x >= region.Area.Left && x <= region.Area.Right && y >= region.Area.Top && y <= region.Area.Bottom &&