ServerEvents.tick(event => {
  if (event.server.tickCount % 20 !== 0) return // Check every second

  const scoreboard = event.server.scoreboard
  const players = event.server.players

  players.forEach(player => {
    const current = scoreboard.getPlayerScore(player, 'kills') || 0
    const stored = player.persistentData.kjs_kills || 0

    if (current > stored) {
      const gained = current - stored

      for (let i = 0; i < gained; i++) {
        player.give(Item.of('minecraft:emerald', 2))
        player.give(Item.of('minecraft:golden_apple', 1))
        player.tell(`§aYou received a reward for killing a player!`)
      }

      player.persistentData.kjs_kills = current
    }
  })
})
