Index: binary-improvements/MapRendering/Web/API/GetLandClaims.cs
===================================================================
--- binary-improvements/MapRendering/Web/API/GetLandClaims.cs	(revision 251)
+++ binary-improvements/MapRendering/Web/API/GetLandClaims.cs	(revision 253)
@@ -7,14 +7,12 @@
 namespace AllocsFixes.NetConnections.Servers.Web.API
 {
-	public class GetLandClaims : WebAPI
-	{
-		public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
-		{
-			string ViewersSteamID = string.Empty;
-            ulong lViewersSteamID = 0L;
+	public class GetLandClaims : WebAPI {
+		public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
+			string requestedSteamID = string.Empty;
 
 			if (req.QueryString ["steamid"] != null) {
-				ViewersSteamID = req.QueryString ["steamid"];
-                if (ViewersSteamID.Length != 17 || !ulong.TryParse (ViewersSteamID, out lViewersSteamID)) {
+				ulong lViewersSteamID;
+				requestedSteamID = req.QueryString ["steamid"];
+				if (requestedSteamID.Length != 17 || !ulong.TryParse (requestedSteamID, out lViewersSteamID)) {
 					resp.StatusCode = (int)HttpStatusCode.BadRequest;
 					Web.SetResponseTextContent (resp, "Invalid SteamID given");
@@ -23,8 +21,8 @@
 			}
 
-            // default user, cheap way to avoid 'null reference exception'
-            try { user = user ?? new WebConnection ("", "", 0L); } catch { }
+			// default user, cheap way to avoid 'null reference exception'
+			user = user ?? new WebConnection ("", "", 0L);
 
-            bool bViewAll = false; try { bViewAll = user.CanViewAllClaims (permissionLevel); } catch { }
+			bool bViewAll = WebConnection.CanViewAllClaims (permissionLevel);
             
 			JSONObject result = new JSONObject ();
@@ -34,55 +32,48 @@
 			result.Add ("claimowners", claimOwners);
 
-			Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap;
-			if (d != null) {
-				World w = GameManager.Instance.World;
-				Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
+			LandClaimList.OwnerFilter[] ownerFilters = null;
+			if (!string.IsNullOrEmpty (requestedSteamID) || !bViewAll) {
+				if (!string.IsNullOrEmpty (requestedSteamID) && !bViewAll) {
+					ownerFilters = new LandClaimList.OwnerFilter[] {
+						LandClaimList.SteamIdFilter (user.SteamID.ToString ()),
+						LandClaimList.SteamIdFilter (requestedSteamID)
+					};
+				} else if (!bViewAll) {
+					ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (user.SteamID.ToString ()) };
+				} else {
+					ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (requestedSteamID) };
+				}
+			}
+			LandClaimList.PositionFilter[] posFilters = null;
 
-                // Add all owners to this temporary list regardless of permissions
-				foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
-					if (kvp.Value.PlayerId.Equals (ViewersSteamID)) {
-						if (!owners.ContainsKey (kvp.Value)) {
-							owners.Add (kvp.Value, new List<Vector3i> ());
-						}
-						owners [kvp.Value].Add (kvp.Key);
+			Dictionary<PersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
+
+			foreach (KeyValuePair<PersistentData.Player, List<Vector3i>> kvp in claims) {
+
+				try {
+					JSONObject owner = new JSONObject ();
+					claimOwners.Add (owner);
+
+					owner.Add ("steamid", new JSONString (kvp.Key.SteamID));
+					owner.Add ("claimactive", new JSONBoolean (kvp.Key.LandProtectionActive));
+
+					if (kvp.Key.Name.Length > 0) {
+						owner.Add ("playername", new JSONString (kvp.Key.Name));
+					} else {
+						owner.Add ("playername", new JSONNull ());
 					}
-				}
 
-                // Loop through all claim owners...
-				foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
-                    try
-                    {
-                        // ... but only show us claims that are from the current web user or if the current web user can see all claims regardless of ownership
-                        if (kvp.Key.PlayerId.Equals (ViewersSteamID) || bViewAll)
-                        {
-                            string currentSteamID = kvp.Key.PlayerId;
-                            bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key);
+					JSONArray claimsJson = new JSONArray ();
+					owner.Add ("claims", claimsJson);
 
-                            JSONObject owner = new JSONObject ();
-                            claimOwners.Add (owner);
+					foreach (Vector3i v in kvp.Value) {
+						JSONObject claim = new JSONObject ();
+						claim.Add ("x", new JSONNumber (v.x));
+						claim.Add ("y", new JSONNumber (v.y));
+						claim.Add ("z", new JSONNumber (v.z));
 
-                            owner.Add("steamid", new JSONString (currentSteamID));
-                            owner.Add("claimactive", new JSONBoolean (isActive));
-
-                            if (PersistentContainer.Instance.Players [currentSteamID, false] != null) {
-                                owner.Add("playername", new JSONString (PersistentContainer.Instance.Players [currentSteamID, false].Name));
-                            } else {
-                                owner.Add("playername", new JSONNull ());
-                            }
-
-                            JSONArray claims = new JSONArray ();
-                            owner.Add ("claims", claims);
-
-                            foreach (Vector3i v in kvp.Value) {
-                                JSONObject claim = new JSONObject ();
-                                claim.Add ("x", new JSONNumber (v.x));
-                                claim.Add ("y", new JSONNumber (v.y));
-                                claim.Add ("z", new JSONNumber (v.z));
-
-                                claims.Add (claim);
-                            }
-                        }
-                    }
-                    catch { }
+						claimsJson.Add (claim);
+					}
+				} catch {
 				}
 			}
