Fixes some potential issues with concurrency, as well as cleaning up my z index check.

This commit is contained in:
Zack Piispanen 2012-12-14 23:40:38 -05:00
parent 88a9c05220
commit 410f6cf872

View file

@ -238,25 +238,21 @@ namespace TShockAPI.DB
return false; return false;
} }
Region top = null; Region top = null;
for (int i = 0; i < Regions.Count; i++)
{ foreach (Region region in Regions.ToList())
if (Regions[i].InArea(x,y) ) {
{ if (region.InArea(x, y))
if (top == null) {
top = Regions[i]; if (top == null || region.Z > top.Z)
else top = region;
{ }
if (Regions[i].Z > top.Z) }
top = Regions[i];
}
}
}
return top == null || top.HasPermissionToBuildInRegion(ply); return top == null || top.HasPermissionToBuildInRegion(ply);
} }
public bool InArea(int x, int y) 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 && if (x >= region.Area.Left && x <= region.Area.Right &&
y >= region.Area.Top && y <= region.Area.Bottom && y >= region.Area.Top && y <= region.Area.Bottom &&
@ -271,7 +267,7 @@ namespace TShockAPI.DB
public List<string> InAreaRegionName(int x, int y) public List<string> InAreaRegionName(int x, int y)
{ {
List<string> regions = new List<string>() { }; List<string> regions = new List<string>() { };
foreach (Region region in Regions) foreach (Region region in Regions.ToList())
{ {
if (x >= region.Area.Left && x <= region.Area.Right && if (x >= region.Area.Left && x <= region.Area.Right &&
y >= region.Area.Top && y <= region.Area.Bottom && y >= region.Area.Top && y <= region.Area.Bottom &&
@ -286,7 +282,7 @@ namespace TShockAPI.DB
public List<Region> InAreaRegion(int x, int y) public List<Region> InAreaRegion(int x, int y)
{ {
List<Region> regions = new List<Region>() { }; List<Region> regions = new List<Region>() { };
foreach (Region region in Regions) foreach (Region region in Regions.ToList())
{ {
if (x >= region.Area.Left && x <= region.Area.Right && if (x >= region.Area.Left && x <= region.Area.Right &&
y >= region.Area.Top && y <= region.Area.Bottom && y >= region.Area.Top && y <= region.Area.Bottom &&