From a3d29bb8f09d68759eba0ecd1a1eab292036fb67 Mon Sep 17 00:00:00 2001
From: MagicBot <MagicBot@magicbane.com>
Date: Sun, 8 Oct 2023 23:05:41 -0400
Subject: [PATCH] Error trap

---
 src/engine/objects/Zone.java | 102 ++++++++++++++++++-----------------
 1 file changed, 54 insertions(+), 48 deletions(-)

diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java
index a14a4dc4..015d5854 100644
--- a/src/engine/objects/Zone.java
+++ b/src/engine/objects/Zone.java
@@ -77,63 +77,69 @@ public class Zone extends AbstractGameObject {
      * ResultSet Constructor
      */
     public Zone(ResultSet rs) throws SQLException {
-        super(rs);
-        this.parentZoneID = rs.getInt("parent");
-        this.playerCityUUID = rs.getInt("playerCityUUID");
-        this.guild_zone = this.playerCityUUID != 0;
-        this.zoneName = rs.getString("zone_name");
-        this.xOffset = rs.getFloat("xOffset");
-        this.zOffset = rs.getFloat("zOffset");
-        this.yOffset = rs.getFloat("yOffset");
-        this.template = rs.getInt("template");
-        this.peace_zone = rs.getByte("peace_zone");
-        this.icon1 = rs.getString("icon1");
-        this.icon2 = rs.getString("icon2");
-        this.icon3 = rs.getString("icon3");
-        this.min_level = rs.getInt("min_level");
-        this.max_level = rs.getInt("max_level");
-        this.major_radius = rs.getFloat("major_radius");
-        this.minor_radius = rs.getFloat("minor_radius");
-        this.min_blend = rs.getFloat("min_blend");
-        this.max_blend = rs.getFloat("max_blend");
-        this.sea_level_type = rs.getString("sea_level_type");
-        this.sea_level_offset = rs.getFloat("sea_level");
-        this.terrain_type = rs.getString("terrain_type");
-        this.terrain_max_y = rs.getFloat("terrain_max_y");
-        this.terrain_image = rs.getInt("terrain_image");
-
-        if (this.guild_zone) {
-            this.max_blend = 128;
-            this.min_blend = 128;
-            this.major_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
-            this.minor_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
-            this.terrain_type = "PLANAR";
-        }
-
-        if (this.terrain_type.equals("NONE"))
-            this.terrain = null;
-        else
-            this.terrain = new Terrain(this);
 
-        //this needs to be here specifically for new zones created after server boot (e.g. player city zones)
-
-        Zone parentZone = ZoneManager.getZoneByUUID(parentZoneID);
-        this.setParent(parentZone);
+        super(rs);
 
-        if (this.min_level == 0 && parentZone != null) {
-            this.min_level = parentZone.min_level;
-            this.max_level = parentZone.max_level;
+        try {
+            this.parentZoneID = rs.getInt("parent");
+            this.playerCityUUID = rs.getInt("playerCityUUID");
+            this.guild_zone = this.playerCityUUID != 0;
+            this.zoneName = rs.getString("zone_name");
+            this.xOffset = rs.getFloat("xOffset");
+            this.zOffset = rs.getFloat("zOffset");
+            this.yOffset = rs.getFloat("yOffset");
+            this.template = rs.getInt("template");
+            this.peace_zone = rs.getByte("peace_zone");
+            this.icon1 = rs.getString("icon1");
+            this.icon2 = rs.getString("icon2");
+            this.icon3 = rs.getString("icon3");
+            this.min_level = rs.getInt("min_level");
+            this.max_level = rs.getInt("max_level");
+            this.major_radius = rs.getFloat("major_radius");
+            this.minor_radius = rs.getFloat("minor_radius");
+            this.min_blend = rs.getFloat("min_blend");
+            this.max_blend = rs.getFloat("max_blend");
+            this.sea_level_type = rs.getString("sea_level_type");
+            this.sea_level_offset = rs.getFloat("sea_level");
+            this.terrain_type = rs.getString("terrain_type");
+            this.terrain_max_y = rs.getFloat("terrain_max_y");
+            this.terrain_image = rs.getInt("terrain_image");
+
+            if (this.guild_zone) {
+                this.max_blend = 128;
+                this.min_blend = 128;
+                this.major_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
+                this.minor_radius = (int) Enum.CityBoundsType.ZONE.halfExtents;
+                this.terrain_type = "PLANAR";
+            }
+
+            if (this.terrain_type.equals("NONE"))
+                this.terrain = null;
+            else
+                this.terrain = new Terrain(this);
+
+            //this needs to be here specifically for new zones created after server boot (e.g. player city zones)
+
+            Zone parentZone = ZoneManager.getZoneByUUID(parentZoneID);
+            this.setParent(parentZone);
+
+            if (this.min_level == 0 && parentZone != null) {
+                this.min_level = parentZone.min_level;
+                this.max_level = parentZone.max_level;
+            }
+
+            if (parentZone != null)
+                parentZone.addNode(this);
+        } catch (Exception e) {
+            Logger.error(e);
+            throw new RuntimeException(e);
         }
 
-        if (parentZone != null)
-            parentZone.addNode(this);
-
         // If zone doesn't yet hava a hash then write it back to the zone table
 
         if (hash == null)
             setHash();
 
-
     }
 
     public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {