Skip to content

Commit

Permalink
chore: address code dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropapa committed Sep 29, 2024
1 parent 75d710d commit 2871556
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions brz-core/server/adapters/inventory.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
declare const SETTINGS: any;

const qbCoreGetPlayer = () =>
SETTINGS.INVENTORY_SYSTEM === "qbCore" &&
exports["qb-core"]?.GetCoreObject?.()?.Functions?.GetPlayer;
const qbCoreGetPlayer = (source: number) => {
const getPlayer =
SETTINGS.INVENTORY_SYSTEM === "qbCore" &&
exports["qb-core"]?.GetCoreObject?.()?.Functions?.GetPlayer;

const player = getPlayer(source);

if (!player) {
console.error("Player not found ", source);
return false;
}

return player;
};

export const oxInventoryAdapter = {
removeItem: (source: number, itemName: string) => {
Expand Down Expand Up @@ -43,21 +54,19 @@ export const oxInventoryAdapter = {

export const qbCoreAdapter = {
removeItem: (source: number, itemName: string) => {
const player = qbCoreGetPlayer()(source);
const player = qbCoreGetPlayer(source);

if (!player) {
console.error("Player not found ", source, itemName);
return false;
}

player.Functions.RemoveItem(itemName, 1);
return true;
},
addItem: (source: number, itemName: string) => {
const player = qbCoreGetPlayer()(source);
const player = qbCoreGetPlayer(source);

if (!player) {
console.error("Player not found ", source, itemName);
return false;
}

Expand All @@ -71,10 +80,9 @@ export const qbCoreAdapter = {
return item;
},
notify: (source: number, message: string, type: "success" | "error") => {
const player = qbCoreGetPlayer()(source);
const player = qbCoreGetPlayer(source);

if (!player) {
console.error("Player not found");
return false;
}

Expand Down

0 comments on commit 2871556

Please sign in to comment.