ItemEvents.foodEaten(event => {
  let { server, player } = event
  
  if (event.item.id === 'kubejs:soul_of_ignis') {

    player.persistentData.IgnisPower = true;

    player.runCommandSilent(`attribute ${player.username} minecraft:generic.max_health base set 40`)
    player.runCommandSilent(`effect give ${player.username} minecraft:regeneration 5 255 true`)
    player.runCommandSilent(`particle cataclysm:flare_explode ~ ~1 ~`)
    player.runCommandSilent(`playsound minecraft:item.totem.use ambient @p`)
    Client.gameRenderer.displayItemActivation('kubejs:soul_of_ignis');
  }

  if (event.item.id === 'kubejs:soul_of_maledictus') {

    player.persistentData.MaledictusPower = true;

    player.runCommandSilent(`attribute ${player.username} minecraft:generic.max_health base set 40`)
    player.runCommandSilent(`effect give ${player.username} minecraft:regeneration 5 255 true`)
    player.runCommandSilent(`particle minecraft:explosion_emitter ~ ~1 ~`)
    player.runCommandSilent(`playsound minecraft:item.totem.use ambient @p`)
    Client.gameRenderer.displayItemActivation('kubejs:soul_of_maledictus');
  }

  if (event.item.id === 'kubejs:soul_of_scylla') {

    player.persistentData.ScyllaPower = true;

    player.runCommandSilent(`attribute ${player.username} minecraft:generic.max_health base set 40`)
    player.runCommandSilent(`effect give ${player.username} minecraft:regeneration 5 255 true`)
    player.runCommandSilent(`particle cataclysm:lightning_explode ~ ~1 ~`)
    player.runCommandSilent(`playsound minecraft:item.totem.use ambient @p`)
    Client.gameRenderer.displayItemActivation('kubejs:soul_of_scylla');
  }
});

PlayerEvents.tick(event => {
  let player = event.player;
  let data = player.persistentData;

  if (data.IgnisPower) {
    player.server.runCommandSilent(`effect give ${player.username} minecraft:fire_resistance infinite 0 true`);
    player.server.runCommandSilent(`effect give ${player.username} minecraft:strength infinite 2 true`);
    player.server.runCommandSilent(`effect give ${player.username} minecraft:resistance infinite 1 true`);
  }

  if (data.MaledictusPower) {
    player.server.runCommandSilent(`effect give ${player.username} minecraft:jump_boost infinite 1 true`);
    player.server.runCommandSilent(`effect give ${player.username} minecraft:speed infinite 1 true`);
    player.server.runCommandSilent(`attribute ${player.username} irons_spellbooks:max_mana base set 200`);
  }

  if (data.ScyllaPower) {
    player.server.runCommandSilent(`effect give ${player.username} minecraft:dolphins_grace infinite 1 true`);
    player.server.runCommandSilent(`effect give ${player.username} minecraft:conduit_power infinite 1 true`);
    player.server.runCommandSilent(`effect give ${player.username} irons_spellbooks:charged infinite 0 true`);
  }
});

EntityEvents.death(event => {
  let entity = event.entity;
  
  if (!entity.isPlayer()) return;

  entity.persistentData.IgnisPower = false;
  entity.persistentData.MaledictusPower = false;
  entity.persistentData.ScyllaPower = false;
});