From e93313e0f22c8582ec606a3edcf0f173123408f6 Mon Sep 17 00:00:00 2001 From: MCrow Date: Tue, 8 Oct 2024 15:32:46 +0200 Subject: [PATCH] fix vehicle/item name too long error --- ZaupShop/Commands/Console/CommandUploadItemShop.cs | 4 +--- ZaupShop/DatabaseMgr.cs | 4 ++++ ZaupShop/ZaupShop.csproj | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ZaupShop/Commands/Console/CommandUploadItemShop.cs b/ZaupShop/Commands/Console/CommandUploadItemShop.cs index 38972c7..2c4db28 100644 --- a/ZaupShop/Commands/Console/CommandUploadItemShop.cs +++ b/ZaupShop/Commands/Console/CommandUploadItemShop.cs @@ -30,9 +30,7 @@ public void Execute(IRocketPlayer caller, string[] command) { foreach (ItemAsset asset in items) { - // get name of item max length 32 characters - string itemName = asset.itemName.Length > 32 ? asset.itemName.Substring(0, 32) : asset.itemName; - pluginInstance.ShopDB.AddItem(asset.id, itemName, 0, false, 0, true); + pluginInstance.ShopDB.AddItem(asset.id, asset.itemName, 0, false, 0, true); } Logger.Log($"Done! Finished syncing {count} items with the {ZaupShop.Instance.Configuration.Instance.ItemShopTableName} table in database!"); }); diff --git a/ZaupShop/DatabaseMgr.cs b/ZaupShop/DatabaseMgr.cs index f219d88..d4ec462 100644 --- a/ZaupShop/DatabaseMgr.cs +++ b/ZaupShop/DatabaseMgr.cs @@ -77,6 +77,8 @@ public bool AddItem(int id, string name, decimal cost, bool isChange, decimal? b using var connection = createConnection(); using var command = connection.CreateCommand(); + name = name.Length > 32 ? name.Substring(0, 32) : name; + command.CommandText = $@" INSERT INTO `{ZaupShop.Instance.Configuration.Instance.ItemShopTableName}` (`id`, `itemname`, `cost`, `buyback`) @@ -109,6 +111,8 @@ public bool AddVehicle(int id, string name, decimal cost, bool change, bool dont using var connection = createConnection(); using var command = connection.CreateCommand(); + name = name.Length > 32 ? name.Substring(0, 32) : name; + command.CommandText = $@" INSERT INTO `{ZaupShop.Instance.Configuration.Instance.VehicleShopTableName}` (`id`, `vehiclename`, `cost`) diff --git a/ZaupShop/ZaupShop.csproj b/ZaupShop/ZaupShop.csproj index 2fb636c..25a4165 100644 --- a/ZaupShop/ZaupShop.csproj +++ b/ZaupShop/ZaupShop.csproj @@ -5,7 +5,7 @@ latest ZaupShop ZaupShop - 2.0.1 + 2.0.2