So! I have an attempt at a script to clear a player's inventory with the /clear command, to try to remove the pile of mod-related books they start with. (There aren't mod configs to not generate them for a lot of them, unfortunately. :/ )
I'm using Decursio Stages to track if it's the first time joining, and after running the script, it adds the stage.
However, what I think is happening, is that the script runs when they join, and then the books are added after. Removing and re-adding the stage after this causes it to work correctly.
I tried adding a janky wait line to the script, but it doesn't seem to help.
Am I missing something obvious here?
const StageUtil = Java.loadClass('com.decursioteam.decursio_stages.utils.StageUtil')
PlayerEvents.loggedIn(event => {
if (!StageUtil.hasStage(event.player, "starting inventory"))
{
let playerName = event.player.getName().getString();
event.server.schedule(2000, () => {event.server.tell(`Welcome, ${playerName}!`);
Utils.server.runCommandSilent(`clear ${playerName}`)
Utils.server.runCommandSilent(`give ${playerName} minecraft:stone_sword`)
Utils.server.runCommandSilent(`decstages add ${playerName} "starting inventory"`)
});
}
});