From c33773a3181beb9400bc950b0d011b2b2422e247 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 May 2024 07:17:40 +0000 Subject: [PATCH] Added more resiliency to the give command for modders who dont want to add localization for their mods (!325) Fixed cases for modded items causing problems with Commando. Co-authored-by: clodan Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/325 Co-authored-by: Alex Co-committed-by: Alex --- .../SptCommands/GiveCommand/GiveSptCommand.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts b/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts index 99d48a74..3451d574 100644 --- a/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts +++ b/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts @@ -146,16 +146,17 @@ export class GiveSptCommand implements ISptCommand commandHandler, `An error occurred while trying to use localized text. Locale will be defaulted to 'en'.`, ); - this.logger.error(e); + this.logger.warning(e); locale = "en"; } - const localizedGlobal = this.databaseServer.getTables().locales.global[locale]; + const localizedGlobal = this.databaseServer.getTables().locales.global[locale] ?? + this.databaseServer.getTables().locales.global.en; const closestItemsMatchedByName = this.itemHelper.getItems() .filter((i) => this.isItemAllowed(i)) - .map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase()) - .filter((i) => i !== undefined) + .map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase() ?? i._props.Name) + .filter((i) => i !== undefined && i !== "") .map(i => ({match: stringSimilarity(item.toLocaleLowerCase(), i.toLocaleLowerCase()), itemName: i})) .sort((a1, a2) => a2.match - a1.match); @@ -186,7 +187,7 @@ export class GiveSptCommand implements ISptCommand const tplId = isItemName ? this.itemHelper.getItems() .filter((i) => this.isItemAllowed(i)) - .find((i) => this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() === item)._id + .find((i) => (this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() ?? i._props.Name) === item)._id : item; const checkedItem = this.itemHelper.getItem(tplId);