private bool UpdateContainer()
 {
     // here to perform State updates to the data so it'll load properly. Will also stop containers from loading if the container version isn't less than the CurrentPluginVersion set here, it's a protection measure so that container contents don't get corrupted with potentially mismatched packing and unpacking procedures.
     if (ContainerVersion < CurrentPluginContainerVersion)
     {
         try
         {
             BarricadeManager.version = ContainerVersion;
             Logger.Log("run update.");
             Transform = BarricadeTool.getBarricade(Player.Player.transform, 100, Player.Position, new Quaternion(), AssetID, State);
             Container = Transform.GetComponent <InteractableStorage>();
             SaveState();
             ContainerVersion = BarricadeManager.SAVEDATA_VERSION;
             return(true);
         }
         catch (Exception ex)
         {
             Logger.LogException(ex, "Error updating the container.");
             return(false);
         }
         finally
         {
             BarricadeManager.version = BarricadeManager.SAVEDATA_VERSION;
         }
     }
     else
     {
         return(false);
     }
 }
 internal bool SetContainer(ushort assetID, byte[] state, UnturnedPlayer player, string containerName, byte itemCount, byte containerVersion)
 {
     ItemAsset = ((ItemBarricadeAsset)Assets.find(EAssetType.ITEM, assetID));
     if (ItemAsset == null || ItemAsset.build != EBuild.STORAGE)
     {
         return(false);
     }
     else
     {
         State            = state;
         ItemCount        = itemCount;
         ContainerName    = containerName;
         AssetID          = assetID;
         ContainerVersion = containerVersion;
         Player           = player;
         if (ContainerVersion < BarricadeManager.SAVEDATA_VERSION)
         {
             if (!UpdateContainer())
             {
                 return(false);
             }
         }
         Transform = BarricadeTool.getBarricade(Player.Player.transform, 100, Player.Position, new Quaternion(), AssetID, State);
         Container = Transform.GetComponent <InteractableStorage>();
         return(true);
     }
 }
        internal bool SetContainer(ushort assetID, byte[] state, UnturnedPlayer player, string containerName, byte itemCount, byte containerVersion)
        {
            Asset asset        = Assets.find(EAssetType.ITEM, assetID);
            bool  shouldUpdate = false;

            if (asset == null || (asset is ItemBarricadeAsset && ((ItemBarricadeAsset)asset).build != EBuild.STORAGE))
            {
                return(false);
            }
            else
            {
                State            = state;
                ItemCount        = itemCount;
                ContainerName    = containerName;
                AssetID          = assetID;
                ContainerVersion = containerVersion;
                Player           = player;
                try
                {
                    // Run update, if the container version is less than the barricade manager version.
                    if (ContainerVersion < BarricadeManager.SAVEDATA_VERSION)
                    {
                        shouldUpdate             = true;
                        BarricadeManager.version = containerVersion;
                        Logger.Log("Updating container.");
                    }
                    Transform = BarricadeTool.getBarricade(null, 100, Vector3.zero, new Quaternion(), AssetID, State);
                    Container = Transform.GetComponent <InteractableStorage>();
                    Container.transform.position = Vector3.zero;
                    Container.onStateRebuilt     = new InteractableStorage.RebuiltStateHandler(SaveState);
                    return(true);
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex, "Error setting container.");
                    Container = null;
                    return(false);
                }
                finally
                {
                    if (shouldUpdate)
                    {
                        BarricadeManager.version = BarricadeManager.SAVEDATA_VERSION;
                        if (Container != null)
                        {
                            ContainerVersion = BarricadeManager.SAVEDATA_VERSION;
                            Container.rebuildState();
                        }
                    }
                }
            }
        }
 protected override void Load()
 {
     _state            = DataBaseHelper.GetState(Player.CSteamID).State;
     _storageTransform = BarricadeTool.getBarricade(null, 100, Player.Position, default, 328, _state);