Hello. I'm trying to remove or clean inventory on first join, to remove one item, which is added by mod but it's not possible to remove it through config or datapack. I have asked chatGPT, but obviously it doesn't work and I have no coding skills either. Can someone help me?
// kubejs/server_scripts/first_join_item_removal.js
// Replace 'modid:item_name' with the item you want to remove
const ITEM_TO_REMOVE = 'modid:item_name';
ServerEvents.playerLoggedIn(event => {
const player = event.player;
// Check if this is the player's first login
if (!player.persistentData.has('first_join_checked')) {
// Mark that we've checked the player on first join
player.persistentData.putBoolean('first_join_checked', true);
// Check and remove the specific item from the player's inventory
const inventory = player.inventory;
const itemsToRemove = inventory.findAll(ITEM_TO_REMOVE);
itemsToRemove.forEach(itemStack => {
inventory.removeItem(itemStack);
});
// Optionally, log the action to the server console
console.log(`Removed ${ITEM_TO_REMOVE} from player ${player.name.getString()} on first join.`);
}
});